Skip to content

Commit 30a0962

Browse files
authored
Merge pull request BrentOzarULTD#2404 from BrentOzarULTD/2386_sp_BlitzFirst_stats_in_one_line
BrentOzarULTD#2386 sp_BlitzFirst stats update warning
2 parents 5a4201a + 517acb0 commit 30a0962

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

sp_BlitzFirst.sql

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)