Skip to content

Commit 58cc602

Browse files
Merge pull request #752 from erikdarlingdata/dev
Merge dev to main: help parameter ordering + QuickieCache help update
2 parents 6f8692c + fee775e commit 58cc602

11 files changed

Lines changed: 113 additions & 24 deletions

File tree

sp_HealthParser/sp_HealthParser.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ BEGIN
171171
ON ap.system_type_id = t.system_type_id
172172
AND ap.user_type_id = t.user_type_id
173173
WHERE o.name = N'sp_HealthParser'
174+
ORDER BY
175+
ap.parameter_id
174176
OPTION(RECOMPILE);
175177

176178
SELECT

sp_HumanEvents/sp_HumanEvents.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ BEGIN
243243
JOIN sys.types AS t
244244
ON ap.system_type_id = t.system_type_id
245245
AND ap.user_type_id = t.user_type_id
246-
WHERE o.name = N'sp_HumanEvents';
246+
WHERE o.name = N'sp_HumanEvents'
247+
ORDER BY
248+
ap.parameter_id
249+
OPTION(RECOMPILE);
247250

248251

249252
/*Example calls*/

sp_HumanEvents/sp_HumanEventsBlockViewer.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ BEGIN
193193
ON ap.system_type_id = t.system_type_id
194194
AND ap.user_type_id = t.user_type_id
195195
WHERE o.name = N'sp_HumanEventsBlockViewer'
196+
ORDER BY
197+
ap.parameter_id
196198
OPTION(RECOMPILE);
197199

198200
SELECT

sp_IndexCleanup/sp_IndexCleanup.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ BEGIN TRY
201201
ON ap.system_type_id = t.system_type_id
202202
AND ap.user_type_id = t.user_type_id
203203
WHERE o.name = N'sp_IndexCleanup'
204+
ORDER BY
205+
ap.parameter_id
204206
OPTION(MAXDOP 1, RECOMPILE);
205207

206208
SELECT

sp_LogHunter/sp_LogHunter.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ BEGIN
138138
ON ap.system_type_id = t.system_type_id
139139
AND ap.user_type_id = t.user_type_id
140140
WHERE o.name = N'sp_LogHunter'
141+
ORDER BY
142+
ap.parameter_id
141143
OPTION(RECOMPILE);
142144

143145
SELECT

sp_PerfCheck/sp_PerfCheck.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ BEGIN
130130
ON ap.system_type_id = t.system_type_id
131131
AND ap.user_type_id = t.user_type_id
132132
WHERE o.name = N'sp_PerfCheck'
133+
ORDER BY
134+
ap.parameter_id
133135
OPTION(MAXDOP 1, RECOMPILE);
134136

135137
SELECT

sp_PressureDetector/sp_PressureDetector.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ BEGIN
179179
ON ap.system_type_id = t.system_type_id
180180
AND ap.user_type_id = t.user_type_id
181181
WHERE o.name = N'sp_PressureDetector'
182+
ORDER BY
183+
ap.parameter_id
182184
OPTION(MAXDOP 1, RECOMPILE);
183185

184186
SELECT

sp_QueryReproBuilder/sp_QueryReproBuilder.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ BEGIN
171171
ON ap.system_type_id = t.system_type_id
172172
AND ap.user_type_id = t.user_type_id
173173
WHERE o.name = N'sp_QueryReproBuilder'
174+
ORDER BY
175+
ap.parameter_id
174176
OPTION(RECOMPILE);
175177

176178
RETURN;

sp_QueryStoreCleanup/sp_QueryStoreCleanup.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ BEGIN
160160
ON ap.system_type_id = t.system_type_id
161161
AND ap.user_type_id = t.user_type_id
162162
WHERE o.name = N'sp_QueryStoreCleanup'
163+
ORDER BY
164+
ap.parameter_id
163165
OPTION(MAXDOP 1, RECOMPILE);
164166

