5454ALTER 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*/
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