Skip to content

Commit 044456a

Browse files
authored
Merge pull request #1097 from BrentOzarULTD/sp_BlitzCache_QS_Switch_Operator
Closes #976
2 parents eb0dadc + e9c7f96 commit 044456a

File tree

2 files changed

+72
-7
lines changed

2 files changed

+72
-7
lines changed

sp_BlitzCache.sql

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ CREATE TABLE ##bou_BlitzCacheProcs (
209209
is_spool_more_rows BIT,
210210
estimated_rows FLOAT,
211211
is_bad_estimate BIT,
212+
is_paul_white_electric BIT,
212213
SetOptions VARCHAR(MAX),
213214
Warnings VARCHAR(MAX)
214215
);
@@ -889,6 +890,7 @@ BEGIN
889890
is_spool_more_rows BIT,
890891
estimated_rows FLOAT,
891892
is_bad_estimate BIT,
893+
is_paul_white_electric BIT,
892894
SetOptions VARCHAR(MAX),
893895
Warnings VARCHAR(MAX)
894896
);
@@ -2806,6 +2808,24 @@ WHERE SPID = @@SPID
28062808
OPTION(RECOMPILE);
28072809
END
28082810

2811+
2812+
RAISERROR(N'Is Paul White Electric?', 0, 1) WITH NOWAIT;
2813+
WITH XMLNAMESPACES('http://schemas.microsoft.com/sqlserver/2004/07/showplan' AS p),
2814+
is_paul_white_electric AS (
2815+
SELECT 1 AS [is_paul_white_electric],
2816+
r.SqlHandle
2817+
FROM #relop AS r
2818+
CROSS APPLY r.relop.nodes('//p:RelOp') c(n)
2819+
WHERE c.n.exist('@PhysicalOp[.="Switch"]') = 1
2820+
)
2821+
UPDATE b
2822+
SET b.is_paul_white_electric = ipwe.is_paul_white_electric
2823+
FROM ##bou_BlitzCacheProcs AS b
2824+
JOIN is_paul_white_electric ipwe
2825+
ON ipwe.SqlHandle = b.SqlHandle
2826+
WHERE b.SPID = @@SPID
2827+
OPTION (RECOMPILE);
2828+
28092829
IF @SkipAnalysis = 1
28102830
BEGIN
28112831
RAISERROR(N'Skipping analysis, going to results', 0, 1) WITH NOWAIT;
@@ -3022,7 +3042,8 @@ SET Warnings = SUBSTRING(
30223042
CASE WHEN is_adaptive = 1 THEN + ', Adaptive Joins' ELSE '' END +
30233043
CASE WHEN is_spool_expensive = 1 THEN + ', Expensive Index Spool' ELSE '' END +
30243044
CASE WHEN is_spool_more_rows = 1 THEN + ', Large Index Row Spool' ELSE '' END +
3025-
CASE WHEN is_bad_estimate = 1 THEN + ', Row estimate mismatch' ELSE '' END
3045+
CASE WHEN is_bad_estimate = 1 THEN + ', Row estimate mismatch' ELSE '' END +
3046+
CASE WHEN is_paul_white_electric = 1 THEN ', SWITCH!' ELSE '' END
30263047
, 2, 200000)
30273048
WHERE SPID = @@SPID
30283049
OPTION (RECOMPILE) ;
@@ -3089,7 +3110,8 @@ SELECT DISTINCT
30893110
CASE WHEN is_adaptive = 1 THEN + ', Adaptive Joins' ELSE '' END +
30903111
CASE WHEN is_spool_expensive = 1 THEN + ', Expensive Index Spool' ELSE '' END +
30913112
CASE WHEN is_spool_more_rows = 1 THEN + ', Large Index Row Spool' ELSE '' END +
3092-
CASE WHEN is_bad_estimate = 1 THEN + ', Row estimate mismatch' ELSE '' END
3113+
CASE WHEN is_bad_estimate = 1 THEN + ', Row estimate mismatch' ELSE '' END +
3114+
CASE WHEN is_paul_white_electric = 1 THEN ', SWITCH!' ELSE '' END
30933115
, 2, 200000)
30943116
FROM ##bou_BlitzCacheProcs b
30953117
WHERE SPID = @@SPID
@@ -3467,7 +3489,8 @@ BEGIN
34673489
CASE WHEN is_adaptive = 1 THEN '', 53'' ELSE '''' END +
34683490
CASE WHEN is_spool_expensive = 1 THEN + '', 54'' ELSE '''' END +
34693491
CASE WHEN is_spool_more_rows = 1 THEN + '', 55'' ELSE '''' END +
3470-
CASE WHEN is_bad_estimate = 1 THEN + '', 56'' ELSE '''' END
3492+
CASE WHEN is_bad_estimate = 1 THEN + '', 56'' ELSE '''' END +
3493+
CASE WHEN b.is_paul_white_electric = 1 THEN '', 57'' ELSE '''' END
34713494
, 2, 200000) AS opserver_warning , ' + @nl ;
34723495
END
34733496

