@@ -195,6 +195,7 @@ CREATE TABLE ##bou_BlitzCacheProcs (
195
195
index_ops AS (index_insert_count + index_update_count + index_delete_count +
196
196
cx_insert_count + cx_update_count + cx_delete_count +
197
197
table_insert_count + table_update_count + table_delete_count),
198
+ is_large_scan BIT ,
198
199
SetOptions VARCHAR (MAX ),
199
200
Warnings VARCHAR (MAX )
200
201
);
@@ -830,6 +831,7 @@ BEGIN
830
831
index_ops AS (index_insert_count + index_update_count + index_delete_count +
831
832
cx_insert_count + cx_update_count + cx_delete_count +
832
833
table_insert_count + table_update_count + table_delete_count),
834
+ is_large_scan BIT ,
833
835
SetOptions VARCHAR (MAX ),
834
836
Warnings VARCHAR (MAX )
835
837
);
@@ -2229,6 +2231,37 @@ BEGIN
2229
2231
OPTION (RECOMPILE ) ;
2230
2232
END ;
2231
2233
2234
+ IF (@v = 13 AND @build >= 4001 )
2235
+ BEGIN
2236
+ RAISERROR (N ' Using 2016 SP1 estimated rows read to detect inefficient scans' , 0 , 1 ) WITH NOWAIT ;
2237
+
2238
+ WITH XMLNAMESPACES(' http://schemas.microsoft.com/sqlserver/2004/07/showplan' AS p),
2239
+ er AS (
2240
+ SELECT
2241
+ r .SqlHandle ,
2242
+ c .n .value (' @EstimateRows' , ' FLOAT' ) AS estimated_rows,
2243
+ c .n .value (' @EstimatedRowsRead' , ' FLOAT' ) AS estimated_rows_read
2244
+ FROM #relop AS r
2245
+ CROSS APPLY r .relop .nodes (' //p:RelOp' ) c(n)
2246
+ WHERE c .n .exist(' @EstimatedRowsRead' ) = 1
2247
+ ), er2 AS (
2248
+ SELECT * ,
2249
+ CASE WHEN er .estimated_rows_read >= 100000
2250
+ AND er .estimated_rows * 10 < er .estimated_rows_read
2251
+ THEN 1
2252
+ ELSE 0
2253
+ END AS is_large_scan
2254
+ FROM er
2255
+ )
2256
+ UPDATE b
2257
+ SET b .is_large_scan = er2 .is_large_scan
2258
+ FROM ##bou_BlitzCacheProcs b
2259
+ JOIN er2
2260
+ ON b .SqlHandle = er2 .SqlHandle
2261
+ WHERE er2 .is_large_scan = 1
2262
+ OPTION (RECOMPILE );
2263
+ END
2264
+
2232
2265
/* END Testing using XML nodes to speed up processing */
2233
2266
RAISERROR (N ' Gathering additional plan level information' , 0 , 1 ) WITH NOWAIT ;
2234
2267
WITH XMLNAMESPACES(' http://schemas.microsoft.com/sqlserver/2004/07/showplan' AS p)
@@ -2516,7 +2549,8 @@ SET Warnings = CASE WHEN QueryPlan IS NULL THEN 'We couldn''t find a plan for
2516
2549
CASE WHEN is_computed_scalar = 1 THEN ' , Computed Column UDF ' ELSE ' ' END +
2517
2550
CASE WHEN is_sort_expensive = 1 THEN ' , Expensive Sort' ELSE ' ' END +
2518
2551
CASE WHEN is_computed_filter = 1 THEN ' , Filter UDF' ELSE ' ' END +
2519
- CASE WHEN index_ops >= 5 THEN ' , ' + CONVERT (VARCHAR (10 ), index_ops) + ' Indexes Modified' ELSE ' ' END
2552
+ CASE WHEN index_ops >= 5 THEN ' , ' + CONVERT (VARCHAR (10 ), index_ops) + ' Indexes Modified' ELSE ' ' END +
2553
+ CASE WHEN is_large_scan = 1 THEN ' , Inefficient Scan' ELSE ' ' END
2520
2554
, 2 , 200000 )
2521
2555
END
2522
2556
WHERE SPID = @@SPID
@@ -2844,7 +2878,8 @@ BEGIN
2844
2878
CASE WHEN is_computed_scalar = 1 THEN '' , 42 '' ELSE '' END +
2845
2879
CASE WHEN is_sort_expensive = 1 THEN '' , 43'' ELSE '' '' END +
2846
2880
CASE WHEN is_computed_filter = 1 THEN '' , 44'' ELSE '' '' END +
2847
- CASE WHEN index_ops >= 5 THEN '' , 45'' ELSE '' '' END
2881
+ CASE WHEN index_ops >= 5 THEN '' , 45'' ELSE '' '' END +
2882
+ CASE WHEN is_large_scan = 1 THEN '' , 46'' ELSE '' '' END +
2848
2883
, 2, 200000) END AS opserver_warning , ' + @nl ;
2849
2884
END
2850
2885
@@ -3489,7 +3524,20 @@ BEGIN
3489
3524
' Write Queries Are Hitting >= 5 Indexes' ,
3490
3525
' No URL yet' ,
3491
3526
' This can cause lots of hidden I/O -- Run sp_BLitzIndex for more information.' ) ;
3492
-
3527
+
3528
+ IF EXISTS (SELECT 1 / 0
3529
+ FROM ##bou_BlitzCacheProcs p
3530
+ WHERE p .is_large_scan = 1
3531
+ AND SPID = @@SPID )
3532
+ INSERT INTO ##bou_BlitzCacheResults (SPID, CheckID, Priority, FindingsGroup, Finding, URL , Details)
3533
+ VALUES (@@SPID ,
3534
+ 46 ,
3535
+ 100 ,
3536
+ ' Inefficient Scan' ,
3537
+ ' More than 10x rows read than returned' ,
3538
+ ' No URL yet' ,
3539
+ ' This looks for scans of >100k rows where the output is < 10x the scan.' ) ;
3540
+
3493
3541
IF EXISTS (SELECT 1 / 0
3494
3542
FROM #plan_creation p
3495
3543
WHERE (p .percent_24 > 0 OR p .percent_4 > 0 )
0 commit comments