Skip to content

Commit 9d786d4

Browse files
committed
BrentOzarULTD#3342 sp_BlitzCache concurrency
On testing BrentOzarULTD#3342, it was failing with the Reanalyze param turned on, so moved those to different parts of the code to make sure the temp table exists.
1 parent 63664ff commit 9d786d4

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

‎sp_BlitzCache.sql‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -967,31 +967,19 @@ IF EXISTS(SELECT * FROM sys.all_columns WHERE object_id = OBJECT_ID('sys.dm_exec
967967
ELSE
968968
SET @VersionShowsAirQuoteActualPlans = 0;
969969

970-
IF @Reanalyze = 1 AND OBJECT_ID('tempdb..##BlitzCacheResults') IS NULL
971-
BEGIN
972-
RAISERROR(N'##BlitzCacheResults does not exist, can''t reanalyze', 0, 1) WITH NOWAIT;
973-
SET @Reanalyze = 0;
974-
END;
975-
976-
IF @Reanalyze = 0
977-
BEGIN
978-
RAISERROR(N'Cleaning up old warnings for your SPID', 0, 1) WITH NOWAIT;
979-
DELETE ##BlitzCacheResults
980-
WHERE SPID = @@SPID
981-
OPTION (RECOMPILE) ;
982-
RAISERROR(N'Cleaning up old plans for your SPID', 0, 1) WITH NOWAIT;
983-
DELETE ##BlitzCacheProcs
984-
WHERE SPID = @@SPID
985-
OPTION (RECOMPILE) ;
986-
END;
987-
988970
IF @Reanalyze = 1
971+
BEGIN
972+
IF OBJECT_ID('tempdb..##BlitzCacheResults') IS NULL
973+
BEGIN
974+
RAISERROR(N'##BlitzCacheResults does not exist, can''t reanalyze', 0, 1) WITH NOWAIT;
975+
SET @Reanalyze = 0;
976+
END
977+
ELSE
989978
BEGIN
990979
RAISERROR(N'Reanalyzing current data, skipping to results', 0, 1) WITH NOWAIT;
991980
GOTO Results;
992981
END;
993-
994-
982+
END;
995983

996984

997985
IF @SortOrder IN ('all', 'all avg')
@@ -2431,6 +2419,14 @@ BEGIN
24312419
Details VARCHAR(4000)
24322420
);
24332421
END;
2422+
ELSE
2423+
BEGIN
2424+
RAISERROR(N'Cleaning up old warnings for your SPID', 0, 1) WITH NOWAIT;
2425+
DELETE ##BlitzCacheResults
2426+
WHERE SPID = @@SPID
2427+
OPTION (RECOMPILE) ;
2428+
END
2429+
24342430

24352431
IF OBJECT_ID('tempdb.dbo.##BlitzCacheProcs') IS NULL
24362432
BEGIN
@@ -2622,7 +2618,13 @@ BEGIN
26222618
Pattern NVARCHAR(20)
26232619
);
26242620
END;
2625-
2621+
ELSE
2622+
BEGIN
2623+
RAISERROR(N'Cleaning up old plans for your SPID', 0, 1) WITH NOWAIT;
2624+
DELETE ##BlitzCacheProcs
2625+
WHERE SPID = @@SPID
2626+
OPTION (RECOMPILE) ;
2627+
END
26262628

26272629
IF @Reanalyze = 0
26282630
BEGIN

0 commit comments

Comments
 (0)