Why new rows beyond the last histogram step get badly under-estimated in SQL Server, how the legacy and new cardinality estimators differ, and how to keep statistics current after loads.
Statistics hold a histogram of at most 200 steps built at the last update. Rows added since then with keys beyond the last step — today's dates, new identity values — are invisible to it. The legacy cardinality estimator (CE) typically estimates 1 row for them; the new CE (compat 120+) assumes the rows exist and estimates from density and the modification counter, which is better but often still low after a big load. The bad estimate cascades: nested loops instead of hash joins, tiny memory grants that spill. I fix it by updating statistics as the last step of the load, watching modification_counter, and using incremental statistics on partitioned tables so the update is cheap.
What happens. A statistics object's histogram is built when statistics are created or updated. Columns that only grow — CreatedAt, an IDENTITY key, a batch number — keep adding values above the last histogram step (RANGE_HI_KEY). Auto-update only fires after enough modifications (since compat 130 the threshold is roughly SQRT(1000 × rows), so about 1 million changes for a 1-billion-row table). Until then, queries for "today" ask about a range the histogram knows nothing about.
What each estimator does.
Why it matters. The estimate drives every downstream choice: a 1-row estimate gives nested loops with key lookups and a tiny memory grant. With 500,000 actual rows that means millions of lookups and a sort that spills to tempdb. This is a classic "the 9 am report is slow, but fine by lunchtime" pattern — auto-update eventually catches up.
How I deal with it.
UPDATE STATISTICS dbo.Orders IX_Orders_CreatedAt), on the specific statistics that matter, not the whole database.modification_counter and last_updated from sys.dm_db_stats_properties; a maintenance job updates statistics whose counter passes a threshold you choose.INCREMENTAL = ON and update only the new partition with RESAMPLE ON PARTITIONS(n). The optimiser still uses one merged histogram, but keeping it fresh becomes cheap.OPTION (RECOMPILE) after the load, or filtered statistics on the recent range.Example. A nightly ETL into Azure SQL loaded ~2 million rows into Transactions. The morning reconciliation query filtered WHERE PostedAt >= @today and took 4 minutes; the actual plan showed estimated 1 row (the database was still at compat 110), actual 2.1 million. Adding a statistics update as the final ETL step and moving to compat 160 brought it to 6 seconds.
Checks a very common real-world cause of morning slowdowns and whether the candidate reads estimated vs actual rows.
Green flags: explains the histogram's last step and auto-update thresholds; contrasts legacy and new CE; connects the estimate to join choice and memory grants; fixes it in the load process; mentions modification_counter and incremental statistics.
Red flags: "rebuild all indexes nightly"; doesn't know statistics have a histogram; blames the server or adds hardware; can't explain why it gets better later in the day.
Histogram limits. At most 200 steps (plus a NULL step). Each step records RANGE_HI_KEY, EQ_ROWS, RANGE_ROWS, DISTINCT_RANGE_ROWS and AVG_RANGE_ROWS. Anything above the highest RANGE_HI_KEY is out of range.
Auto-update thresholds. Historically 500 + 20% of rows. Since compat 130 (SQL Server 2016) a dynamic threshold of MIN(500 + 0.2 × n, SQRT(1000 × n)) applies, so large tables update more often. Auto-update happens when a query that needs the statistics compiles, synchronously by default; AUTO_UPDATE_STATISTICS_ASYNC avoids the compile stall but the first query still uses stale statistics.
Legacy workarounds. Under the legacy CE, trace flags 2389 and 2390 let SQL Server detect "ascending" columns (branding) and do a quick max-value lookup at compile time. The new CE's out-of-range model mostly replaces them.
Sampling. Default sampling on big tables can miss skew in the newest data. PERSIST_SAMPLE_PERCENT = ON keeps a chosen sample rate for later auto-updates.
Incremental statistics. Built per partition and merged; UPDATE STATISTICS ... WITH RESAMPLE ON PARTITIONS(...) touches only changed partitions. They aren't used for partition-level estimates and the merged histogram still has 200 steps, so they reduce maintenance cost rather than changing the estimation model.
Where it shows up. Date-based reporting, "latest N" queues, outbox tables polled by Id > @lastId, and any IDENTITY key used as a high-water mark.
-- How stale are the statistics on the hot table?
SELECT s.name AS stats_name,
sp.last_updated,
sp.rows,
sp.modification_counter,
sp.steps
FROM sys.stats AS s
CROSS APPLY sys.dm_db_stats_properties(s.object_id, s.stats_id) AS sp
WHERE s.object_id = OBJECT_ID(N'dbo.Transactions');
-- Where does the histogram end?
DBCC SHOW_STATISTICS ('dbo.Transactions', 'IX_Transactions_PostedAt') WITH HISTOGRAM;
-- Last step of the ETL
UPDATE STATISTICS dbo.Transactions IX_Transactions_PostedAt WITH FULLSCAN;
-- Partitioned table: incremental statistics, update only the new partition
CREATE STATISTICS st_Transactions_PostedAt
ON dbo.Transactions (PostedAt) WITH INCREMENTAL = ON;
UPDATE STATISTICS dbo.Transactions st_Transactions_PostedAt
WITH RESAMPLE ON PARTITIONS (42);
sp_updatestats nightly instead of updating the few statistics that matter right after the load.AUTO_UPDATE_STATISTICS_ASYNC and thinking it solves the first slow query.I treat statistics as part of the data pipeline, not DBA housekeeping: the job that loads data owns making the statistics true afterwards. The sign to look for is a large gap between estimated and actual rows on a date or identity predicate, especially one that gets better on its own later in the day. I'd also design queries that touch recent data so a moderate misestimate doesn't flip the plan — a covering index on the date avoids lookups, so a bad estimate costs less. On Azure SQL, where maintenance windows are yours to manage, an explicit statistics step in the ETL is cheap insurance.
How to tell it (STAR)
**Situation:** At [company], our reconciliation job took [duration] every morning but was fast by lunchtime. **Task:** I needed to find out why. **Action:** I compared estimated and actual rows in the plan, found a 1-row estimate on today's dates, confirmed with sys.dm_db_stats_properties that statistics predated the load, and added a statistics update as the last ETL step. **Result:** The job dropped to [duration] and stayed there.
Last updated 23 Nov 2026.