Skip to content

Add lesson 29: Reading EXPLAIN#88

Merged
exekias merged 3 commits into
mainfrom
lesson/29-explain
Jul 2, 2026
Merged

Add lesson 29: Reading EXPLAIN#88
exekias merged 3 commits into
mainfrom
lesson/29-explain

Conversation

@exekias

@exekias exekias commented Jul 2, 2026

Copy link
Copy Markdown
Member

Adds the second lesson of Module 7: Performance & indexing — reading EXPLAIN (roadmap item 29-explain).

What's in the lesson

  • EXPLAIN (plan only) vs EXPLAIN ANALYZE (actually runs the query) — with a write-safety warning (BEGIN … ROLLBACK)
  • Reading the plan as a tree, innermost-first
  • The estimate line (cost=startup..total rows width) and, with ANALYZE, actual time/rows/loops
  • Estimate-vs-actual mismatch → stale stats → ANALYZE / autovacuum
  • Node vocabulary: Seq / Index / Index-Only / Bitmap scans, Sort, Hash / Merge Join, Nested Loop, aggregates, Limit
  • EXPLAIN (ANALYZE, BUFFERS), plus VERBOSE / SETTINGS / FORMAT JSON; planning vs execution time
  • A worked join example walked through the tree

Seed

Two related tables via generate_series (~4k customers, ~40k orders) with an index and ANALYZE. Illustrative plan output lives in fenced blocks (numbers vary per run); learners run the real EXPLAINs.

Checks

One query-returns check (status-index-created): a closing diagnose-fix capstone has the learner spot the status='cancelled' Seq Scan, add the orders(status) index, and watch the plan flip to a Bitmap Index Scan; the check confirms the index via pg_indexes (0 before, 1 after, verified on PG16). This also corrected an earlier line that wrongly claimed cancelled already used an index-style plan (no status index existed, so it was a Seq Scan).

Notes

Includes the byte-identical Module 7 module.yaml.

npm run lessons:validate and next build both pass.

Part of #6

🤖 Generated with Claude Code

Part of #6

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
learn-postgres Ready Ready Preview Jul 2, 2026 12:46pm

…isks

The first Run block had two count(*), and Markdown paired the asterisks as emphasis, so the shell received count() and Postgres rejected it (42809). Escaped both as count(\*) per the >=2-asterisks run-block rule; verified the rendered SQL now contains count(*).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
New 'Your turn': learner uses EXPLAIN to see status='cancelled' do a Seq Scan, adds the orders(status) index, and confirms the plan flips to a Bitmap Index Scan; a query-returns check on pg_indexes verifies the index (0 before, 1 after, verified on PG16). Also corrects the earlier section, which wrongly claimed 'cancelled' already used an index-style plan — without a status index it is a Seq Scan; reworded to compare row estimates and foreshadow the capstone.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@exekias exekias merged commit 82d7675 into main Jul 2, 2026
3 checks passed
@exekias exekias deleted the lesson/29-explain branch July 2, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant