Skip to content

Commit db4803e

Browse files
authored
#2172 sp_BlitzCache BringThePain (#2201)
If you use SortOrder = all and Top > 10, you now have to set BringThePain = 1. Closes #2172.
1 parent 310618a commit db4803e

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ The @SortOrder parameter lets you pick which top 10 queries you want to examine:
152152
* writes - if you wanna find those pesky ETL processes
153153
* You can also use average or avg for a lot of the sorts, like @SortOrder = 'avg reads'
154154
* all - sorts by all the different sort order options, and returns a single result set of hot messes. This is a little tricky because:
155-
* We find the @Top N queries by CPU, then by reads, then writes, duration, executions, memory grant, spills, etc.
155+
* We find the @Top N queries by CPU, then by reads, then writes, duration, executions, memory grant, spills, etc. If you want to set @Top > 10, you also have to set @BringThePain = 1 to make sure you understand that it can be pretty slow.
156156
* As we work through each pattern, we exclude the results from the prior patterns. So for example, we get the top 10 by CPU, and then when we go to get the top 10 by reads, we exclude queries that were already found in the top 10 by CPU. As a result, the top 10 by reads may not really be the top 10 by reads - because some of those might have been in the top 10 by CPU.
157157
* To make things even a little more confusing, in the Pattern column of the output, we only specify the first pattern that matched, not all of the patterns that matched. It would be cool if at some point in the future, we turned this into a comma-delimited list of patterns that a query matched, and then we'd be able to get down to a tighter list of top queries. For now, though, this is kinda unscientific.
158158
* query hash - filters for only queries that have multiple cached plans (even though they may all still be the same plan, just different copies stored.) If you use @SortOrder = 'query hash', you can specify a second sort order with a comma, like 'query hash, reads' in order to find only queries with multiple plans, sorted by the ones doing the most reads. The default second sort is CPU.

sp_BlitzCache.sql

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ ALTER PROCEDURE dbo.sp_BlitzCache
258258
@SlowlySearchPlansFor NVARCHAR(4000) = NULL,
259259
@Reanalyze BIT = 0 ,
260260
@SkipAnalysis BIT = 0 ,
261-
@BringThePain BIT = 0, /* This will forcibly set @Top to 2,147,483,647 */
261+
@BringThePain BIT = 0 ,
262262
@MinimumExecutionCount INT = 0,
263263
@Debug BIT = 0,
264264
@CheckDateOverride DATETIMEOFFSET = NULL,
@@ -431,7 +431,7 @@ BEGIN
431431
UNION ALL
432432
SELECT N'@BringThePain',
433433
N'BIT',
434-
N'This forces sp_BlitzCache to examine the entire plan cache. Be careful running this on servers with a lot of memory or a large execution plan cache.'
434+
N'When using @SortOrder = ''all'' and @Top > 10, we require you to set @BringThePain = 1 so you understand that sp_BlitzCache will take a while to run.'
435435

436436
UNION ALL
437437
SELECT N'@QueryFilter',
@@ -1043,12 +1043,6 @@ BEGIN
10431043
END
10441044

10451045

1046-
IF @BringThePain = 1
1047-
BEGIN
1048-
RAISERROR(N'You have chosen to bring the pain. Setting top to 2147483647.', 0, 1) WITH NOWAIT;
1049-
SET @Top = 2147483647;
1050-
END;
1051-
10521046
/* Change duration from seconds to milliseconds */
10531047
IF @DurationFilter IS NOT NULL
10541048
BEGIN
@@ -6065,6 +6059,7 @@ RAISERROR('Beginning all sort loop', 0, 1) WITH NOWAIT;
60656059

60666060
IF (
60676061
@Top > 10
6062+
AND @SkipAnalysis = 0
60686063
AND @BringThePain = 0
60696064
)
60706065
BEGIN

0 commit comments

Comments
 (0)