# Statistics: Key to Query Optimization
> [!Note]
> Accurate and up‐to‐date **statistics**—including **histograms**, **density** metrics, and **string statistics**—are crucial for the **cost‐based optimizer** to generate efficient execution plans and reliably estimate cardinalities under diverse query patterns.
In SQL Server, the optimizer relies on a **cost–estimation** model that uses statistics to predict how many rows each operator will process. **Histograms** reveal the distribution of values in a column’s first 200 steps, while **density** statistics quantify the selectivity of equality predicates. For textual data, **string statistics** improve cardinality estimates on `LIKE` and full‐text searches.
> [!info]
> **Critical Maintenance**
> Periodic execution of `UPDATE STATISTICS` (or enabling `AUTO_UPDATE_STATISTICS`) prevents outdated histograms—especially on **ever‐increasing** keys—from misleading the optimizer and spawning suboptimal plans.
Since SQL Server 2014, the **new cardinality estimator** enhances multi‐column and skewed data scenarios, but it may alter established performance baselines. Testing under both the legacy and new estimators ensures that plan changes deliver genuine benefit.
> [!tip]
> Always compare execution plans and runtime metrics after updating statistics or switching estimators to confirm that **precise statistics** translate into **superior performance**.
Ultimately, the goal is simple: **accurate statistics = optimal execution plans = superior query performance**.
---
## ## References
- Korotkevitch, D. (2022). _SQL Server advanced troubleshooting and performance tuning: Best practices and techniques_. O’Reilly Media.
- Nevarez, B. (2022). _SQL Server query tuning and optimization: Optimize Microsoft SQL Server 2022 queries and applications_. Packt Publishing.