@@ -2111,31 +2111,37 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
21112111
21122112
21132113 /* Query Problems - Statistics Updated Recently - CheckID 44 */
2114+ CREATE TABLE #UpdatedStats (Details NVARCHAR (4000 ), RowsForSorting BIGINT );
21142115 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 =
21222118 QUOTENAME(DB_NAME()) + N'' .'' +
21232119 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
21312127 FROM sys.objects AS obj
21322128 INNER JOIN sys.stats AS stat ON stat.object_id = obj.object_id
21332129 CROSS APPLY sys.dm_db_stats_properties(stat.object_id, stat.stats_id) AS sp
21342130 WHERE sp.last_updated > DATEADD(MI, -15, GETDATE())
21352131 AND obj.is_ms_shipped = 0
21362132 AND '' [?]'' <> '' [tempdb]'' ;' ;
21372133
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 (' ' ));
21392145
21402146 RAISERROR (' Finished running investigatory queries' ,10 ,1 ) WITH NOWAIT ;
21412147
0 commit comments