patternsqlModerate
Auto Update Stats not updating Statistics
Viewed 0 times
updateautoupdatingstatsstatisticsnot
Problem
Am using
From the below link I learned that, the Auto Update stats will fire for every
https://blogs.msdn.microsoft.com/srgolla/2012/09/04/sql-server-statistics-explained/
I created a table with 1000 records
Creating statistics
Checking the created Statistics
As per the formula
So If I add/modify
Add
To fire the
Checking the statistics
Unfortunately still the
Even after inserting
SQL SERVER 2012 I have my Auto Update Stats ON in my database. From the below link I learned that, the Auto Update stats will fire for every
SQRT(1000 * Table rows) change in table rows.https://blogs.msdn.microsoft.com/srgolla/2012/09/04/sql-server-statistics-explained/
I created a table with 1000 records
SELECT TOP 500 Row_number()OVER (ORDER BY (SELECT NULL)) rn,
name
INTO stst
FROM sys.objectsCreating statistics
CREATE STATISTICS rn
ON stst (rn)
CREATE STATISTICS name
ON stst (name)Checking the created Statistics
DBCC show_statistics('stst', rn) -- Rows 500
DBCC show_statistics('stst', name) -- Rows 500As per the formula
select SQRT(1000 * 500) -- 707.106781186548So If I add/modify
707.106781186548 records in my table auto update statistics should fire Add
1000 more records to my table which should be more than enough to fire auto update statsINSERT INTO stst(rn,name)
SELECT TOP 1000 Row_number()OVER (ORDER BY (SELECT NULL)) rn,
a.name
FROM sys.objects aTo fire the
auto update statsSelect * from ststChecking the statistics
DBCC show_statistics('stst', rn) -- Rows 500
DBCC show_statistics('stst', name) -- Rows 500Unfortunately still the
Rows is 500 only. Even after inserting
1000 records into my table which is obviously greater than 707.106781186548 while performing SELECT why Auto Update stats didn't fire ? What am I missing hereSolution
The new calculation is only used if trace flag 2371 is enabled, except on SQL Server 2016 when the context database compatibility level is set to 130, where it is the default behaviour. See Microsoft KB 2754171:
Controlling Autostat (AUTO_UPDATE_STATISTICS) behavior in SQL Server
Statistics are not updated when data is modified. A statistics update is triggered when cost-based optimization finds that interesting statistics for the query are stale.
The optimizer does not enter cost-based optimization for very simple ("trivial") queries, where a single obvious plan is always optimal. No statistics updates occur in that scenario.
See the Microsoft White Paper Plan Caching and Recompilation in SQL Server 2012 by Greg Low.
Controlling Autostat (AUTO_UPDATE_STATISTICS) behavior in SQL Server
Statistics are not updated when data is modified. A statistics update is triggered when cost-based optimization finds that interesting statistics for the query are stale.
The optimizer does not enter cost-based optimization for very simple ("trivial") queries, where a single obvious plan is always optimal. No statistics updates occur in that scenario.
See the Microsoft White Paper Plan Caching and Recompilation in SQL Server 2012 by Greg Low.
Context
StackExchange Database Administrators Q#158805, answer score: 11
Revisions (0)
No revisions yet.