Problem Statement
You see large gaps between estimated and actual rows in a plan. Walk through a systematic way to fix this.
Explanation
Start by checking statistics on columns in filters and joins. Update them and ensure histograms capture skewed distributions. If correlations exist between columns, consider composite indexes or extended statistics so the optimizer understands joint selectivity.
Next, rewrite non-SARGable predicates and add selective indexes to reduce row counts early. Re-run the plan to confirm estimates converge toward actuals, and verify that the join order now favors smaller, selective inputs.
Code Solution
SolutionRead Only
CREATE STATISTICS s_orders ON orders(status, country); -- or extended stats equivalent per engine
