skip to content
09, 13 chapters
how a query runs
everything.execution

how a query runs

parse, plan, execute. EXPLAIN, scans, joins, sorts, and the iterator that pulls one row at a time.

start part 09part 09 of 18, 13 chapters
  1. 09.01relational algebraselection, projection, join and friends. the handful of operators every query compiles down to.
  2. 09.02the life of a queryparser, analyzer, rewriter, planner, executor. one query watched at every stage.
  3. 09.03the system catalogpg_class, pg_attribute, pg_type. the tables that describe your tables, and how names become numbers.
  4. 09.04reading EXPLAINa tree you read from the inside out. cost, rows, width, and what each number actually means.
  5. 09.05EXPLAIN ANALYZE and BUFFERSestimates next to actuals, loops, shared hit vs read, and the Index Searches line new in postgres 18.
  6. 09.06the executor and the iterator modelevery plan node answers one question: next row, please? press next() and watch one row climb.
  7. 09.07seq scans, index scans and bitmap scansthree ways to read a table, and the bitmap that turns random reads back into sequential ones.
  8. 09.08nested loop joinsfor each outer row, look for matches. dumb, and perfect when one side is tiny. plus Memoize.
  9. 09.09hash joinsbuild a hash table on the small side, probe it with the big one. and what happens when it doesn't fit.
  10. 09.10merge joinstwo sorted inputs, two cursors walking forward. why sorted order is a resource.
  11. 09.11sorting and work_memquicksort in memory, top-N heapsort for LIMIT, external merge on disk, and Incremental Sort.
  12. 09.12how GROUP BY runsHashAggregate vs GroupAggregate, and the hash table that spills to disk.
  13. 09.13parallel queryGather, workers and partial aggregates. why one query used four cores, and why it can't in this page.