Skip to content

Commit

Permalink
Merge pull request #501 from erikdarlingdata/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
erikdarlingdata authored Nov 9, 2024
2 parents a38e861 + 2f05682 commit 8734278
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Current valid parameter details:
| parameter_name | data_type | description | valid_inputs | defaults |
|-----------------------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| @database_name | sysname | the name of the database you want to look at query store in | a database name with query store enabled | NULL; current database name if NULL |
| @sort_order | varchar | the runtime metric you want to prioritize results by | cpu, logical reads, physical reads, writes, duration, memory, tempdb, executions, recent, plan count by hashes, cpu waits, lock waits, locks waits, latch waits, latches waits, buffer latch waits, buffer latches waits, buffer io waits, log waits, log io waits, network waits, network io waits, parallel waits, parallelism waits, memory waits, total waits | cpu |
| @sort_order | varchar | the runtime metric you want to prioritize results by | cpu, logical reads, physical reads, writes, duration, memory, tempdb, executions, recent, plan count by hashes, cpu waits, lock waits, locks waits, latch waits, latches waits, buffer latch waits, buffer latches waits, buffer io waits, log waits, log io waits, network waits, network io waits, parallel waits, parallelism waits, memory waits, total waits, rows | cpu |
| @top | bigint | the number of queries you want to pull back | a positive integer between 1 and 9,223,372,036,854,775,807 | 10 |
| @start_date | datetimeoffset | the begin date of your search, will be converted to UTC internally | January 1, 1753, through December 31, 9999 | the last seven days |
| @end_date | datetimeoffset | the end date of your search, will be converted to UTC internally | January 1, 1753, through December 31, 9999 | NULL |
Expand Down
10 changes: 9 additions & 1 deletion sp_QuickieStore/Examples.sql
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ EXEC dbo.sp_QuickieStore
/*Search for specific query text*/
EXEC dbo.sp_QuickieStore
@database_name = 'StackOverflow2013',
@query_text_search = 'WITH Comment'
@query_text_search = 'WITH Comment';

/*Search for specific query text, with brackets automatically escaped.
Commonly needed when dealing with ORM queries.
Expand Down Expand Up @@ -418,6 +418,14 @@ SELECT
Version = @version_output,
VersionDate = @version_date_output;

/*Search for queries that take a while and return lots of rows on average*/
EXEC dbo.sp_QuickieStore
@database_name = 'StackOverflow2013',
@top = 10,
@sort_order = 'rows',
@duration_ms = 20000;


