LEGACY_CARDINALITY_ESTIMATION
Use the pre-2014 cardinality estimator in this database regardless of compatibility level.
- Par défaut
OFF- Range
- ON, OFF, PRIMARY (secondary only)
- Restart needed
- Non
- Default checked on
- SQL Server 2025
Ce que cela fait
Lets a database get the newer compatibility level's features while keeping the old estimator's row estimates. Per query, the hint USE HINT('FORCE_LEGACY_CARDINALITY_ESTIMATION') does the same.
Valeur par défaut
OFF. OFF (SQL Server 2025).
Check the current value
-- run in the database you want to check SELECT name, value, value_for_secondary, is_value_default FROM sys.database_scoped_configurations WHERE name = 'LEGACY_CARDINALITY_ESTIMATION';
Change it
-- run in the database to change ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = ON;
No restart. It applies to the current database, to queries compiled after the change; run it in each database that needs it.
When to change it
After an upgrade where many queries regressed because of estimate changes and you need time to fix them.
What can go wrong
Locks the database to the old model's blind spots; plan for it to be temporary.
Questions about LEGACY_CARDINALITY_ESTIMATION
What is the default value of LEGACY_CARDINALITY_ESTIMATION in SQL Server?
OFF. OFF (SQL Server 2025).
Does changing LEGACY_CARDINALITY_ESTIMATION require a restart?
No. No restart. It applies to the current database, to queries compiled after the change; run it in each database that needs it.
When should I change LEGACY_CARDINALITY_ESTIMATION?
After an upgrade where many queries regressed because of estimate changes and you need time to fix them.
Back to all SQL Server settings, or check the SQL Server manual for every option.
Check LEGACY_CARDINALITY_ESTIMATION on your own server
SQLly runs the query above against SQL Server and the other engines in this reference, from one desktop app on macOS, Windows and Linux.