Microsoft Certified IT Professional Rudi Bruchez EI Microsoft Certified IT Professional

Rudi Bruchez EI · www.pachadata.com · rudi@pachadata.com · +33 6 22 48 76 99
Consulting, audit, performance tuning, solutions, training
SQL Server OLTP and BI / NoSQL

Version of December 2, 2026 (ee0bce9d) · https://www.pachadata.com/en/docs/reference/fixed-guesses/

The estimator's fixed guesses

The selectivities SQL Server’s optimizer applies without a histogram, predicate by predicate, for the legacy estimator and models 120 to 170, measured.

Page co-written with Claude, who ran the measurements on both instances.

The fixed guess

To estimate the number of rows a filter lets through, the optimizer usually reads the histogram of a statistic on the column. When it has none, or cannot use it, it takes the density of the statistic when that is enough (an equality on a variable), and otherwise a fixed selectivity written in the engine’s code: a guess, which I give here with its value (“the 30% guess”).

This happens in four situations:

  • the column has no statistic (AUTO_CREATE_STATISTICS set to OFF, or a table just created in a database that does not create them);
  • the column is wrapped in a function (ABS(a) = 5) or compared with another column;
  • the compared value is not known at compile time: a local variable, a parameter compiled with OPTIMIZE FOR UNKNOWN;
  • the object has no statistic at all: a table variable, a multi-statement table-valued function.

The guess shows in the estimated plan, in the Estimated Number of Rows property of the operator that applies the filter. Trace flag 2363, which is undocumented, also writes the calculator chosen: CSelCalcFixedFilter (0.3) for a 30% guess. It only works with models 120 and later: combined with the legacy estimator, the query fails with error 10781.

The “legacy estimator” columns give model 70, obtained with the FORCE_LEGACY_CARDINALITY_ESTIMATION hint. Models 120 to 170 are those of the compatibility levels of SQL Server 2014 to 2025. Unless noted otherwise, the values were measured on a 100,000-row table, on SQL Server 2025 CU11 and SQL Server 2022 CU26, which give the same figures; model 170 exists only on 2025. The script is at the end of the page.

Predicates on a column without a statistic

PredicateLegacy estimatorModels 120 to 170Rows out of 100,000 (recent)
a = 5N^0.75 rowssquare root of N316.23 (legacy: 5,623.41)
a IS NULLN^0.75 rowssquare root of N316.23 (legacy: 5,623.41)
a > 5, <, >=, <=30%30%30,000
a BETWEEN 5 AND 109%9%9,000
a >= 5 AND a <= 109%9%9,000
a <> 51 - N^-0.2551%51,000 (legacy: 94,376.6)
x = y (two columns)10%10%10,000
s LIKE '%abc%'formula on the pattern (see below)9%9,000 (legacy: 19,313.3)
s LIKE 'ab%'formula on the pattern9%9,000 (legacy: 14,484.9)

Equality without a statistic depends on the number of rows in the table, not on a percentage. The selectivity is the square root of N divided by N for models 120 to 170, and N^-0.25 for the legacy estimator. On a million rows, the first would expect 1,000 rows, the second 31,623. IS NULL follows the same rule as equality.

The 9% of a range is not the product of two 30% inequalities. The output of trace flag 2363 shows a single calculator, CSelCalcFixedFilter (0.09), for BETWEEN as well as for >= AND <=, which the optimizer has already merged into one range. The new estimator’s <> is also a constant, CSelCalcFixedFilter (0.51). The value matches 0.3 + 0.3 - 0.3 × 0.3, two inequalities < and > joined by an OR.

The legacy estimator’s LIKE follows a formula that depends on the pattern: 0.09 × k × ln(L) / n, where k is the number of %, n the number of characters of the pattern excluding wildcards, and L half the maximum length of the column. For '%abc%' on a varchar(50): 0.09 × 2 × ln(25) / 3 = 0.193, or 19,313 rows. With a statistic, the LIKE goes through the histogram and the string summary: that is the subject of the article on string statistics.

Function around the column

PredicateLegacy estimatorModel 120Models 130 to 170
ABS(a) = 5, no statistic5,623.41316.2310,000 (10%)
ABS(a) BETWEEN 5 AND 10, no statistic9,000 (9%)16,431.716,431.7

