Skip to content

Commit 141a501

Browse files
authored
Merge pull request BrentOzarULTD#2414 from BrentOzarULTD/2413_sp_BlitzFirst_readability_stats_update
2413 sp_BlitzFirst stats readability
2 parents 588015a + fda240a commit 141a501

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

sp_BlitzFirst.sql

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,19 +2111,19 @@ 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);
2114+
CREATE TABLE #UpdatedStats (HowToStopIt NVARCHAR(4000), RowsForSorting BIGINT);
21152115
IF EXISTS(SELECT * FROM sys.all_objects WHERE name = 'dm_db_stats_properties')
21162116
BEGIN
21172117
EXEC sp_MSforeachdb N'USE [?];
2118-
INSERT INTO #UpdatedStats(Details, RowsForSorting)
2119-
SELECT Details =
2118+
INSERT INTO #UpdatedStats(HowToStopIt, RowsForSorting)
2119+
SELECT HowToStopIt =
21202120
QUOTENAME(DB_NAME()) + N''.'' +
21212121
QUOTENAME(SCHEMA_NAME(obj.schema_id)) + N''.'' +
21222122
QUOTENAME(obj.name) +
21232123
N'' statistic '' + QUOTENAME(stat.name) +
21242124
N'' was updated on '' + CONVERT(NVARCHAR(50), sp.last_updated, 121) + N'','' +
21252125
N'' had '' + CAST(sp.rows AS NVARCHAR(50)) + N'' rows, with '' +
2126-
CAST(sp.rows_sampled AS NVARCHAR(50)) + N'' rows sampled, '' +
2126+
CAST(sp.rows_sampled AS NVARCHAR(50)) + N'' rows sampled,'' +
21272127
N'' producing '' + CAST(sp.steps AS NVARCHAR(50)) + N'' steps in the histogram.'',
21282128
sp.rows
21292129
FROM sys.objects AS obj
@@ -2135,16 +2135,21 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
21352135
END;
21362136

21372137
IF EXISTS (SELECT * FROM #UpdatedStats)
2138-
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
2138+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details, HowToStopIt)
21392139
SELECT 44 AS CheckId,
21402140
50 AS Priority,
21412141
'Query Problems' AS FindingGroup,
21422142
'Statistics Updated Recently' AS Finding,
21432143
'http://www.BrentOzar.com/go/stats' AS URL,
2144-
Details = LEFT((SELECT (SELECT Details + NCHAR(10))
2144+
'In the last 15 minutes, statistics were updated. To see which ones, click the HowToStopIt column.' + @LineFeed + @LineFeed
2145+
+ 'This effectively clears the plan cache for queries that involve these tables,' + @LineFeed
2146+
+ 'which thereby causes parameter sniffing: those queries are now getting brand new' + @LineFeed
2147+
+ 'query plans based on whatever parameters happen to call them next.' + @LineFeed + @LineFeed
2148+
+ 'Be on the lookout for sudden parameter sniffing issues after this time range.',
2149+
HowToStopIt = (SELECT (SELECT HowToStopIt + NCHAR(10))
21452150
FROM #UpdatedStats
21462151
ORDER BY RowsForSorting DESC
2147-
FOR XML PATH('')),4000);
2152+
FOR XML PATH(''));
21482153

21492154
RAISERROR('Finished running investigatory queries',10,1) WITH NOWAIT;
21502155

0 commit comments

Comments
 (0)