Skip to content

Commit a2c4823

Browse files
sp_QuickieStore: fix @find_high_impact output formatting
- query_sql_text now uses processing-instruction XML pattern (clickable in SSMS without encoding issues), matching the main output path - top_waits column and LEFT JOIN conditionally omitted when Query Store wait stats are unavailable (SQL 2016 or waits not enabled) instead of showing a NULL column - Updated help text to reflect conditional top_waits behavior Tested on SQL2022 (waits present) and SQL2016 (waits omitted). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9229a59 commit a2c4823

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

sp_QuickieStore/sp_QuickieStore.sql

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ BEGIN
398398
SELECT 'object_name: the stored procedure, function, or trigger this query belongs to, or "Adhoc" for ad hoc SQL' UNION ALL
399399
SELECT 'query_sql_text: representative query text (the most-executed variant for this query_hash)' UNION ALL
400400
SELECT 'query_plan: the most recent execution plan (XML) for this query_hash' UNION ALL
401-
SELECT 'top_waits: top 3 Query Store wait categories with total wait time in ms (SQL 2017+ only, NULL on 2016)' UNION ALL
401+
SELECT 'top_waits: top 3 Query Store wait categories with total wait time in ms (SQL 2017+ with wait stats enabled, omitted otherwise)' UNION ALL
402402
SELECT 'query_hash: the query_hash that groups all parameterized variants of the same query' UNION ALL
403403
SELECT 'query_count: how many distinct query_ids share this hash (parameterized variants)' UNION ALL
404404
SELECT 'plan_count: how many distinct plans exist across all variants. >1 may indicate plan instability.' UNION ALL
@@ -5155,11 +5155,31 @@ SELECT
51555155
END + N',
51565156
pw.primary_window,
51575157
qi.object_name,
5158-
rt.query_sql_text,
5158+
query_sql_text =
5159+
(
5160+
SELECT
5161+
[processing-instruction(query)] =
5162+
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
5163+
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
5164+
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
5165+
rt.query_sql_text COLLATE Latin1_General_BIN2,
5166+
NCHAR(31),N''?''),NCHAR(30),N''?''),NCHAR(29),N''?''),NCHAR(28),N''?''),NCHAR(27),N''?''),NCHAR(26),N''?''),NCHAR(25),N''?''),NCHAR(24),N''?''),NCHAR(23),N''?''),NCHAR(22),N''?''),
5167+
NCHAR(21),N''?''),NCHAR(20),N''?''),NCHAR(19),N''?''),NCHAR(18),N''?''),NCHAR(17),N''?''),NCHAR(16),N''?''),NCHAR(15),N''?''),NCHAR(14),N''?''),NCHAR(12),N''?''),
5168+
NCHAR(11),N''?''),NCHAR(8),N''?''),NCHAR(7),N''?''),NCHAR(6),N''?''),NCHAR(5),N''?''),NCHAR(4),N''?''),NCHAR(3),N''?''),NCHAR(2),N''?''),NCHAR(1),N''?''),NCHAR(0),N'''')
5169+
FOR XML
5170+
PATH(N''''),
5171+
TYPE
5172+
),
51595173
query_plan =
51605174
TRY_CONVERT(xml, qp.query_plan),
5161-
qw.top_waits,
5162-
s.query_hash,
5175+
' +
5176+
CASE
5177+
WHEN @new = 1
5178+
AND @query_store_waits_enabled = 1
5179+
THEN N'qw.top_waits,
5180+
'
5181+
ELSE N''
5182+
END + N's.query_hash,
51635183
s.query_count,
51645184
s.plan_count,
51655185
qi.query_id_list,
@@ -5493,9 +5513,15 @@ LEFT JOIN #hi_query_identifiers AS qi
54935513
ON s.query_hash = qi.query_hash
54945514
LEFT JOIN #hi_primary_window AS pw
54955515
ON s.query_hash = pw.query_hash
5496-
LEFT JOIN #hi_query_waits AS qw
5516+
' +
5517+
CASE
5518+
WHEN @new = 1
5519+
AND @query_store_waits_enabled = 1
5520+
THEN N'LEFT JOIN #hi_query_waits AS qw
54975521
ON s.query_hash = qw.query_hash
5498-
OUTER APPLY
5522+
'
5523+
ELSE N''
5524+
END + N'OUTER APPLY
54995525
(
55005526
SELECT TOP (1)
55015527
qsp.query_plan

0 commit comments

Comments
 (0)