Skip to content

fix(coderd/database): improve perf of GetTemplateInsightsByInterval #12773

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

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Mar 27, 2024

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

THEN (d::timestamptz + (@interval_days::int || ' day')::interval)
ELSE @end_time::timestamptz
END AS to_
LEAST(
Copy link
Member Author

Choose a reason for hiding this comment

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

LEAST is more performant than case.

@@ -410,6 +413,7 @@ LEFT JOIN
template_usage_stats AS tus
ON
tus.start_time >= ts.from_
AND tus.start_time < ts.to_ -- End time exclusion criteria optimization for index.
Copy link
Member Author

Choose a reason for hiding this comment

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

Main performance optimization.

Copy link
Member

Choose a reason for hiding this comment

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

Nice spotting 👍 👍

@mafredri mafredri marked this pull request as ready for review March 27, 2024 11:43
@mafredri mafredri requested review from mtojek and johnstcn March 27, 2024 11:43
@@ -410,6 +413,7 @@ LEFT JOIN
template_usage_stats AS tus
ON
tus.start_time >= ts.from_
AND tus.start_time < ts.to_ -- End time exclusion criteria optimization for index.
Copy link
Member

Choose a reason for hiding this comment

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

Nice spotting 👍 👍

@mafredri mafredri merged commit 47fd190 into main Mar 27, 2024
33 checks passed
@mafredri mafredri deleted the mafredri/03-27-fix_coderd_database_improve_perf_of_gettemplateinsightsbyinterval_ branch March 27, 2024 12:10
@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.

2 participants