Skip to content

Commit a0ec444

Browse files
Merge pull request #495 from ReeceGoding/MoreExamples
sp_QuickieStore: Add more examples to the examples file.
2 parents c5e95ff + 6f66b44 commit a0ec444

File tree

1 file changed

+180
-7
lines changed

1 file changed

+180
-7
lines changed

sp_QuickieStore/Examples.sql

Lines changed: 180 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ https://github.com/erikdarlingdata/DarlingData
2424
EXEC dbo.sp_QuickieStore
2525
@help = 1;
2626

27+
/*The default is finding the top 10 sorted by CPU in the last seven days.*/
28+
EXEC dbo.sp_QuickieStore
29+
@database_name = 'StackOverflow2013';
2730

2831
/*Find top 10 sorted by memory*/
2932
EXEC dbo.sp_QuickieStore
3033
@database_name = 'StackOverflow2013',
3134
@sort_order = 'memory',
32-
@top = 10;
35+
@top = 10;
3336

37+
/*Find top 10 in each user database sorted by cpu*/
38+
EXEC dbo.sp_QuickieStore
39+
@get_all_databases = 1,
40+
@sort_order = 'cpu',
41+
@top = 10;
3442

3543
/*Search for specific query_ids*/
3644
EXEC dbo.sp_QuickieStore
@@ -72,6 +80,13 @@ EXEC dbo.sp_QuickieStore
7280
@start_date = '20210320',
7381
@end_date = '20210321';
7482

83+
/*Filter out weekends and anything outside of your choice of hours.*/
84+
EXEC dbo.sp_QuickieStore
85+
@database_name = 'StackOverflow2013',
86+
@workdays = 1,
87+
@work_start = '8am',
88+
@work_end = '6pm'
89+
7590

7691
/*Search for queries with a minimum execution count*/
7792
EXEC dbo.sp_QuickieStore
@@ -87,6 +102,26 @@ EXEC dbo.sp_QuickieStore
87102
@duration_ms = 10000;
88103

89104

105+
/*Use wait filter to search for queries responsible for high waits*/
106+
EXEC dbo.sp_QuickieStore
107+
@database_name = 'StackOverflow2013',
108+
@wait_filter = 'memory',
109+
@sort_order = 'memory';
110+
111+
/*We also support using wait types as a sort order, see the documentation for the full list.
112+
The wait-related sort orders are special because we add an extra column for the duration of the wait type you are asking for.
113+
It's all the way over on the right.
114+
*/
115+
EXEC dbo.sp_QuickieStore
116+
@database_name = 'StackOverflow2013',
117+
@sort_order = 'memory waits';
118+
119+
/*You can also sort by total wait time across all waits. */
120+
EXEC dbo.sp_QuickieStore
121+
@database_name = 'StackOverflow2013',
122+
@sort_order = 'total waits';
123+
124+
90125
/*Search for queries with a specific execution type
91126
When we do not provide this parameter, we grab all types.
92127
This example grabs "aborted" queries, which are queries cancelled by the client.
@@ -120,13 +155,101 @@ EXEC dbo.sp_QuickieStore
120155
/*Search for a specific stored procedure*/
121156
EXEC dbo.sp_QuickieStore
122157
@database_name = 'StackOverflow2013',
123-
@procedure_name = 'top_percent_sniffer';
158+
@procedure_name = 'top_percent_sniffer';
159+
160+
/*Search for a specific stored procedure in a specific schema*/
161+
EXEC dbo.sp_QuickieStore
162+
@database_name = 'StackOverflow2013',
163+
@procedure_schema = 'not_dbo'
164+
@procedure_name = 'top_percent_sniffer';
124165

125166
/*Search for specific query text*/
126167
EXEC dbo.sp_QuickieStore
127168
@database_name = 'StackOverflow2013',
128169
@query_text_search = 'WITH Comment'
129170

