You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add @primary_window filter and resource_metrics XML to sp_QuickieStore @find_high_impact
New @primary_window parameter narrows @find_high_impact results to queries
whose majority activity falls in a single window. Accepts any prefix of
business / off-hours / weekend (case-insensitive, b/o/w is enough). Validated
up front: errors out unless @find_high_impact = 1 and the value starts with
b, o, or w. Filter is applied in the final dynamic SELECT as
WHERE o.primary_window LIKE 'Business%' (or 'Off-hours%' / 'Weekend%'),
leveraging the existing primary_window classification with its >50% rule.
Queries whose primary_window is 'Spread' are excluded by design.
The eight individual total_* columns plus max_dop in the @find_high_impact
result set are replaced with a single resource_metrics XML column. Built in
Step 6 of the #hi_output insert from #hi_scored using FOR XML PATH(N'metrics'),
TYPE with attribute-path aliases — native xml output, no string
concatenation. The XML also surfaces the avg/min/max per-execution metrics
that #hi_query_stats already computes but that previously weren't projected.
Shape:
<metrics>
<cpu total_ms avg_ms min_ms max_ms/>
<duration total_ms avg_ms min_ms max_ms/>
<physical_reads total_mb avg_mb min_mb max_mb/>
<writes total_mb avg_mb min_mb max_mb/>
<memory total_mb avg_mb min_mb max_mb/>
<tempdb total_mb avg_mb/>
<executions total/>
<rows total avg/>
<parallelism max_dop/>
</metrics>
Share columns (cpu_share, duration_share, etc.) are kept as dedicated
sortable columns rather than folded into the XML. The underlying total_*
and max_dop columns remain in #hi_output storage so debug dumps are
unaffected; only the final user-facing SELECT changed.
Help text updated: new @primary_window description/valid_inputs/defaults,
high_impact_columns section mentions resource_metrics and the filter hint,
debug parameter dump includes @primary_window.
Smoke-tested on sql2022 against StackOverflow2013: all three bucket
filters return only rows in that bucket, XML is well-formed with the
expected element/attribute shape.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: sp_QuickieStore/sp_QuickieStore.sql
+79-9Lines changed: 79 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -102,6 +102,7 @@ ALTER PROCEDURE
102
102
@include_query_hash_totals bit=0, /*will add an additional column to final output with total resource usage by query hash, may be skewed by query_hash and query_plan_hash bugs with forced plans/plan guides*/
103
103
@include_maintenance bit=0, /*Set this bit to 1 to add maintenance operations such as index creation to the result set*/
104
104
@find_high_impact bit=0, /*finds the vital few queries consuming disproportionate resources across cpu, duration, reads, writes, memory, and executions*/
105
+
@primary_window nvarchar(20) =NULL, /*with @find_high_impact, restricts results to queries whose majority activity is in this window: business, off-hours, or weekend*/
105
106
@help bit=0, /*return available parameter details, etc.*/
106
107
@debug bit=0, /*prints dynamic sql, statement length, parameter and variable values, and raw temp table contents*/
107
108
@troubleshoot_performance bit=0, /*set statistics xml on for queries against views*/
@@ -204,6 +205,7 @@ BEGIN
204
205
WHENN'@include_query_hash_totals'THENN'will add an additional column to final output with total resource usage by query hash, may be skewed by query_hash and query_plan_hash bugs with forced plans/plan guides'
205
206
WHENN'@include_maintenance'THENN'Set this bit to 1 to add maintenance operations such as index creation to the result set'
206
207
WHENN'@find_high_impact'THENN'finds the vital few queries consuming disproportionate resources across cpu, duration, reads, writes, memory, and executions'
208
+
WHENN'@primary_window'THENN'with @find_high_impact, restricts results to queries whose majority activity is in this window (business, off-hours, or weekend)'
207
209
WHENN'@help'THEN'how you got here'
208
210
WHENN'@debug'THEN'prints dynamic sql, statement length, parameter and variable values, and raw temp table contents'
209
211
WHENN'@troubleshoot_performance'THEN'set statistics xml on for queries against views'
0 commit comments