Reference · Cheat sheet

Reading EXPLAIN

Lesson 0006 distilled — the node line, ANALYZE vs plain, and the one check that matters. Built to print.

From lesson 0006Context: PostgreSQL current

The node line

Seq Scan on t (cost=0.00..18.50 rows=5 width=36)

cost = startup..total, arbitrary units (seq page = 1.0); includes children. For comparing plans, not seconds.

rows = estimated rows emitted (after filter), not scanned.

width = est. bytes/row. Read the tree bottom-up.

EXPLAIN vs EXPLAIN ANALYZE

Plain EXPLAIN: estimates only, doesn't run.

EXPLAIN ANALYZE: executes the query; shows actual time, actual rows, loops next to estimates.

DML danger: EXPLAIN ANALYZE UPDATE… really updates. Use BEGIN; … ; ROLLBACK;.

The #1 skill

Check estimated rows vs actual rows. Big gap → planner flew blind → bad join/scan choices cascade upward.

Usual fix: estimates come from stats gathered by ANALYZE (autovacuum runs it too). Stale stats → ANALYZE thetable;.

BUFFERS (implicit with ANALYZE)

Buffers: shared hit=36 read=6

hit = from cache (fast). read = from disk (slow — the number that hurts on a cold cache).

Scan nodes (from the storage arc)

Seq Scan — whole heap (fine for a big fraction of rows).

Index Scan — index → heap fetch (two-step, 0003).

Index Only Scan — skips heap if all-visible; watch Heap Fetches:.

Bitmap Heap Scan — index → bitmap → heap in physical order (many scattered matches).

Postgres vs MySQL

AspectMySQLPostgres
Shaperow per tablenode tree
Costrows×filteredpage-fetch units
Cache viewBUFFERS
Top checkrows vs actualest vs actual rows