Few things shape a SQL Server query plan as quietly as statistics, and at SQLDay Lite 2026 they had a whole session to themselves. "Mastering Statistics in Microsoft SQL Server" was presented by Uwe Ricken of db Berater GmbH, a Microsoft Certified Master: SQL Server 2008 who received the Microsoft MVP Award for SQL Server in 2013 and has worked with SQL Server since version 6.0. The conference was organized by Data Community Poland at the Gdańsk University of Technology on 24-25 September 2026.
Statistics are one of those topics every SQL Server professional has heard of and few have looked at closely. Yet they decide whether a query reads ten rows through an index or scans a million, which makes them one of the most direct levers on performance that data teams have. Uwe's session went from the big picture to the bytes inside a statistics object, with a demo script for nearly every claim.
Why the optimizer needs a model of your data
Uwe opens with a definition worth keeping: statistics are "the tiny data models that tell the optimizer what your tables look like." To show why the optimizer needs them, the session compares running a query to planning a house.
Parsing is someone reading your request and checking that the grammar makes sense. Compilation is the architect turning your idea into a structured blueprint, collecting the tools, workers, machines and materials the project will need. Optimization is the architect pricing each option and picking the most cost-effective combination. The speaker notes give an example: should five workers dig the construction pit by hand, or should an excavator do it? The architect calculates both and chooses the cheaper one.
The point the slides underline is that at this stage the architect is planning the house, not building it. Every cost is an estimate, and those estimates come from statistics. If the architect misjudges the size of the pit, the whole plan follows that misjudgement.
When SQL Server creates statistics, and when it doesn't
The first block of demos looks at the three ways statistics objects come into existence:
- Automatic creation, when the database option Auto Create Statistics is on. Filtering
dbo.orderson a column without an index makes SQL Server create a_WA_Sys_...statistics object for that column on the spot. - Index creation, because every index builds a statistics object on its key columns. The demo shows that these start with a 100% sample rate.
- Manual creation with
CREATE STATISTICS, for filtered statistics, multi-column statistics or tighter control over precision.
Some of the details are easy to miss in daily work. The demos show that a SELECT DISTINCT on a column triggers a new statistics object while an ORDER BY does not, and that simply compiling a query (Ctrl+L in SSMS, without executing it) is already enough to create one. They also show that an auto-created statistics object stays in place when you later add an index on the same column, so tables can quietly collect overlapping statistics over time.
On the manual side, the scripts walk through the options you can attach to CREATE STATISTICS: NORECOMPUTE to exclude an object from automatic updates, a WHERE clause for a filtered statistic on one value such as o_orderpriority = '2-HIGH', and SAMPLE 30 PERCENT with PERSIST_SAMPLE_PERCENT = ON to keep a chosen sample rate across future updates.
How the auto-update threshold changed with SQL Server 2016
Statistics only help while they reflect the data, so the session spends time on when SQL Server refreshes them. The slides show the classic rule from before SQL Server 2016: for tables with more than 500 rows, an automatic update kicks in after 500 rows plus 20% of the table have changed. From SQL Server 2016 the threshold depends on the compatibility level and follows a dynamic formula.
Uwe's demo script puts the two rules side by side for table sizes from 100 rows up to ten billion:
SELECT rows,
CAST((500 + (rows * 0.2)) AS BIGINT) AS [<
SELECT rows,
CAST((500 + (rows * 0.2)) AS BIGINT) AS [<
SELECT rows,
CAST((500 + (rows * 0.2)) AS BIGINT) AS [<
The difference grows quickly with table size. Using the demo's formulas, a table with one million rows needed 200,500 modifications under the old rule, compared with about 31,600 under the square-root rule. A chart in the deck, "Fixed vs. dynamic Auto Update Statistics", shows the same thing as a percentage: the traditional fixed threshold stays flat at 20%, while the dynamic threshold (which trace flag 2371 enabled on older versions) drops towards a fraction of a percent for very large tables.
The session also makes clear that reaching the threshold does not refresh anything by itself. A statistics update happens the next time the optimizer compiles a query that needs that statistic and finds it stale. The slides trace the sequence: the binding phase, loading the statistics, checking whether they are out of date, updating them if so, and only then building the plan, with the schema stability and schema modification locks this involves. To watch this happen, Uwe uses an Extended Events session on the sqlserver.auto_stats event with a ring buffer target, plus a small stored procedure, sp_read_xevent_auto_stats, that reads which statistics were updated, how long it took and at what sample rate. A further demo looks at how automatic updates behave when a query gets a trivial plan.
What's inside a statistics object
The internals section splits a statistics object into three parts:
- STATS_HEADER, with general information about the object
- DENSITY_VECTOR, the average distribution of rows per unique combination of key columns
- HISTOGRAM, the distribution of values in the first key column
As background: the histogram holds up to 200 steps, each recording a boundary value, how many rows equal it and how many fall in the range below it.
The classic way to read all this is DBCC SHOW_STATISTICS, and the demos use it alongside the newer catalog views and functions: sys.stats, sys.dm_db_stats_histogram(), sys.dm_db_stats_properties() and sys.dm_db_stats_properties_internal(). The functions return rows you can join and filter, which makes them practical for scripting checks across many tables. One of Uwe's helper functions in the demo database does exactly that, listing each statistics object on a table with its columns, origin, filter and sample settings.
Known values versus unknown values
The most practical lesson sits on a single slide: the histogram can only be used if the value of the predicate is known at compile time. If it isn't, SQL Server falls back to the density vector.
The demo makes this concrete with a copy of sys.messages and an index on severity. A query with the literal severity = 12 gets an accurate estimate straight from the histogram. The same query with a local variable gets an estimate of 23,075 rows. The script explains where that number comes from: the index has 16 distinct severity values, so the density is 1/16 = 0.0625, and the estimate is simply the table's row count multiplied by 0.0625. Every value gets the same average, however common or rare it really is.
The fix shown in the demo, from Uwe's scripts:
DECLARE @severity SMALLINT = 12;
SELECT *
FROM dbo.messages
WHERE severity = @severity
ORDER BY language_id, message_id
OPTION (RECOMPILE);
DECLARE @severity SMALLINT = 12;
SELECT *
FROM dbo.messages
WHERE severity = @severity
ORDER BY language_id, message_id
OPTION (RECOMPILE);
DECLARE @severity SMALLINT = 12;
SELECT *
FROM dbo.messages
WHERE severity = @severity
ORDER BY language_id, message_id
OPTION (RECOMPILE);
With OPTION (RECOMPILE) the variable's value is known when the plan is compiled, so the histogram comes back into play.
A second demo takes the same idea across a join. With 1.6 million customers and 47 nations, filtering on n_nationkey = 44 and filtering on n_name = 'Portugal' return the same customers, but the optimizer knows far more in the first case. When the filter is on the name, SQL Server does not know the matching key while it estimates the customers table, so it uses the density vector of the c_nationkey index and estimates 32,815 rows. The demo then works through the options for telling SQL Server more, first a unique index on n_name, then a filtered statistics object on n_nationkey WHERE n_name = 'PORTUGAL' combined with a recompile, and compares the resulting plans.
Practical takeaways
- Check your database settings: Auto Create Statistics, Auto Update Statistics and Auto Update Statistics Asynchronously each change how and when statistics appear.
- Know your compatibility level, because it decides which auto-update threshold applies to large tables.
- Use
sys.dm_db_stats_properties()to comparemodification_counteragainst the threshold before a big load. - When estimates look surprising, ask whether the predicate value was known at compile time. Local variables and parameters lead to the density vector unless the plan is recompiled.
- Consider filtered or manual statistics for skewed values and correlated columns that the defaults don't capture.
- Keep statistics maintenance in your regular jobs. The session recommends Ola Hallengren's SQL Server Maintenance Solution and includes it in the demo folder.
Good estimates start with well-understood data
Uwe's session is a reminder that the optimizer makes decisions from a summary of the data, not from the data itself. When the shape of a table changes, for example a load doubles its size or one value suddenly dominates a column, the plans built on yesterday's statistics can drift away from reality until the next update catches up.
The same changes matter well beyond query plans. A sudden jump in row counts or a shift in a column's value distribution often signals something upstream: a duplicated load, a changed filter in an ETL job, or a new source system sending different codes. Monitoring volumes and distributions over time catches these shifts early, which is what digna's Data Anomalies module does by learning each table's normal patterns and flagging deviations automatically.
Thank you, Uwe and SQLDay Lite
Many thanks to Uwe Ricken for a session packed with runnable demos and clear explanations, and to Data Community Poland for organizing SQLDay Lite 2026 in Gdańsk. The slides and demo scripts are available in the SQLDay Lite 2026 repository, and Uwe also publishes the material in the Mastering SQL Server Statistics repository on GitHub. For anyone who wants to keep practising, Uwe runs monthly real-world scenarios at SQL Challenges. More about the conference is on the SQLDay Lite website.
Frequently asked questions
When does SQL Server automatically update statistics?
SQL Server updates statistics once enough rows change and a query that needs them is compiled. Before SQL Server 2016, large tables needed 500 rows plus 20% of the table to change; from 2016 a dynamic formula applies, so a one-million-row table needs about 31,600 modifications instead of 200,500.
Why does a local variable cause a poor cardinality estimate in SQL Server?
Because the value is unknown at compile time, SQL Server cannot use the histogram and falls back to the density vector. In Uwe Ricken's demo on a copy of sys.messages, 16 distinct severity values gave a density of 0.0625, so every value received the same estimate of 23,075 rows.
How does OPTION (RECOMPILE) improve query estimates?
It lets the optimizer see the variable's actual value when the plan is compiled, so the histogram comes back into play instead of the density vector. The session showed this fix for queries with local variables, where a histogram-based estimate replaced the flat average applied to every value.
What are the three parts of a SQL Server statistics object?
A statistics object consists of the STATS_HEADER, the DENSITY_VECTOR and the HISTOGRAM. The header holds general information, the density vector stores the average rows per unique key combination, and the histogram describes the first key column in up to 200 steps, readable with DBCC SHOW_STATISTICS or sys.dm_db_stats_histogram().
What makes SQL Server create statistics automatically?
With Auto Create Statistics on, filtering on a column without an index creates a _WA_Sys_ statistics object immediately. Uwe Ricken's demos also showed that SELECT DISTINCT triggers one while ORDER BY does not, and that merely compiling a query in SSMS with Ctrl+L is enough to create it.