@@ -2111,31 +2111,37 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
2111
2111
2112
2112
2113
2113
/* Query Problems - Statistics Updated Recently - CheckID 44 */
2114
+ CREATE TABLE #UpdatedStats (Details NVARCHAR (4000 ), RowsForSorting BIGINT );
2114
2115
EXEC sp_MSforeachdb N' USE [?];
2115
- INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
2116
- SELECT 44 AS CheckId,
2117
- 50 AS Priority,
2118
- '' Query Problems'' AS FindingGroup,
2119
- '' Statistics Updated Recently'' AS Finding,
2120
- '' http://www.BrentOzar.com/go/stats'' AS URL,
2121
- Details =
2116
+ INSERT INTO #UpdatedStats(Details, RowsForSorting)
2117
+ SELECT Details =
2122
2118
QUOTENAME(DB_NAME()) + N'' .'' +
2123
2119
QUOTENAME(SCHEMA_NAME(obj.schema_id)) + N'' .'' +
2124
- QUOTENAME(obj.name) + NCHAR(13) + NCHAR(10) +
2125
- N'' statistic '' + QUOTENAME(stat.name) + NCHAR(13) + NCHAR(10) +
2126
- N'' was updated on '' + CONVERT(NVARCHAR(50), sp.last_updated, 121) + N'' ,'' + NCHAR(13) + NCHAR(10) +
2127
- N'' had '' + CAST(sp.rows AS NVARCHAR(50)) + N'' rows, with '' +
2128
- CAST(sp.rows_sampled AS NVARCHAR(50)) + N'' rows sampled,'' + NCHAR(13) + NCHAR(10) +
2129
- N'' producing '' + CAST(sp.steps AS NVARCHAR(50)) + N'' steps in the histogram.'' + NCHAR(13) + NCHAR(10) +
2130
- N '' This invalidated plans in the cache for this object, causing plan compiles and parameter sniffing.' '
2120
+ QUOTENAME(obj.name) +
2121
+ N'' statistic '' + QUOTENAME(stat.name) +
2122
+ N'' was updated on '' + CONVERT(NVARCHAR(50), sp.last_updated, 121) + N'' ,'' +
2123
+ N'' had '' + CAST(sp.rows AS NVARCHAR(50)) + N'' rows, with '' +
2124
+ CAST(sp.rows_sampled AS NVARCHAR(50)) + N'' rows sampled, '' +
2125
+ N'' producing '' + CAST(sp.steps AS NVARCHAR(50)) + N'' steps in the histogram.'' ,
2126
+ sp.rows
2131
2127
FROM sys.objects AS obj
2132
2128
INNER JOIN sys.stats AS stat ON stat.object_id = obj.object_id
2133
2129
CROSS APPLY sys.dm_db_stats_properties(stat.object_id, stat.stats_id) AS sp
2134
2130
WHERE sp.last_updated > DATEADD(MI, -15, GETDATE())
2135
2131
AND obj.is_ms_shipped = 0
2136
2132
AND '' [?]'' <> '' [tempdb]'' ;' ;
2137
2133
2138
-
2134
+ IF EXISTS (SELECT * FROM #UpdatedStats)
2135
+ INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL , Details)
2136
+ SELECT 44 AS CheckId,
2137
+ 50 AS Priority,
2138
+ ' Query Problems' AS FindingGroup,
2139
+ ' Statistics Updated Recently' AS Finding,
2140
+ ' http://www.BrentOzar.com/go/stats' AS URL ,
2141
+ Details = (SELECT (SELECT Details + NCHAR (10 ))
2142
+ FROM #UpdatedStats
2143
+ ORDER BY RowsForSorting DESC
2144
+ FOR XML PATH (' ' ));
2139
2145
2140
2146
RAISERROR (' Finished running investigatory queries' ,10 ,1 ) WITH NOWAIT ;
2141
2147
0 commit comments