Skip to content

Commit a08cdb3

Browse files
Collapse per-metric totals in sp_QuickieCache into a resource_metrics XML column
Mirrors the compact XML rollup just added to sp_QuickieStore @find_high_impact. Twelve individual columns (total_cpu_ms, total_duration_ms, total_physical_reads, total_logical_writes, total_grant_mb, total_spills, max_grant_mb, max_used_grant_mb, max_spills, max_dop, min_rows, max_rows) are replaced with a single clickable resource_metrics xml column in the main result set. Built during the #scored insert using FOR XML PATH(N'metrics'), TYPE with attribute-path aliases — native xml, no STRING_AGG and no string concatenation. avg_* attributes are computed inline as total / NULLIF(total_executions, 0) and surface per-execution metrics that previously weren't exposed anywhere in the output. Shape: <metrics> <cpu total_ms avg_ms min_ms max_ms/> <duration total_ms avg_ms min_ms max_ms/> <physical_reads total avg min max/> <logical_writes total avg/> <rows total avg min max/> <grant total_mb avg_mb max_mb/> <used_grant total_mb avg_mb max_mb/> <spills total avg max/> <executions total/> <parallelism max_dop/> </metrics> No time-of-day / primary_window filter here (unlike sp_QuickieStore) — the plan cache DMVs don't carry per-interval execution metadata, so there's nothing to classify Business / Off-hours / Weekend activity against. Share columns (cpu_share, duration_share, etc.) remain as dedicated sortable columns. Smoke-tested on sql2022: installed cleanly, ran end-to-end, resource_metrics is well-formed XML with all expected child elements. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3e168e6 commit a08cdb3

1 file changed

Lines changed: 43 additions & 12 deletions

File tree

sp_QuickieCache/sp_QuickieCache.sql

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,9 @@ OPTION(RECOMPILE, MAXDOP 1);';
17361736
high_signals nvarchar(500) NULL,
17371737
diagnostics nvarchar(max) NULL,
17381738

1739+
/* resource rollup */
1740+
resource_metrics xml NULL,
1741+
17391742
/* plan metadata */
17401743
oldest_plan_creation datetime NULL,
17411744
newest_plan_creation datetime NULL,
@@ -1792,6 +1795,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
17921795
grant_pctl,
17931796
spills_pctl,
17941797
executions_pctl,
1798+
resource_metrics,
17951799
oldest_plan_creation,
17961800
newest_plan_creation,
17971801
last_execution_time,
@@ -1955,6 +1959,44 @@ OPTION(RECOMPILE, MAXDOP 1);';
19551959
ELSE NULL
19561960
END,
19571961

1962+
resource_metrics =
1963+
(
1964+
SELECT
1965+
[cpu/@total_ms] = qs.total_cpu_ms,
1966+
[cpu/@avg_ms] = qs.total_cpu_ms / NULLIF(qs.total_executions, 0),
1967+
[cpu/@min_ms] = qs.min_cpu_ms,
1968+
[cpu/@max_ms] = qs.max_cpu_ms,
1969+
[duration/@total_ms] = qs.total_duration_ms,
1970+
[duration/@avg_ms] = qs.total_duration_ms / NULLIF(qs.total_executions, 0),
1971+
[duration/@min_ms] = qs.min_duration_ms,
1972+
[duration/@max_ms] = qs.max_duration_ms,
1973+
[physical_reads/@total] = qs.total_physical_reads,
1974+
[physical_reads/@avg] = CONVERT(decimal(38, 2), qs.total_physical_reads) / NULLIF(qs.total_executions, 0),
1975+
[physical_reads/@min] = qs.min_physical_reads,
1976+
[physical_reads/@max] = qs.max_physical_reads,
1977+
[logical_writes/@total] = qs.total_logical_writes,
1978+
[logical_writes/@avg] = CONVERT(decimal(38, 2), qs.total_logical_writes) / NULLIF(qs.total_executions, 0),
1979+
[rows/@total] = qs.total_rows,
1980+
[rows/@avg] = CONVERT(decimal(38, 2), qs.total_rows) / NULLIF(qs.total_executions, 0),
1981+
[rows/@min] = qs.min_rows,
1982+
[rows/@max] = qs.max_rows,
1983+
[grant/@total_mb] = qs.total_grant_mb,
1984+
[grant/@avg_mb] = qs.total_grant_mb / NULLIF(qs.total_executions, 0),
1985+
[grant/@max_mb] = qs.max_grant_mb,
1986+
[used_grant/@total_mb] = qs.total_used_grant_mb,
1987+
[used_grant/@avg_mb] = qs.total_used_grant_mb / NULLIF(qs.total_executions, 0),
1988+
[used_grant/@max_mb] = qs.max_used_grant_mb,
1989+
[spills/@total] = qs.total_spills,
1990+
[spills/@avg] = CONVERT(decimal(38, 2), qs.total_spills) / NULLIF(qs.total_executions, 0),
1991+
[spills/@max] = qs.max_spills,
1992+
[executions/@total] = qs.total_executions,
1993+
[parallelism/@max_dop] = qs.max_dop
1994+
FOR
1995+
XML
1996+
PATH(N'metrics'),
1997+
TYPE
1998+
),
1999+
19582000
oldest_plan_creation = qs.oldest_plan_creation,
19592001
newest_plan_creation = qs.newest_plan_creation,
19602002
last_execution_time = qs.last_execution_time,
@@ -2338,18 +2380,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
23382380
s.spills_share,
23392381
s.executions_share,
23402382
s.diagnostics,
2341-
s.total_cpu_ms,
2342-
s.total_duration_ms,
2343-
s.total_physical_reads,
2344-
s.total_logical_writes,
2345-
s.total_grant_mb,
2346-
s.total_spills,
2347-
s.max_grant_mb,
2348-
s.max_used_grant_mb,
2349-
s.max_spills,
2350-
s.max_dop,
2351-
s.min_rows,
2352-
s.max_rows,
2383+
s.resource_metrics,
23532384
s.oldest_plan_creation,
23542385
s.last_execution_time,
23552386
s.sample_sql_handle,

0 commit comments

Comments
 (0)