Use EXPLAIN to separate row-estimate problems from missing-index and expensive-sort problems.
Do not optimize the query in your head. Inspect the plan the database actually chose. Row estimates Large estimate errors point to stale statistics, correlated columns, or predicates the planner cannot model well. Access path A sequential scan can be fine. An index scan can be bad. Judge by rows touched, selectivity, and whether the path supports order. Join order The first large mistake often multiplies through later joins. Bad cardinality early creates expensive downstream work. Sort and aggregate Sorting or hashing a huge intermediate result can dominate runtime even when the base-table access looks reasonable.
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in