@@ -4255,7 +4278,20 @@ BEGIN
42554278
'Potentially bad cardinality estimates',
42564279
'Estimated rows are different from average rows by a factor of 10000',
42574280
'No URL yet',
4258-
'This may indicate a performance problem if mismatches occur regularly') ;
4281+
'This may indicate a performance problem if mismatches occur regularly') ;
4282+
4283+
IF EXISTS (SELECT 1/0
4284+
FROM ##bou_BlitzCacheProcs p
4285+
WHERE p.is_paul_white_electric = 1
4286+
)
4287+
INSERT INTO ##bou_BlitzCacheResults (SPID, CheckID, Priority, FindingsGroup, Finding, URL, Details)
4288+
VALUES (@@SPID,
4289+
998,
4290+
200,
4291+
'Is Paul White Electric?',
4292+
'This query has a Switch operator in it!',
4293+
'http://sqlblog.com/blogs/paul_white/archive/2013/06/11/hello-operator-my-switch-is-bored.aspx',
4294+
'You should email this query plan to Paul: SQLkiwi at gmail dot com') ;
42594295

42604296
IF @v >= 14
42614297
BEGIN

sp_BlitzQueryStore.sql

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ CREATE TABLE #working_warnings
609609
is_bad_estimate BIT,
610610
is_big_log BIT,
611611
is_big_tempdb BIT,
612+
is_paul_white_electric BIT,
612613
warnings NVARCHAR(4000)
613614
INDEX ww_ix_ids CLUSTERED (plan_id, query_id, query_hash, sql_handle)
614615
);
@@ -2632,7 +2633,21 @@ JOIN #trace_flags tf
26322633
ON tf.sql_handle = b.sql_handle
26332634
OPTION (RECOMPILE);
26342635

2635-
2636+
RAISERROR(N'Is Paul White Electric?', 0, 1) WITH NOWAIT;
2637+
WITH XMLNAMESPACES('http://schemas.microsoft.com/sqlserver/2004/07/showplan' AS p),
2638+
is_paul_white_electric AS (
2639+
SELECT 1 AS [is_paul_white_electric],
2640+
r.sql_handle
2641+
FROM #relop AS r
2642+
CROSS APPLY r.relop.nodes('//p:RelOp') c(n)
2643+
WHERE c.n.exist('@PhysicalOp[.="Switch"]') = 1
2644+
)
2645+
UPDATE b
2646+
SET b.is_paul_white_electric = ipwe.is_paul_white_electric
2647+
FROM #working_warnings AS b
2648+
JOIN is_paul_white_electric ipwe
2649+
ON ipwe.sql_handle = b.sql_handle
2650+
OPTION (RECOMPILE);
26362651

26372652
RAISERROR(N'General query dispositions: frequent executions, long running, etc.', 0, 1) WITH NOWAIT;
26382653

@@ -2723,7 +2738,8 @@ SET b.warnings = SUBSTRING(
27232738
CASE WHEN b.is_spool_more_rows = 1 THEN + ', Large Index Row Spool' ELSE '' END +
27242739
CASE WHEN b.is_bad_estimate = 1 THEN + ', Row estimate mismatch' ELSE '' END +
27252740
CASE WHEN b.is_big_log = 1 THEN + ', High log use' ELSE '' END +
2726-
CASE WHEN b.is_big_tempdb = 1 THEN ', High tempdb use' ELSE '' END
2741+
CASE WHEN b.is_big_tempdb = 1 THEN ', High tempdb use' ELSE '' END +
2742+
CASE WHEN b.is_paul_white_electric = 1 THEN ', SWITCH!' ELSE '' END
27272743
, 2, 200000)
27282744
FROM #working_warnings b
27292745
OPTION (RECOMPILE);
@@ -3680,7 +3696,20 @@ BEGIN
36803696
'High tempdb use',
36813697
'This query uses more than half of a data file on average',
36823698
'No URL yet',
3683-
'You should take a look at tempdb waits to see if you''re having problems') ;
3699+
'You should take a look at tempdb waits to see if you''re having problems') ;
3700+
3701+
IF EXISTS (SELECT 1/0
3702+
FROM #working_warnings p
3703+
WHERE p.is_paul_white_electric = 1
3704+
)
3705+
INSERT INTO #warning_results (CheckID, Priority, FindingsGroup, Finding, URL, Details)
3706+
VALUES (
3707+
998,
3708+
200,
3709+
'Is Paul White Electric?',
3710+
'This query has a Switch operator in it!',
3711+
'http://sqlblog.com/blogs/paul_white/archive/2013/06/11/hello-operator-my-switch-is-bored.aspx',
3712+
'You should email this query plan to Paul: SQLkiwi at gmail dot com') ;
36843713

36853714
INSERT INTO #warning_results (CheckID, Priority, FindingsGroup, Finding, URL, Details)
36863715
SELECT

0 commit comments

Comments
 (0)