A function around the column prevents reading the histogram, unless an indexed computed column or a statistic on the same expression exists, which is not the case here. On ABS(a) = 5, from model 130 on, trace flag 2363 shows two calculations: a 10% guess (CSelCalcFixedFilter (0.1)), then equality without a statistic (square root of N), and the optimizer keeps the 10%. Model 120 only does the second calculation, equality without a statistic.

The range on a function is no longer merged into a single range: it is two 30% inequalities, combined as two separate predicates (next section): 2363 displays it, 0.3 × 0.3^0.5 = 16.43% with the new estimator. The legacy one gives 9,000 rows, the value of the product 0.3 × 0.3, but 2363 does not work with it, so there is no way to know whether it computes that product or applies 9% directly.

Several predicates on the same table

PredicatesLegacy estimatorModels 120 to 170
a > 5 AND b > 5, no statistic9,000 (0.3 × 0.3)16,431.7 (0.3 × 0.3^0.5)
a = 5 AND b = 5, histograms (0.1% and 1%)1 (0.001 × 0.01 × N)10 (0.001 × 0.01^0.5 × N)
the same with k > 50000 (50%)18.41 (0.001 × 0.01^0.5 × 0.5^0.25 × N)

The legacy estimator multiplies the selectivities: it assumes the columns are independent. Two equalities with no statistic at all are an exception: a = 5 AND b = 5 gives 2,738.42 rows, not the product (316.2); I did not establish the rule it applies then. The new one applies an exponential backoff: it sorts the selectivities from lowest to highest and takes the first in full, the square root of the second, the fourth root of the third, the eighth root of the fourth. Beyond four predicates, the following ones are ignored: five inequalities without a statistic give the same estimate as four. The estimate stays higher, because columns filtered together are often correlated. Both estimators round up to a minimum of 1 row: the 0.5 row computed by the legacy one becomes 1.

A multi-column statistic changes these figures. It deserves its own table, which I have not included here.

Unknown value on a column with a statistic

Column a here has a FULLSCAN statistic, with 1,000 distinct values. The compared value is a local variable, which the optimizer does not know at compile time.

PredicateLegacy estimatorModels 120 to 170
a = @v100 (density × N)100 (density × N)
a > @v30,000 (30%)30,000 (30%)
a BETWEEN @v AND @w9,000 (9%)16,431.7 (0.3 × 0.3^0.5)
a <> @v94,376.6 (1 - N^-0.25)90,000 (90%)
s LIKE @p5,375.28 (0.015 × ln L, L = 36)9,000 (9%)
for comparison, a <> 599,900 (histogram)99,900 (histogram)

Equality reads the density of the statistic (All density, 1 / 1,000 here) and assumes the value has an average frequency. That is right for a column whose values are evenly distributed, wrong for a very frequent value. Inequalities ignore the statistic and take 30%, and the range between two variables is treated as two inequalities. The <> on a variable is 90% with the new estimator, unrelated to the density: with 1,000 distinct values, the complement of the density would give 99.9%.

OPTION (RECOMPILE) gives the optimizer the variable’s current value, and it goes back to the histogram. A procedure parameter is estimated on its compile-time value, except with OPTIMIZE FOR UNKNOWN or DISABLE_PARAMETER_SNIFFING, which treat it as a local variable.

Ascending key, values beyond the histogram

The statistic was computed on 100,000 rows (about 10 rows per value, from 0 to 10,000), then 9,999 rows were added with values greater than the last step of the histogram, without updating the statistics.

PredicateLegacy estimatorModels 120 to 160Model 170
g = 10500110 (density × rows of the statistic)1 (density × added rows)
g > 1000112,999.7 (30% of the added rows)2,999.7
k BETWEEN 100001 AND 100100 (unique key, 10,000 rows added)1900 (9% of the added rows)900
g = 500 (value in the histogram)101111

The legacy estimator sees nothing beyond the histogram and estimates 1 row. Models 120 and later apply the fixed guesses to only the number of rows added since the statistic. For equality, model 170 of SQL Server 2025 changes the base: it multiplies the density by the added rows, no longer by the rows of the statistic. I did not find this change in the Microsoft documentation.

