@@ -199,6 +199,8 @@ CREATE TABLE ##bou_BlitzCacheProcs (
199
199
is_spatial BIT ,
200
200
index_dml BIT ,
201
201
table_dml BIT ,
202
+ long_running_low_cpu BIT ,
203
+ low_cost_high_cpu BIT ,
202
204
SetOptions VARCHAR (MAX ),
203
205
Warnings VARCHAR (MAX )
204
206
);
@@ -864,6 +866,8 @@ BEGIN
864
866
is_spatial BIT ,
865
867
index_dml BIT ,
866
868
table_dml BIT ,
869
+ long_running_low_cpu BIT ,
870
+ low_cost_high_cpu BIT ,
867
871
SetOptions VARCHAR (MAX ),
868
872
Warnings VARCHAR (MAX )
869
873
);
@@ -2751,7 +2755,9 @@ SET frequent_execution = CASE WHEN ExecutionsPerMinute > @execution_threshold
2751
2755
is_sort_expensive = CASE WHEN QueryPlanCost > (@ctp / 2 ) AND sort_cost >= QueryPlanCost * .5 THEN 1 END ,
2752
2756
is_remote_query_expensive = CASE WHEN remote_query_cost >= QueryPlanCost * .05 THEN 1 END ,
2753
2757
is_forced_serial = CASE WHEN is_forced_serial = 1 THEN 1 END ,
2754
- is_unused_grant = CASE WHEN PercentMemoryGrantUsed <= @memory_grant_warning_percent AND MinGrantKB > @MinMemoryPerQuery THEN 1 END
2758
+ is_unused_grant = CASE WHEN PercentMemoryGrantUsed <= @memory_grant_warning_percent AND MinGrantKB > @MinMemoryPerQuery THEN 1 END ,
2759
+ long_running_low_cpu = CASE WHEN AverageDuration > AverageCPU * 4 THEN 1 END ,
2760
+ low_cost_high_cpu = CASE WHEN QueryPlanCost < @ctp AND AverageCPU > 500 . AND QueryPlanCost * 10 < AverageCPU THEN 1 END
2755
2761
WHERE SPID = @@SPID
2756
2762
OPTION (RECOMPILE ) ;
2757
2763
@@ -2845,7 +2851,9 @@ SET Warnings = CASE WHEN QueryPlan IS NULL THEN 'We couldn''t find a plan for
2845
2851
CASE WHEN is_row_level = 1 THEN ' , Row Level Security' ELSE ' ' END +
2846
2852
CASE WHEN is_spatial = 1 THEN ' , Spatial Index' ELSE ' ' END +
2847
2853
CASE WHEN index_dml = 1 THEN ' , Index DML' ELSE ' ' END +
2848
- CASE WHEN table_dml = 1 THEN ' , Table DML' ELSE ' ' END
2854
+ CASE WHEN table_dml = 1 THEN ' , Table DML' ELSE ' ' END +
2855
+ CASE WHEN low_cost_high_cpu = 1 THEN ' , Low Cost High CPU' ELSE ' ' END +
2856
+ CASE WHEN long_running_low_cpu = 1 THEN + ' Long Running With Low CPU' ELSE ' ' END
2849
2857
, 2 , 200000 )
2850
2858
END
2851
2859
WHERE SPID = @@SPID
@@ -2907,7 +2915,9 @@ SELECT DISTINCT
2907
2915
CASE WHEN is_row_level = 1 THEN ' , Row Level Security' ELSE ' ' END +
2908
2916
CASE WHEN is_spatial = 1 THEN ' , Spatial Index' ELSE ' ' END +
2909
2917
CASE WHEN index_dml = 1 THEN ' , Index DML' ELSE ' ' END +
2910
- CASE WHEN table_dml = 1 THEN ' , Table DML' ELSE ' ' END
2918
+ CASE WHEN table_dml = 1 THEN ' , Table DML' ELSE ' ' END +
2919
+ CASE WHEN low_cost_high_cpu = 1 THEN ' , Low Cost High CPU' ELSE ' ' END +
2920
+ CASE WHEN long_running_low_cpu = 1 THEN + ' Long Running With Low CPU' ELSE ' ' END
2911
2921
, 2 , 200000 )
2912
2922
END
2913
2923
FROM ##bou_BlitzCacheProcs b
@@ -3255,7 +3265,9 @@ BEGIN
3255
3265
CASE WHEN is_row_level = 1 THEN '' , 46'' ELSE '' '' END +
3256
3266
CASE WHEN is_spatial = 1 THEN '' , 47'' ELSE '' '' END +
3257
3267
CASE WHEN index_dml = 1 THEN '' , 48'' ELSE '' '' END +
3258
- CASE WHEN table_dml = 1 THEN '' , 49'' ELSE '' '' END
3268
+ CASE WHEN table_dml = 1 THEN '' , 49'' ELSE '' '' END +
3269
+ CASE WHEN long_running_low_cpu = 1 THEN '' , 50'' ELSE '' '' END +
3270
+ CASE WHEN low_cost_high_cpu = 1 THEN '' , 51, '' ELSE '' '' END
3259
3271
, 2, 200000) END AS opserver_warning , ' + @nl ;
3260
3272
END
3261
3273
@@ -3955,6 +3967,32 @@ BEGIN
3955
3967
' No URL yet' ,
3956
3968
' This can cause recompiles and stuff.' ) ;
3957
3969
3970
+ IF EXISTS (SELECT 1 / 0
3971
+ FROM ##bou_BlitzCacheProcs p
3972
+ WHERE p .long_running_low_cpu = 1
3973
+ AND SPID = @@SPID )
3974
+ INSERT INTO ##bou_BlitzCacheResults (SPID, CheckID, Priority, FindingsGroup, Finding, URL , Details)
3975
+ VALUES (@@SPID ,
3976
+ 50 ,
3977
+ 150 ,
3978
+ ' Long Running Low CPU' ,
3979
+ ' You have a query that runs for much longer than it uses CPU' ,
3980
+ ' No URL yet' ,
3981
+ ' This can be a sign of blocking, linked servers, or poor client application code (ASYNC_NETWORK_IO).' ) ;
3982
+
3983
+ IF EXISTS (SELECT 1 / 0
3984
+ FROM ##bou_BlitzCacheProcs p
3985
+ WHERE p .low_cost_high_cpu = 1
3986
+ AND SPID = @@SPID )
3987
+ INSERT INTO ##bou_BlitzCacheResults (SPID, CheckID, Priority, FindingsGroup, Finding, URL , Details)
3988
+ VALUES (@@SPID ,
3989
+ 51 ,
3990
+ 150 ,
3991
+ ' Low Cost Query With High CPU' ,
3992
+ ' You have a low cost query that uses a lot of CPU' ,
3993
+ ' No URL yet' ,
3994
+ ' This can be a sign of functions or Dynamic SQL that calls black-box code.' ) ;
3995
+
3958
3996
IF EXISTS (SELECT 1 / 0
3959
3997
FROM #plan_creation p
3960
3998
WHERE (p .percent_24 > 0 OR p .percent_4 > 0 )
0 commit comments