Skip to content

Commit 9268e37

Browse files
authored
#2000 sp_BlitzCache add SearchSlowly parameter (#2001)
Working on #2000.
1 parent 37e8b1c commit 9268e37

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

sp_BlitzCache.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ ALTER PROCEDURE dbo.sp_BlitzCache
254254
@QueryFilter VARCHAR(10) = 'ALL' ,
255255
@DatabaseName NVARCHAR(128) = NULL ,
256256
@StoredProcName NVARCHAR(128) = NULL,
257+
@SlowlySearchPlansFor NVARCHAR(4000) = NULL,
257258
@Reanalyze BIT = 0 ,
258259
@SkipAnalysis BIT = 0 ,
259260
@BringThePain BIT = 0, /* This will forcibly set @Top to 2,147,483,647 */
@@ -422,6 +423,11 @@ BEGIN
422423
N'NVARCHAR(128)',
423424
N'Name of stored procedure you want to find plans for.'
424425

426+
UNION ALL
427+
SELECT N'@SlowlySearchPlansFor',
428+
N'NVARCHAR(4000)',
429+
N'String to search for in plan text. % wildcards allowed.'
430+
425431
UNION ALL
426432
SELECT N'@BringThePain',
427433
N'BIT',
@@ -1838,6 +1844,13 @@ IF @MinutesBack IS NOT NULL
18381844
SET @body += N' AND x.last_execution_time >= DATEADD(MINUTE, @min_back, GETDATE()) ' + @nl ;
18391845
END;
18401846

1847+
IF @SlowlySearchPlansFor IS NOT NULL
1848+
BEGIN
1849+
RAISERROR(N'Setting string search for @SlowlySearchPlansFor, so remember, this is gonna be slow', 0, 1) WITH NOWAIT;
1850+
SET @SlowlySearchPlansFor = REPLACE((REPLACE((REPLACE((REPLACE((@SlowlySearchPlansFor), N'[', N'_')), N']', N'_')), N'^', N'_')), N'''', N'''''');
1851+
SET @body_where += N' AND CAST(qp.query_plan AS NVARCHAR(MAX)) LIKE ''%' + @SlowlySearchPlansFor + '%'' ' + @nl;
1852+
END
1853+
18411854

18421855
/* Apply the sort order here to only grab relevant plans.
18431856
This should make it faster to process since we'll be pulling back fewer
@@ -1889,6 +1902,7 @@ SET @body += N') AS qs
18891902

18901903
SET @body_where += N' AND pa.attribute = ' + QUOTENAME('dbid', @q ) + @nl ;
18911904

1905+
18921906
IF @NoobSaibot = 1
18931907
BEGIN
18941908
SET @body_where += N' AND qp.query_plan.exist(''declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";//p:StmtSimple//p:MissingIndex'') = 1' + @nl ;
@@ -2191,7 +2205,6 @@ BEGIN
21912205
SET @sql += @body_order + @nl + @nl + @nl ;
21922206
END;
21932207

2194-
21952208
/*******************************************************************************
21962209
*
21972210
* Because the trigger execution count in SQL Server 2008R2 and earlier is not

0 commit comments

Comments
 (0)