The last row shows another difference: for a value present in the histogram, models 120 and later scale the estimate to the table’s current number of rows (109,999 instead of 100,000), and the legacy estimator does not.

Table variables and multi-statement table-valued functions

ObjectLegacy estimatorModels 120 to 170
table variable, deferred compilation (level 150 and above)actual rows (1,000)actual rows (1,000)
the same with WHERE i > 500300 (30%)300 (30%)
table variable, DISABLE_DEFERRED_COMPILATION_TV11
multi-statement function, interleaved execution (level 140 and above)actual rows (1,000)actual rows (1,000)
the same, DISABLE_INTERLEAVED_EXECUTION_TVF1100

A table variable has no statistic. Since SQL Server 2019, at compatibility level 150, the compilation of the statement is deferred until its first execution, and the optimizer then knows the number of rows of the variable. It still does not know their distribution: a filter receives the fixed guess, 30% for an inequality. Before level 150, or with the hint that disables it, the estimate is one row.

A multi-statement table-valued function is estimated at 100 rows by models 120 and later, and at 1 row by the legacy estimator. Since SQL Server 2017, at level 140, interleaved execution runs the function before compiling the rest of the plan, and the estimate becomes the actual number of rows, whatever the model.

Both mechanisms are part of Intelligent Query Processing; their availability by edition is in the table IQP in Standard edition.

Redoing the measurement

Measurement script

The script creates a lab database, because the demonstration needs a database where AUTO_CREATE_STATISTICS is OFF: in an ordinary database, the first compilation creates the statistic and the fixed guess disappears. Read each estimate in the estimated plan (Ctrl+L in SSMS), at the operator that filters. Add OPTION (USE HINT('FORCE_LEGACY_CARDINALITY_ESTIMATION')) for the legacy estimator, or OPTION (USE HINT('QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_120')) for another model.

-- Lab database, with no automatic creation or update of statistics
CREATE DATABASE LaboEstimations;
GO
ALTER DATABASE LaboEstimations SET AUTO_CREATE_STATISTICS OFF;
ALTER DATABASE LaboEstimations SET AUTO_UPDATE_STATISTICS OFF;
GO
USE LaboEstimations;
GO
-- 100,000 rows: a has 1,000 distinct values, b 100
WITH n AS (
    SELECT TOP (100000) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS i
    FROM sys.all_columns AS c1
    CROSS JOIN sys.all_columns AS c2
)
SELECT CAST(i % 1000 AS int) AS a,
       CAST(i % 100 AS int) AS b,
       CAST(i % 500 AS int) AS x,
       CAST(i % 700 AS int) AS y,
       CAST(CONVERT(varchar(36), NEWID()) AS varchar(50)) AS s,
       CAST(i AS int) AS k
INTO dbo.SansStat
FROM n;

-- The same table, with full statistics
SELECT * INTO dbo.AvecStat FROM dbo.SansStat;
CREATE STATISTICS st_a ON dbo.AvecStat (a) WITH FULLSCAN;
CREATE STATISTICS st_b ON dbo.AvecStat (b) WITH FULLSCAN;
CREATE STATISTICS st_s ON dbo.AvecStat (s) WITH FULLSCAN;
CREATE STATISTICS st_k ON dbo.AvecStat (k) WITH FULLSCAN;

-- Ascending key, unique key: 10,000 rows added beyond the histogram
SELECT k INTO dbo.Cle FROM dbo.SansStat;
CREATE STATISTICS st_k ON dbo.Cle (k) WITH FULLSCAN;
INSERT dbo.Cle (k) SELECT k + 100000 FROM dbo.SansStat WHERE k <= 10000;

-- Ascending key, about 10 rows per value: 9,999 rows added
SELECT k / 10 AS g INTO dbo.Cle2 FROM dbo.SansStat;
CREATE STATISTICS st_g ON dbo.Cle2 (g) WITH FULLSCAN;
INSERT dbo.Cle2 (g) SELECT g + 10001 FROM dbo.Cle2 WHERE g < 1000;
GO

