Skip to content

Commit 2f3544b

Browse files
Merge fix/healthparser-wait-avg-weighting into dev
2 parents 8d54a5d + e4b081f commit 2f3544b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

sp_HealthParser/sp_HealthParser.sql

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,21 @@ AND ca.utc_timestamp < @end_date';
21992199
),
22002200
tc.wait_type,
22012201
waits = SUM(CONVERT(bigint, tc.waits)),
2202-
average_wait_time_ms = CONVERT(bigint, AVG(tc.average_wait_time_ms)),
2202+
/*
2203+
Weighted average rather than AVG(avg): tc.average_wait_time_ms
2204+
is already a per-event average, so AVG() over the bucket was
2205+
an unweighted mean of means — events with one wait got the
2206+
same pull on the output as events with thousands. Weight by
2207+
waits to get the true bucket-scoped average. NULLIF keeps us
2208+
safe if every contributing row had waits = 0.
2209+
*/
2210+
average_wait_time_ms =
2211+
CONVERT
2212+
(
2213+
bigint,
2214+
SUM(CONVERT(decimal(38, 2), tc.average_wait_time_ms) * CONVERT(decimal(38, 2), tc.waits))
2215+
/ NULLIF(SUM(CONVERT(decimal(38, 2), tc.waits)), 0)
2216+
),
22032217
max_wait_time_ms = CONVERT(bigint, MAX(tc.max_wait_time_ms))
22042218
INTO #tc
22052219
FROM #topwaits_count AS tc

0 commit comments

Comments
 (0)