SQL Server Statistics Deep Dive: Why Outdated Stats Kill Query Performance (DBA Tuning)

Опубликовано: 18 Май 2026
на канале: Generiss Academy
3
0

Statistics are the unsung heroes of query performance. They are internal histograms used by the query optimizer to make critical decisions about execution plans. When statistics are wrong, the optimizer makes bad decisions, leading directly to slow queries.


The Role of Statistics:
What they are: Small objects that summarize the distribution of data values in columns.
Purpose: The optimizer uses them to calculate cardinality estimates (how many rows a query will return). Accurate estimates lead to efficient execution plans (Index Seeks over Table Scans).
Creation: Statistics are created automatically when you build an index or when the optimizer finds no existing statistics for a column used in a predicate. You can view them with DBCC SHOW_STATISTICS.
The Stale Statistics Problem:
Auto Update Threshold: By default, SQL Server only automatically updates statistics after a certain percentage of data changes. For very large tables, this threshold can be too high, causing statistics to become stale and performance to suffer dramatically before an automatic update occurs.
Bad Plans: Stale statistics lead to massive differences between the estimated number of rows and the actual number of rows, forcing the optimizer to choose an inefficient plan.
Maintenance and T-SQL:
Manual Update: For high-volume environments, manual updates are necessary to stay ahead of the auto-update threshold.
Efficient Update: EXEC sp_updatestats; updates only statistics that have changed since the last run.
Full Accuracy: Use WITH FULLSCAN to create the most accurate statistics possible, especially for columns with uneven data distribution.
Scheduling: Run a dedicated statistics update job after your index maintenance window to ensure all tables are covered.
Timestamps
0:00 - Introduction: The Core of Query Optimization
0:45 - What Statistics Are and How They Are Created
1:45 - How Stale Statistics Cause Performance Regressions
2:45 - T-SQL Commands to Update Statistics: sp_updatestats and FULLSCAN
3:30 - Best Practices for Statistics Maintenance Scheduling