Skip to content

Commit 427fa9f

Browse files
Use MIN/MAX/AVG for sp_QuickieStore wait-time column aggregations
The plan-level wait-stats aggregation in the #query_store_wait_stats insert used SUM() for every value including the ones typed and named as min_query_wait_time_ms and max_query_wait_time_ms. Summing per-interval minima and maxima inflates the output by the number of captured intervals and produces numbers the column names promise they won't. Changed the min_/max_ columns to MIN()/MAX(). Also changed avg_query_wait_time_ms from SUM() to AVG(); summed averages are the same kind of unit error. The outer GROUP BY is per (plan_id, wait_category_desc), so MIN/MAX/AVG land on the right scope. Left the HAVING SUM(min_query_wait_time_ms) > 0 as-is — as a gate for "any wait time recorded in any interval" it's correct and changing it would alter the row-filter semantics. total_query_wait_time_ms still uses SUM — that one matches its name. Verified the sproc installs and returns correctly-shaped wait output against PerformanceMonitor on SQL Server 2022. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ca2dbd8 commit 427fa9f

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

sp_QuickieStore/sp_QuickieStore.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10832,13 +10832,13 @@ SELECT
1083210832
total_query_wait_time_ms =
1083310833
SUM(qsws_with_lasts.total_query_wait_time_ms),
1083410834
avg_query_wait_time_ms =
10835-
SUM(qsws_with_lasts.avg_query_wait_time_ms),
10835+
AVG(qsws_with_lasts.avg_query_wait_time_ms),
1083610836
last_query_wait_time_ms =
1083710837
MAX(qsws_with_lasts.partitioned_last_query_wait_time_ms),
1083810838
min_query_wait_time_ms =
10839-
SUM(qsws_with_lasts.min_query_wait_time_ms),
10839+
MIN(qsws_with_lasts.min_query_wait_time_ms),
1084010840
max_query_wait_time_ms =
10841-
SUM(qsws_with_lasts.max_query_wait_time_ms)
10841+
MAX(qsws_with_lasts.max_query_wait_time_ms)
1084210842
FROM
1084310843
(
1084410844
SELECT

0 commit comments

Comments
 (0)