@sargonpiraev

Query planner

Created 1 min readseed · 1/5#database

A query planner chooses how to execute a declarative query: which access methods to use (full scan vs index), how to join inputs (nested loop, hash join, merge join), and in what order.

It builds on statistics about tables—row counts, value distributions—so stale stats often produce bad plans even when the SQL is fine.

Prefer execution feedback that includes real timings, not estimates alone: the gap between estimated and actual row counts is the usual signal that something is wrong.

For how PostgreSQL’s planner and EXPLAIN fit together, see Postgres query planner.