Commit e4b081f
Weight sp_HealthParser #tc wait average by waits count
The #tc aggregation rolls up #topwaits_count rows into wait_type /
rounded-time buckets. It summed the waits count correctly but took
AVG(tc.average_wait_time_ms) — an unweighted mean of already-averaged
per-event values. An event that contributed a single wait got the same
pull on the bucket's output as an event with thousands of waits, so
the displayed "average wait" skewed toward sparse outlier events.
Changed to a weighted average:
SUM(avg * waits) / NULLIF(SUM(waits), 0)
with CONVERT(decimal(38,2)) on the operands to avoid bigint
multiplication overflow on high-volume waits, and NULLIF to keep
the expression well-defined if every contributing row has
waits = 0. Result is CONVERT(bigint, ...) to preserve the existing
output type.
Left #td alone — its GROUP BY includes the metric columns themselves,
so that block is effectively a DISTINCT rather than an aggregation,
and is paired with a downstream ROW_NUMBER() dedupe step. Different
shape, different concern.
Verified the sproc installs clean and @what_to_check = 'waits' against
system_health runs without errors on SQL Server 2022.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8d54a5d commit e4b081f
1 file changed
Lines changed: 15 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2199 | 2199 | | |
2200 | 2200 | | |
2201 | 2201 | | |
2202 | | - | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
2203 | 2217 | | |
2204 | 2218 | | |
2205 | 2219 | | |
| |||
0 commit comments