171+
/*Search for specific query text, with brackets automatically escaped.
172+
Commonly needed when dealing with ORM queries.
173+
*/
174+
EXEC dbo.sp_QuickieStore
175+
@database_name = 'StackOverflow2013',
176+
@query_text_search = 'FROM [users] AS [t0]',
177+
@escape_brackets = 1;
178+
179+
/*By default, We use '\' to escape when @escape_brackets = 1 is set.
180+
Maybe you want something else.
181+
Provide it with @escape_character.
182+
*/
183+
EXEC dbo.sp_QuickieStore
184+
@database_name = 'StackOverflow2013',
185+
@query_text_search = 'FROM foo\bar AS [t0]',
186+
@escape_character = '~'
187+
@escape_brackets = 1;
188+
189+
190+
/*Find every reference to a particular table in your Query Store data, sorted by their execution counts.
191+
Quite expensive!
192+
Handy when tuning or finding dependencies, but only as good as what your Query Store has captured.
193+
Makes use of @get_all_databases = 1, which lets you search all user databases.
194+
Note the abuse of @start_date. By setting it very far back in the past and leaving @end_date unspecified, we cover all of the data.
195+
We also abuse @top by setting it very high.
196+
*/
197+
EXEC dbo.sp_QuickieStore
198+
@get_all_databases = 1,
199+
@start_date = '20000101',
200+
@sort_order = 'executions',
201+
@query_text_search = 'MyTable',
202+
@top = 100;
203+
204+
/*Filter out certain query text with @query_text_search_not.
205+
Good for when @query_text_search gets false positives.
206+
After all, it's only doing string searching.
207+
*/
208+
EXEC dbo.sp_QuickieStore
209+
@get_all_databases = 1,
210+
@start_date = '20000101',
211+
@sort_order = 'executions',
212+
@query_text_search = 'MyTable',
213+
@query_text_search_not = 'MyTable_secret_backup'
214+
@top = 100;
215+
216+
217+
/*What happened recently on a database?*/
218+
EXEC dbo.sp_QuickieStore
219+
@database_name = 'StackOverflow2013'
220+
@sort_order = 'recent';
221+
222+
/*What happened recently that referenced my database?
223+
Good for finding cross-database queries, such as when checking if a database is dead code.
224+
Don't forget that queries in a database do not need to reference it explicitly!
225+
*/
226+
EXEC dbo.sp_QuickieStore
227+
@get_all_databases = 1,
228+
@start_date = '20000101',
229+
@sort_order = 'recent',
230+
@query_text_search = 'StackOverflow2013'
231+
@top = 10;
232+
233+
/*Only return queries with feedback (2022+)*/
234+
EXEC dbo.sp_QuickieStore
235+
@database_name = 'StackOverflow2013',
236+
@only_query_with_feedback = 1;
237+
238+
/*Only return queries with variants (2022+)*/
239+
EXEC dbo.sp_QuickieStore
240+
@database_name = 'StackOverflow2013',
241+
@only_query_with_variants = 1;
242+
243+
/*Only return queries with forced plans (2022+)*/
244+
EXEC dbo.sp_QuickieStore
245+
@database_name = 'StackOverflow2013',
246+
@only_query_with_forced_plans = 1;
247+
248+
/*Only return queries with forced plan failures (2022+)*/
249+
EXEC dbo.sp_QuickieStore
250+
@database_name = 'StackOverflow2013',
251+
@only_query_with_forced_plan_failures = 1;
252+
130253
/*Only return queries with query hints (2022+)*/
131254
EXEC dbo.sp_QuickieStore
132255
@database_name = 'StackOverflow2013',
@@ -140,19 +263,38 @@ EXEC dbo.sp_QuickieStore
140263
@expert_mode = 1;
141264

142265

143-
/*Use format output to add commas to larger numbers*/
266+
/*Use format output to add commas to larger numbers
267+
This is enabled by default.
268+
*/
144269
EXEC dbo.sp_QuickieStore
145270
@database_name = 'StackOverflow2013',
146271
@sort_order = 'memory',
147272
@top = 10,
148273
@format_output = 1;
149274