165167
/*

sp_QuickieCache/sp_QuickieCache.sql

Lines changed: 91 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ GO
5454
ALTER PROCEDURE
5555
dbo.sp_QuickieCache
5656
(
57-
@top integer = 10, /*candidates per metric dimension before dedup*/
57+
@top bigint = 10, /*candidates per metric dimension before dedup*/
5858
@sort_order varchar(20) = 'cpu', /*secondary sort after impact_score: cpu, duration, reads, writes, memory, spills, executions*/
5959
@database_name sysname = NULL, /*filter to a specific database*/
6060
@start_date datetime = NULL, /*only include plans created after this date*/
@@ -84,6 +84,21 @@ BEGIN
8484
*/
8585
IF @help = 1
8686
BEGIN
87+
/*
88+
Introduction
89+
*/
90+
SELECT
91+
introduction =
92+
'hi, i''m sp_QuickieCache!' UNION ALL
93+
SELECT 'you got me from https://code.erikdarling.com' UNION ALL
94+
SELECT 'i analyze the plan cache to find the vital few queries consuming disproportionate resources' UNION ALL
95+
SELECT 'think of me as the plan cache companion to sp_QuickieStore' UNION ALL
96+
SELECT 'i score queries across 7 dimensions using Pareto (80/20) analysis' UNION ALL
97+
SELECT 'from your loving sql server consultant, erik darling: https://erikdarling.com';
98+
99+
/*
100+
Parameters
101+
*/
87102
SELECT
88103
parameter_name =
89104
ap.name,
@@ -92,44 +107,97 @@ BEGIN
92107
description =
93108
CASE ap.name
94109
WHEN N'@top'
95-
THEN N'Number of candidate queries per metric dimension (cpu, reads, etc.) before dedup. Default: 10.'
110+
THEN N'candidates per metric dimension before dedup'
111+
WHEN N'@sort_order'
112+
THEN N'secondary sort after impact_score'
113+
WHEN N'@database_name'
114+
THEN N'filter to a specific database'
115+
WHEN N'@start_date'
116+
THEN N'only include plans created after this date'
117+
WHEN N'@end_date'
118+
THEN N'only include plans created before this date'
119+
WHEN N'@minimum_execution_count'
120+
THEN N'minimum execution count to include a query'
121+
WHEN N'@ignore_system_databases'
122+
THEN N'exclude system databases (master, model, msdb, tempdb)'
123+
WHEN N'@impact_threshold'
124+
THEN N'minimum impact_score to surface in results'
125+
WHEN N'@debug'
126+
THEN N'print diagnostic information'
127+
WHEN N'@help'
128+
THEN N'how you got here'
129+
WHEN N'@version'
130+
THEN N'OUTPUT; for support'
131+
WHEN N'@version_date'
132+
THEN N'OUTPUT; for support'
133+
ELSE N''
134+
END,
135+
valid_inputs =
136+
CASE ap.name
137+
WHEN N'@top'
138+
THEN N'a positive integer'
96139
WHEN N'@sort_order'
97-
THEN N'Secondary sort after impact_score. Options: cpu, duration, reads, writes, memory, spills, executions. Default: cpu.'
140+
THEN N'cpu, duration, reads, writes, memory, spills, executions'
98141
WHEN N'@database_name'
99-
THEN N'Filter to a specific database. Default: NULL (all user databases).'
142+
THEN N'a valid database name'
100143
WHEN N'@start_date'
101-
THEN N'Only include plans created after this date. Default: NULL (no filter).'
144+
THEN N'a valid datetime'
102145
WHEN N'@end_date'
103-
THEN N'Only include plans created before this date. Default: NULL (no filter).'
146+
THEN N'a valid datetime'
104147
WHEN N'@minimum_execution_count'
105-
THEN N'Minimum execution count to include a query. Filters single-execution noise. Default: 2.'
148+
THEN N'a positive integer'
106149
WHEN N'@ignore_system_databases'
107-
THEN N'Exclude system databases (master, model, msdb, tempdb). Default: 1.'
150+
THEN N'0 or 1'
108151
WHEN N'@impact_threshold'
109-
THEN N'Minimum impact_score (0.00-1.00) to surface in results. Default: 0.50.'
152+
THEN N'0.00 to 1.00'
110153
WHEN N'@debug'
111-
THEN N'Print diagnostic information. Default: 0.'
154+
THEN N'0 or 1'
112155
WHEN N'@help'
113-
THEN N'You are here. Default: 0.'
156+
THEN N'0 or 1'
114157
WHEN N'@version'
115-
THEN N'OUTPUT; for support.'
158+
THEN N'none; OUTPUT'
116159
WHEN N'@version_date'
117-
THEN N'OUTPUT; for support.'
160+
THEN N'none; OUTPUT'
161+
ELSE N''
162+
END,
163+
defaults =
164+
CASE ap.name
165+
WHEN N'@top'
166+
THEN N'10'
167+
WHEN N'@sort_order'
168+
THEN N'cpu'
169+
WHEN N'@database_name'
170+
THEN N'NULL'
171+
WHEN N'@start_date'
172+
THEN N'NULL'
173+
WHEN N'@end_date'
174+
THEN N'NULL'
175+
WHEN N'@minimum_execution_count'
176+
THEN N'2'
177+
WHEN N'@ignore_system_databases'
178+
THEN N'1'
179+
WHEN N'@impact_threshold'
180+
THEN N'0.50'
181+
WHEN N'@debug'
182+
THEN N'0'
183+
WHEN N'@help'
184+
THEN N'0'
185+
WHEN N'@version'
186+
THEN N'none; OUTPUT'
187+
WHEN N'@version_date'
188+
THEN N'none; OUTPUT'
118189
ELSE N''
119190
END
120191
FROM sys.all_parameters AS ap
192+
JOIN sys.all_objects AS o
193+
ON ap.object_id = o.object_id
121194
JOIN sys.types AS t
122-
ON t.user_type_id = ap.user_type_id
123-
WHERE ap.object_id = @@PROCID
195+
ON ap.system_type_id = t.system_type_id
196+
AND ap.user_type_id = t.user_type_id
197+
WHERE o.name = N'sp_QuickieCache'
124198
ORDER BY
125-
ap.parameter_id;
126-
127-
SELECT
128-
methodology = N'Pareto (80/20) analysis across 7 resource dimensions',
129-
dimensions = N'CPU, Duration, Logical Reads, Logical Writes, Memory Grants, Spills, Executions',
130-
scoring = N'PERCENT_RANK per dimension, averaged across active dimensions (>= 0.1% of total)',
131-
high_signal = N'Dimensions where query ranks >= 80th percentile',
132-
output = N'Queries with impact_score >= @impact_threshold, plus workload profile summary';
199+
ap.parameter_id
200+
OPTION(MAXDOP 1, RECOMPILE);
133201

134202
/*
135203
License to F5

0 commit comments

Comments
 (0)