Skip to content

Commit f18e7ed

Browse files
authored
Merge pull request #2675 from erikdarlingdata/issue_2653
Fix multiple plan query
2 parents cd91121 + abe97e8 commit f18e7ed

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

sp_BlitzCache.sql

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,12 +2810,15 @@ SET NumberOfDistinctPlans = distinct_plan_count,
28102810
FROM (
28112811
SELECT COUNT(DISTINCT QueryHash) AS distinct_plan_count,
28122812
COUNT(QueryHash) AS number_of_plans,
2813-
QueryHash
2813+
QueryHash,
2814+
DatabaseName
28142815
FROM ##BlitzCacheProcs
28152816
WHERE SPID = @@SPID
2816-
GROUP BY QueryHash
2817+
GROUP BY QueryHash,
2818+
DatabaseName
28172819
) AS x
28182820
WHERE ##BlitzCacheProcs.QueryHash = x.QueryHash
2821+
AND ##BlitzCacheProcs.DatabaseName = x.DatabaseName
28192822
OPTION (RECOMPILE) ;
28202823

28212824
-- query level checks
@@ -3664,22 +3667,7 @@ END;
36643667

36653668

36663669
/* END Testing using XML nodes to speed up processing */
3667-
RAISERROR(N'Gathering additional plan level information', 0, 1) WITH NOWAIT;
3668-
WITH XMLNAMESPACES('http://schemas.microsoft.com/sqlserver/2004/07/showplan' AS p)
3669-
UPDATE ##BlitzCacheProcs
3670-
SET NumberOfDistinctPlans = distinct_plan_count,
3671-
NumberOfPlans = number_of_plans,
3672-
plan_multiple_plans = CASE WHEN distinct_plan_count < number_of_plans THEN number_of_plans END
3673-
FROM (
3674-
SELECT COUNT(DISTINCT QueryHash) AS distinct_plan_count,
3675-
COUNT(QueryHash) AS number_of_plans,
3676-
QueryHash
3677-
FROM ##BlitzCacheProcs
3678-
WHERE SPID = @@SPID
3679-
GROUP BY QueryHash
3680-
) AS x
3681-
WHERE ##BlitzCacheProcs.QueryHash = x.QueryHash
3682-
OPTION (RECOMPILE);
3670+
36833671

36843672
/* Update to grab stored procedure name for individual statements */
36853673
RAISERROR(N'Attempting to get stored procedure name for individual statements', 0, 1) WITH NOWAIT;

0 commit comments

Comments
 (0)