275+
/*Disable format output to remove commas.*/
276+
EXEC dbo.sp_QuickieStore
277+
@database_name = 'StackOverflow2013',
278+
@sort_order = 'memory',
279+
@top = 10,
280+
@format_output = 0;
150281

151-
/*Use wait filter to search for queries responsible for high waits*/
282+
/*Change the timezone show in your outputs.
283+
This is only an output-formatting change.
284+
It does not change how dates are processed.
285+
*/
152286
EXEC dbo.sp_QuickieStore
153287
@database_name = 'StackOverflow2013',
154-
@wait_filter = 'memory',
155-
@sort_order = 'memory';
288+
@timezone = 'Egypt Standard Time';
289+
290+
/*Debugging something complex?
291+
Hide the bottom table with @hide_help_table = 1 when you need more room.
292+
*/
293+
EXEC dbo.sp_QuickieStore
294+
@database_name = 'StackOverflow2013',
295+
@hide_help_table = 1,
296+
@sort_order = 'latch waits',
297+
@top = 50;
156298

157299
/*Search by query hashes*/
158300
EXEC dbo.sp_QuickieStore
@@ -170,6 +312,27 @@ EXEC dbo.sp_QuickieStore
170312
@include_sql_handles =
171313
'0x0900F46AC89E66DF744C8A0AD4FD3D3306B90000000000000000000000000000000000000000000000000000,0x0200000AC89E66DF744C8A0AD4FD3D3306B90000000000000000000000000000000000000000000000000000';
172314

315+
/*Search, but ignoring some query hashes*/
316+
EXEC dbo.sp_QuickieStore
317+
@ignore_query_hashes = '0x1AB614B461F4D769,0x1CD777B461F4D769';
318+
319+
/*Search, but ignoring some plan hashes*/
320+
EXEC dbo.sp_QuickieStore
321+
@ignore_plan_hashes = '0x6B84B820B8B38564,0x6B84B999D7B38564';
322+
323+
/*Search, but ignoring some SQL Handles*/
324+
EXEC dbo.sp_QuickieStore
325+
@ignore_sql_handles =
326+
'0x0900F46AC89E66DF744C8A0AD4FD3D3306B90000000000000000000000000000000000000000000000000000,0x0200000AC89E66DF744C8A0AD4FD3D3306B90000000000000000000000000000000000000000000000000000';
327+
328+
/*What query hashes have the most plans?
329+
This sort order is special because it needs to return multiple rows for each of the @top hashes it looks at.
330+
It is also special because it adds some new columns all the way over on the right of the output.
331+
*/
332+
EXEC dbo.sp_QuickieStore
333+
@database_name = 'StackOverflow2013',
334+
@sort_order = 'plan count by hashes';
335+
173336
/*Check for regressions.
174337
Specifically, this checks for queries that did more logical reads last week than this week.
175338
The default dates are helpful here. The default @start_date and @end_date specify last week for us and @regression_baseline_end_date defaults to being one week after @regression_baseline_start_date.
@@ -243,13 +406,23 @@ EXEC dbo.sp_QuickieStore
243406
@regression_direction = 'absolute',
244407
@regression_baseline_start_date = @TwoWeekAgo;
245408

409+
/*Get version info.*/
410+
DECLARE @version_output varchar(30),
411+
@version_date_output datetime;
412+
413+
EXEC sp_QuickieStore
414+
@version = @version_output OUTPUT,
415+
@version_date = @version_date_output OUTPUT;
416+
417+
SELECT
418+
Version = @version_output,
419+
VersionDate = @version_date_output;
246420

247421
/*Troubleshoot performance*/
248422
EXEC dbo.sp_QuickieStore
249423
@database_name = 'StackOverflow2013',
250424
@troubleshoot_performance = 1;
251425

252-
253426
/*Debug dynamic SQL and temp table contents*/
254427
EXEC dbo.sp_QuickieStore
255428
@database_name = 'StackOverflow2013',

0 commit comments

Comments
 (0)