-- Multi-statement table-valued function of 1,000 rows
CREATE FUNCTION dbo.Mstvf()
RETURNS @r TABLE (i int)
AS
BEGIN
    INSERT @r SELECT TOP (1000) k FROM dbo.SansStat;
    RETURN;
END;
GO

-- Column without a statistic (estimated plan)
SELECT * FROM dbo.SansStat WHERE a = 5;
SELECT * FROM dbo.SansStat WHERE a IS NULL;
SELECT * FROM dbo.SansStat WHERE a > 5;
SELECT * FROM dbo.SansStat WHERE a BETWEEN 5 AND 10;
SELECT * FROM dbo.SansStat WHERE a >= 5 AND a <= 10;
SELECT * FROM dbo.SansStat WHERE a <> 5;
SELECT * FROM dbo.SansStat WHERE x = y;
SELECT * FROM dbo.SansStat WHERE s LIKE '%abc%';
SELECT * FROM dbo.SansStat WHERE s LIKE 'ab%';

-- Function around the column
SELECT * FROM dbo.SansStat WHERE ABS(a) = 5;
SELECT * FROM dbo.SansStat WHERE ABS(a) BETWEEN 5 AND 10;

-- Several predicates
SELECT * FROM dbo.SansStat WHERE a > 5 AND b > 5;
SELECT * FROM dbo.AvecStat WHERE a = 5 AND b = 5;
SELECT * FROM dbo.AvecStat WHERE a = 5 AND b = 5 AND k > 50000;

-- Unknown value (variables are declared in the same batch)
DECLARE @v int = 5, @w int = 10, @p varchar(50) = '%abc%';
SELECT * FROM dbo.AvecStat WHERE a = @v;
SELECT * FROM dbo.AvecStat WHERE a > @v;
SELECT * FROM dbo.AvecStat WHERE a BETWEEN @v AND @w;
SELECT * FROM dbo.AvecStat WHERE a <> @v;
SELECT * FROM dbo.AvecStat WHERE s LIKE @p;
SELECT * FROM dbo.AvecStat WHERE a <> 5;

-- Ascending key
SELECT * FROM dbo.Cle2 WHERE g = 10500;
SELECT * FROM dbo.Cle2 WHERE g > 10001;
SELECT * FROM dbo.Cle2 WHERE g = 500;
SELECT * FROM dbo.Cle WHERE k BETWEEN 100001 AND 100100;
GO

-- Table variable and multi-statement function (actual plan)
DECLARE @t TABLE (i int);
INSERT @t SELECT TOP (1000) k FROM dbo.SansStat;
SELECT * FROM @t;
SELECT * FROM @t WHERE i > 500;
SELECT * FROM @t OPTION (USE HINT('DISABLE_DEFERRED_COMPILATION_TV'));
SELECT * FROM dbo.Mstvf() AS f JOIN dbo.Cle AS c ON c.k = f.i;
SELECT * FROM dbo.Mstvf() AS f JOIN dbo.Cle AS c ON c.k = f.i
OPTION (USE HINT('DISABLE_INTERLEAVED_EXECUTION_TVF'));
GO

The calculator chosen is displayed with two undocumented trace flags, to be reserved for a test instance:

USE LaboEstimations;
DBCC TRACEON (3604);
SELECT COUNT(*) FROM dbo.SansStat WHERE a BETWEEN 5 AND 10
OPTION (QUERYTRACEON 2363, RECOMPILE);
-- Messages tab: CSelCalcFixedFilter (0.09), Selectivity: 0.09
DBCC TRACEOFF (3604);
GO

-- To finish
USE master;
DROP DATABASE LaboEstimations;

Table variables and the multi-statement function are read in the actual plan (Ctrl+M), because deferred compilation and interleaved execution act only at execution time. Run the last batch of the script with the actual plan enabled.

Contact

I have been an independent SQL Server consultant since 2006. I help when an application slows down, when a server costs too much in storage or licenses, or when a migration must not stop production: audit and diagnosis, query and index tuning, migrations, high availability, training. On site, or as a remote audit delivered in five working days.

rudi@pachadata.com · +33 6 22 48 76 99 · www.pachadata.com/en/contact/