Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(coderd/database): improve query perf of GetTemplateAppInsights #12767

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Mar 26, 2024

The main performance gain here is to join workspace_apps with template_usage_stats before doing jsonb_each. Previously we were doing a lateral join of workspace_apps to the lateral/cross joined (app_usage_mins) rows which was performing poorly.

Ref: #12122

New:

https://explain.dalibo.com/plan/c993d4250f56f555

template_ids|active_users|slug|display_name|icon|usage_seconds
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|19|code-server|code-server|/icon/code.svg|1029540
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|10|filebrowser|File Browser|https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg|1800

Old:

https://explain.dalibo.com/plan/aaed9gbg8hda1c6e

template_ids|active_users|slug_or_port|display_name|icon|is_app|usage_seconds
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|2|1234|||f|120
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|2|13337|||f|360
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|4|3000|||f|600
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|2|3001|||f|360
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|3002|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|33615|||f|180
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|35713|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|38039|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|40367|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|41435|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|42845|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|43271|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|4444|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|46415|||f|180
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|46851|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|55|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|5500|||f|360
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|2|5555|||f|180
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|5556|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|5991|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|6006|||f|2640
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|6081|||f|180
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|7007|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|80|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|5|8000|||f|1020
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|5|8080|||f|1440
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|8081|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|1|9|||f|60
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|19|code-server|code-server|/icon/code.svg|t|1029540
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|10|filebrowser|File Browser|https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg|t|1800
{0d286645-29aa-4eaf-9b52-cc5d2740c90b}|24|[terminal]|||f|333900
(31 rows)

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @mafredri and the rest of your teammates on Graphite Graphite

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mafredri mafredri merged commit 0da29d7 into main Mar 27, 2024
26 checks passed
@mafredri mafredri deleted the mafredri/03-26-fix_coderd_database_improve_query_perf_of_gettemplateappinsights_ branch March 27, 2024 10:28
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants