StuckOut

ResourcesDatabases

How to Read a SQL Execution Plan

Your query times out on a small table. The plan tells you exactly why, once you can read it.

7 min read

Read it inside out

Plans are trees. The deepest, most indented nodes run first. Start there rather than at the top, which is where most people start and get lost.

Look for the scan type

A sequential scan on a large table where you expected an index scan is usually the whole answer. It means the planner decided your index was not worth using, or there is no usable index.

Compare estimated to actual rows

A big gap between estimated and actual is the planner working from stale statistics. That single number explains most mysteriously slow queries.

Then, and only then, add an index

Adding indexes before reading the plan is guessing. Sometimes the fix is rewriting the join, not indexing it.

Still not moving?

If this did not unstick you, the problem is probably specific to your code or your data. Send it over and we will look at the actual thing.

Send my requirements →

Related subjects