You have a slow query and its execution plan. What do you look at first, and in what order?
Why they ask this
It separates people who read plans from people who have seen one. The order matters, because starting at the top-level cost tells you nothing about which operator to fix.
Say this
Find the operator doing the most work — usually the widest scan or the biggest sort — then check whether the row-count estimate near it matches reality. A plan with good estimates and an honest full scan is a different problem from a plan built on a wrong guess.
The reasoning
The three things worth reading, in order. First, access method per table: a full scan where you expected a lookup means the predicate could not be used, and that is a query fix. Second, estimated against actual rows: if they disagree by an order of magnitude, the optimizer chose a plan for a table it thinks is a different size, and the fix is statistics rather than SQL. Third, the blocking operators — sorts, hash builds, spills — because those are where memory and time go.
Join order and join strategy follow from those. A nested loop over a million estimated rows is a symptom of a bad estimate, not a bad decision — the planner would have chosen a hash join if it had known.
What not to do is read the total cost number and try to make it smaller. It is a unitless estimate from the same model that produced the bad plan; on the query you are debugging, it is the thing that is wrong.
The answer most people give
"Look for the operator with the highest cost percentage and optimise that." Cost percentages come from the estimates. When the estimate is the problem — which is most of the time on a query that regressed — the percentages point at the wrong operator.
They’ll ask next
Estimated rows say 12, actual says 4 million. What do you do, and what do you not bother doing?
