- Notifications
You must be signed in to change notification settings - Fork928
fix(coderd/database): improve perf ofGetTemplateInsightsByInterval
#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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -355,7 +355,7 @@ WITH | ||
CROSS JOIN | ||
generate_series( | ||
date_trunc('minute', was.session_started_at), | ||
-- Subtract 1μs to avoid creating an extra series. | ||
date_trunc('minute', was.session_ended_at - '1 microsecond'::interval), | ||
'1 minute'::interval | ||
) AS s(minute_bucket) | ||
@@ -389,14 +389,17 @@ WITH | ||
ts AS ( | ||
SELECT | ||
d::timestamptz AS from_, | ||
LEAST( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
| ||
(d::timestamptz + (@interval_days::int || ' day')::interval)::timestamptz, | ||
@end_time::timestamptz | ||
)::timestamptz AS to_ | ||
FROM | ||
generate_series( | ||
@start_time::timestamptz, | ||
-- Subtract 1 μs to avoid creating an extra series. | ||
(@end_time::timestamptz) - '1 microsecond'::interval, | ||
(@interval_days::int || ' day')::interval | ||
) AS d | ||
) | ||
SELECT | ||
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Main performance optimization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nice spotting 👍 👍 | ||
AND tus.end_time <= ts.to_ | ||
AND CASE WHEN COALESCE(array_length(@template_ids::uuid[], 1), 0) > 0 THEN tus.template_id = ANY(@template_ids::uuid[]) ELSE TRUE END | ||
GROUP BY | ||
@@ -473,7 +477,7 @@ WITH | ||
CROSS JOIN | ||
generate_series( | ||
date_trunc('minute', was.session_started_at), | ||
-- Subtract 1μs to avoid creating an extra series. | ||
date_trunc('minute', was.session_ended_at - '1 microsecond'::interval), | ||
'1 minute'::interval | ||
) AS s(minute_bucket) | ||