@@ -216,6 +216,7 @@ CREATE TABLE ##bou_BlitzCacheProcs (
216216 is_bad_estimate BIT ,
217217 is_paul_white_electric BIT ,
218218 is_row_goal BIT ,
219+ is_big_spills BIT ,
219220 implicit_conversion_info XML ,
220221 cached_execution_parameters XML ,
221222 missing_indexes XML ,
@@ -595,6 +596,25 @@ BEGIN
595596 N ' BIGINT' ,
596597 N ' The maximum used memory grant the query received in kb.'
597598
599+ SELECT N ' MinSpills' ,
600+ N ' BIGINT' ,
601+ N ' The minimum amount this query has spilled to tempdb in 8k pages.'
602+
603+ UNION ALL
604+ SELECT N ' MaxSpills' ,
605+ N ' BIGINT' ,
606+ N ' The maximum amount this query has spilled to tempdb in 8k pages.'
607+
608+ UNION ALL
609+ SELECT N ' TotalSpills' ,
610+ N ' BIGINT' ,
611+ N ' The total amount this query has spilled to tempdb in 8k pages.'
612+
613+ UNION ALL
614+ SELECT N ' AvgSpills' ,
615+ N ' BIGINT' ,
616+ N ' The average amount this query has spilled to tempdb in 8k pages.'
617+
598618 UNION ALL
599619 SELECT N ' PercentMemoryGrantUsed' ,
600620 N ' MONEY' ,
@@ -936,6 +956,7 @@ BEGIN
936956 is_bad_estimate BIT ,
937957 is_paul_white_electric BIT ,
938958 is_row_goal BIT ,
959+ is_big_spills BIT ,
939960 implicit_conversion_info XML ,
940961 cached_execution_parameters XML ,
941962 missing_indexes XML ,
@@ -3747,7 +3768,8 @@ SET frequent_execution = CASE WHEN ExecutionsPerMinute > @execution_threshold
37473768 low_cost_high_cpu = CASE WHEN QueryPlanCost < @ctp AND AverageCPU > 500 . AND QueryPlanCost * 10 < AverageCPU THEN 1 END ,
37483769 is_spool_expensive = CASE WHEN QueryPlanCost > (@ctp / 2 ) AND index_spool_cost >= QueryPlanCost * .1 THEN 1 END ,
37493770 is_spool_more_rows = CASE WHEN index_spool_rows >= (AverageReturnedRows / ISNULL (NULLIF (ExecutionCount, 0 ), 1 )) THEN 1 END ,
3750- is_bad_estimate = CASE WHEN AverageReturnedRows > 0 AND (estimated_rows * 1000 < AverageReturnedRows OR estimated_rows > AverageReturnedRows * 1000 ) THEN 1 END
3771+ is_bad_estimate = CASE WHEN AverageReturnedRows > 0 AND (estimated_rows * 1000 < AverageReturnedRows OR estimated_rows > AverageReturnedRows * 1000 ) THEN 1 END ,
3772+ is_big_spills = CASE WHEN (AvgSpills / 128 .) > 499 . THEN 1 END
37513773WHERE SPID = @@SPID
37523774OPTION (RECOMPILE );
37533775
@@ -3856,8 +3878,9 @@ SET Warnings = SUBSTRING(
38563878 CASE WHEN is_spool_more_rows = 1 THEN + ' , Large Index Row Spool' ELSE ' ' END +
38573879 CASE WHEN is_bad_estimate = 1 THEN + ' , Row estimate mismatch' ELSE ' ' END +
38583880 CASE WHEN is_paul_white_electric = 1 THEN ' , SWITCH!' ELSE ' ' END +
3859- CASE WHEN is_row_goal = 1 THEN ' , Row Goals' ELSE ' ' END
3860- , 2 , 200000 )
3881+ CASE WHEN is_row_goal = 1 THEN ' , Row Goals' ELSE ' ' END +
3882+ CASE WHEN is_big_spills = 1 THEN ' , >500mb spills' ELSE ' ' END
3883+ , 2 , 200000 )
38613884WHERE SPID = @@SPID
38623885OPTION (RECOMPILE );
38633886
@@ -3926,7 +3949,8 @@ SELECT DISTINCT
39263949 CASE WHEN is_spool_more_rows = 1 THEN + ' , Large Index Row Spool' ELSE ' ' END +
39273950 CASE WHEN is_bad_estimate = 1 THEN + ' , Row estimate mismatch' ELSE ' ' END +
39283951 CASE WHEN is_paul_white_electric = 1 THEN ' , SWITCH!' ELSE ' ' END +
3929- CASE WHEN is_row_goal = 1 THEN ' , Row Goals' ELSE ' ' END
3952+ CASE WHEN is_row_goal = 1 THEN ' , Row Goals' ELSE ' ' END +
3953+ CASE WHEN is_big_spills = 1 THEN ' , >500mb spills' ELSE ' ' END
39303954 , 2 , 200000 )
39313955FROM ##bou_BlitzCacheProcs b
39323956WHERE SPID = @@SPID
@@ -4393,7 +4417,8 @@ BEGIN
43934417 CASE WHEN is_spool_more_rows = 1 THEN + '' , 55'' ELSE '' '' END +
43944418 CASE WHEN is_bad_estimate = 1 THEN + '' , 56'' ELSE '' '' END +
43954419 CASE WHEN is_paul_white_electric = 1 THEN '' , 57'' ELSE '' '' END +
4396- CASE WHEN is_row_goal = 1 THEN '' , 58'' ELSE '' '' END
4420+ CASE WHEN is_row_goal = 1 THEN '' , 58'' ELSE '' '' END +
4421+ CASE WHEN is_big_spills = 1 THEN '' , 59'' ELSE '' '' END
43974422 , 2, 200000) AS opserver_warning , ' + @nl ;
43984423 END ;
43994424
@@ -5266,6 +5291,19 @@ BEGIN
52665291 ' https://www.brentozar.com/archive/2018/01/sql-server-2017-cu3-adds-optimizer-row-goal-information-query-plans/' ,
52675292 ' This can be good or bad, and should be investigated for high read queries' ) ;
52685293
5294+ IF EXISTS (SELECT 1 / 0
5295+ FROM ##bou_BlitzCacheProcs p
5296+ WHERE p .is_big_spills = 1
5297+ )
5298+ INSERT INTO ##bou_BlitzCacheResults (SPID, CheckID, Priority, FindingsGroup, Finding, URL , Details)
5299+ VALUES (@@SPID ,
5300+ 59 ,
5301+ 100 ,
5302+ ' tempdb Spills' ,
5303+ ' This query spills >500mb to tempdb on average' ,
5304+ ' https://www.brentozar.com/blitzcache/tempdb-spills/' ,
5305+ ' One way or another, this query didn'' t get enough memory' ) ;
5306+
52695307
52705308 END ;
52715309
0 commit comments