Skip to content

Commit 0fa271f

Browse files
authored
Merge pull request #2388 from BrentOzarULTD/2386_sp_BlitzFirst_stats_update_check
#2386 sp_BlitzFirst new check for stats
2 parents 15285ee + 192ece6 commit 0fa271f

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

Documentation/sp_BlitzFirst_Checks_by_Priority.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Before adding a new check, make sure to add a Github issue for it first, and hav
66

77
If you want to change anything about a check - the priority, finding, URL, or ID - open a Github issue first. The relevant scripts have to be updated too.
88

9-
CURRENT HIGH CHECKID: 43
10-
If you want to add a new check, start at 44
9+
CURRENT HIGH CHECKID: 44
10+
If you want to add a new check, start at 45
1111

1212
| Priority | FindingsGroup | Finding | URL | CheckID |
1313
|----------|---------------------------------|---------------------------------------|-------------------------------------------------|----------|
@@ -28,9 +28,10 @@ If you want to add a new check, start at 44
2828
| 40 | Table Problems | Forwarded Fetches/Sec High | https://BrentOzar.com/go/fetch | 29 |
2929
| 50 | In-Memory OLTP | Garbage Collection in Progress | https://BrentOzar.com/go/garbage | 31 |
3030
| 50 | Query Problems | Compilations/Sec High | https://BrentOzar.com/go/compile | 15 |
31+
| 50 | Query Problems | Implicit Transactions | https://www.brentozar.com/go/ImplicitTransactions/ | 37 |
3132
| 50 | Query Problems | Plan Cache Erased Recently | https://BrentOzar.com/go/freeproccache | 7 |
3233
| 50 | Query Problems | Re-Compilations/Sec High | https://BrentOzar.com/go/recompile | 16 |
33-
| 50 | Query Problems | ImplicitTransactions | https://www.brentozar.com/go/ImplicitTransactions/ | 37 |
34+
| 50 | Query Problems | Statistics Updated Recently | https://BrentOzar.com/go/stats | 44 |
3435
| 50 | Server Performance | High CPU Utilization | https://BrentOzar.com/go/cpu | 24 |
3536
| 50 | Server Performance | High CPU Utilization - Non SQL Processes | https://BrentOzar.com/go/cpu | 28 |
3637
| 50 | Server Performance | Page Life Expectancy Low | https://BrentOzar.com/go/ple | 10 |

sp_BlitzFirst.sql

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,34 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
20492049

20502050
END; /* IF @Seconds < 30 */
20512051

2052+
2053+
/* Query Problems - Statistics Updated Recently - CheckID 44 */
2054+
EXEC sp_MSforeachdb N'USE [?];
2055+
INSERT INTO #BlitzFirstResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
2056+
SELECT 44 AS CheckId,
2057+
50 AS Priority,
2058+
''Query Problems'' AS FindingGroup,
2059+
''Statistics Updated Recently'' AS Finding,
2060+
''http://www.BrentOzar.com/go/stats'' AS URL,
2061+
Details =
2062+
QUOTENAME(DB_NAME()) + N''.'' +
2063+
QUOTENAME(SCHEMA_NAME(obj.schema_id)) + N''.'' +
2064+
QUOTENAME(obj.name) + NCHAR(13) + NCHAR(10) +
2065+
N''statistic '' + QUOTENAME(stat.name) + NCHAR(13) + NCHAR(10) +
2066+
N''was updated on '' + CONVERT(NVARCHAR(50), sp.last_updated, 121) + N'','' + NCHAR(13) + NCHAR(10) +
2067+
N''had '' + CAST(sp.rows AS NVARCHAR(50)) + N'' rows, with '' +
2068+
CAST(sp.rows_sampled AS NVARCHAR(50)) + N'' rows sampled,'' + NCHAR(13) + NCHAR(10) +
2069+
N''producing '' + CAST(sp.steps AS NVARCHAR(50)) + N'' steps in the histogram.'' + NCHAR(13) + NCHAR(10) +
2070+
N''This invalidated plans in the cache for this object, causing plan compiles and parameter sniffing.''
2071+
FROM sys.objects AS obj
2072+
INNER JOIN sys.stats AS stat ON stat.object_id = obj.object_id
2073+
CROSS APPLY sys.dm_db_stats_properties(stat.object_id, stat.stats_id) AS sp
2074+
WHERE sp.last_updated > DATEADD(MI, -15, GETDATE())
2075+
AND obj.is_ms_shipped = 0
2076+
AND ''[?]'' <> ''[tempdb]'';';
2077+
2078+
2079+
20522080
RAISERROR('Finished running investigatory queries',10,1) WITH NOWAIT;
20532081

20542082

@@ -3876,7 +3904,8 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
38763904
ELSE 0
38773905
END DESC,
38783906
Finding,
3879-
ID;
3907+
ID,
3908+
CAST(Details AS NVARCHAR(4000));
38803909
END;
38813910
ELSE IF @ExpertMode = 0 AND @OutputType <> 'NONE' AND @OutputXMLasNVARCHAR = 1 AND @SinceStartup = 0
38823911
BEGIN
@@ -3897,7 +3926,8 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
38973926
ELSE 0
38983927
END DESC,
38993928
Finding,
3900-
ID;
3929+
ID,
3930+
CAST(Details AS NVARCHAR(4000));
39013931
END;
39023932
ELSE IF @ExpertMode = 1
39033933
BEGIN
@@ -3955,7 +3985,8 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
39553985
ELSE 0
39563986
END DESC,
39573987
r.Finding,
3958-
r.ID;
3988+
r.ID,
3989+
CAST(r.Details AS NVARCHAR(4000));
39593990

39603991
-------------------------
39613992
--What happened: #WaitStats

0 commit comments

Comments
 (0)