/*Troubleshoot performance*/
EXEC dbo.sp_QuickieStore
@database_name = 'StackOverflow2013',
Expand Down
16 changes: 14 additions & 2 deletions sp_QuickieStore/sp_QuickieStore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ BEGIN
CASE
ap.name
WHEN N'@database_name' THEN 'a database name with query store enabled'
WHEN N'@sort_order' THEN 'cpu, logical reads, physical reads, writes, duration, memory, tempdb, executions, recent, plan count by hashes, cpu waits, lock waits, locks waits, latch waits, latches waits, buffer latch waits, buffer latches waits, buffer io waits, log waits, log io waits, network waits, network io waits, parallel waits, parallelism waits, memory waits, total waits'
WHEN N'@sort_order' THEN 'cpu, logical reads, physical reads, writes, duration, memory, tempdb, executions, recent, plan count by hashes, cpu waits, lock waits, locks waits, latch waits, latches waits, buffer latch waits, buffer latches waits, buffer io waits, log waits, log io waits, network waits, network io waits, parallel waits, parallelism waits, memory waits, total waits, rows'
WHEN N'@top' THEN 'a positive integer between 1 and 9,223,372,036,854,775,807'
WHEN N'@start_date' THEN 'January 1, 1753, through December 31, 9999'
WHEN N'@end_date' THEN 'January 1, 1753, through December 31, 9999'
Expand Down Expand Up @@ -2658,7 +2658,8 @@ IF @sort_order NOT IN
'parallel waits',
'parallelism waits',
'memory waits',
'total waits'
'total waits',
'rows'
)
BEGIN
RAISERROR('The sort order (%s) you chose is so out of this world that I''m using cpu instead', 10, 1, @sort_order) WITH NOWAIT;
Expand Down Expand Up @@ -5534,6 +5535,7 @@ BEGIN
WHEN 'memory' THEN N'qsrs.avg_query_max_used_memory'
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used' ELSE N'qsrs.avg_cpu_time' END
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms' ELSE N'qsrs.avg_cpu_time' END
END
+ N' ))
Expand Down Expand Up @@ -5631,6 +5633,7 @@ BEGIN
WHEN 'memory' THEN N'qsrs.avg_query_max_used_memory'
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used' ELSE N'qsrs.avg_cpu_time' END
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms' ELSE N'qsrs.avg_cpu_time' END
END
+ N' ))
Expand Down Expand Up @@ -5751,6 +5754,7 @@ BEGIN
WHEN 'memory' THEN N'(hashes_with_changes.change_since_regression_time_period * 8.) / 1024.'
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'(hashes_with_changes.change_since_regression_time_period * 8.) / 1024.' ELSE N'hashes_with_changes.change_since_regression_time_period / 1000.' END
WHEN 'executions' THEN N'hashes_with_changes.change_since_regression_time_period'
WHEN 'rows' THEN N'hashes_with_changes.change_since_regression_time_period'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'hashes_with_changes.change_since_regression_time_period / 1000.' ELSE N'hashes_with_changes.change_since_regression_time_period / 1000.' END
END
ELSE N'hashes_with_changes.change_since_regression_time_period' END
Expand Down Expand Up @@ -5958,6 +5962,7 @@ BEGIN
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used' ELSE N'qsrs.avg_cpu_time' END
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'recent' THEN N'qsrs.last_execution_time'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
ELSE N'qsrs.avg_cpu_time'
END +
N') DESC
Expand Down Expand Up @@ -6373,6 +6378,7 @@ SELECT
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used' ELSE N'qsrs.avg_cpu_time' END
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'recent' THEN N'qsrs.last_execution_time'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
WHEN 'plan count by hashes' THEN N'hashes.plan_hash_count_for_query_hash DESC, hashes.query_hash'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms' ELSE N'qsrs.avg_cpu_time' END
END
Expand Down Expand Up @@ -8243,6 +8249,7 @@ FROM
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used_mb' ELSE N'qsrs.avg_cpu_time' END
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'recent' THEN N'qsrs.last_execution_time'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
WHEN 'plan count by hashes' THEN N'hashes.plan_hash_count_for_query_hash DESC, hashes.query_hash'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms'
ELSE N'qsrs.avg_cpu_time' END
Expand Down Expand Up @@ -8534,6 +8541,7 @@ FROM
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used_mb' ELSE N'qsrs.avg_cpu_time' END
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'recent' THEN N'qsrs.last_execution_time'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
WHEN 'plan count by hashes' THEN N'hashes.plan_hash_count_for_query_hash DESC, hashes.query_hash'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms'
ELSE N'qsrs.avg_cpu_time' END
Expand Down Expand Up @@ -8785,6 +8793,7 @@ FROM
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used_mb' ELSE N'qsrs.avg_cpu_time' END
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'recent' THEN N'qsrs.last_execution_time'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
WHEN 'plan count by hashes' THEN N'hashes.plan_hash_count_for_query_hash DESC, hashes.query_hash'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms'
ELSE N'qsrs.avg_cpu_time' END
Expand Down Expand Up @@ -9045,6 +9054,7 @@ FROM
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'qsrs.avg_tempdb_space_used_mb' ELSE N'qsrs.avg_cpu_time' END
WHEN 'executions' THEN N'qsrs.count_executions'
WHEN 'recent' THEN N'qsrs.last_execution_time'
WHEN 'rows' THEN N'qsrs.avg_rowcount'
WHEN 'plan count by hashes' THEN N'hashes.plan_hash_count_for_query_hash DESC, hashes.query_hash'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'waits.total_query_wait_time_ms'
ELSE N'qsrs.avg_cpu_time' END
Expand Down Expand Up @@ -9322,6 +9332,7 @@ SELECT
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'x.avg_tempdb_space_used_mb' ELSE N'x.avg_cpu_time' END
WHEN 'executions' THEN N'x.count_executions'
WHEN 'recent' THEN N'x.last_execution_time'
WHEN 'rows' THEN N'x.avg_rowcount'
WHEN 'plan count by hashes' THEN N'x.plan_hash_count_for_query_hash DESC, x.query_hash_from_hash_counting'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'x.total_wait_time_from_sort_order_ms' ELSE N'x.avg_cpu_time' END
END END
Expand Down Expand Up @@ -9357,6 +9368,7 @@ SELECT
WHEN 'tempdb' THEN CASE WHEN @new = 1 THEN N'TRY_PARSE(x.avg_tempdb_space_used_mb AS money)' ELSE N'TRY_PARSE(x.avg_cpu_time AS money)' END
WHEN 'executions' THEN N'TRY_PARSE(x.count_executions AS money)'
WHEN 'recent' THEN N'x.last_execution_time'
WHEN 'rows' THEN N'TRY_PARSE(x.avg_rowcount AS money)'
WHEN 'plan count by hashes' THEN N'TRY_PARSE(x.plan_hash_count_for_query_hash AS money) DESC, x.query_hash_from_hash_counting'
ELSE CASE WHEN @sort_order_is_a_wait = 1 THEN N'TRY_PARSE(x.total_wait_time_from_sort_order_ms AS money)' ELSE N'TRY_PARSE(x.avg_cpu_time AS money)' END
END END
Expand Down

0 comments on commit 8734278

Please sign in to comment.