Skip to content

Add lesson 30: Index types beyond B-tree#89

Merged
exekias merged 3 commits into
mainfrom
lesson/30-index-types
Jul 2, 2026
Merged

Add lesson 30: Index types beyond B-tree#89
exekias merged 3 commits into
mainfrom
lesson/30-index-types

Conversation

@exekias

@exekias exekias commented Jul 2, 2026

Copy link
Copy Markdown
Member

Adds the third lesson of Module 7: Performance & indexing — index types beyond B-tree (roadmap item 30-index-types).

What's in the lesson

Each with a when-to-use, a cost note, a CREATE INDEX, and a query it accelerates:

  • GIN — jsonb (@>, ?), arrays (@>, <@, &&), tsvector (@@)
  • GiST — ranges (&&), spatial, KNN (<->), exclusion constraints
  • BRIN — huge, naturally-ordered tables (e.g. append-only created_at)
  • Hash — equality only
  • PartialCREATE INDEX … WHERE …
  • Expression… (lower(email))
  • CoveringINCLUDE for Index-Only Scans
  • A closing "which index should I use?" guide

pg_trgm is mentioned only as an out-of-scope extension (the sandbox is core-only).

Seed

A docs table (~40k rows via generate_series) with jsonb, text[], a skewed status, mixed-case email, and time-ordered created_at so every index type is demonstrable; ends with ANALYZE.

Checks

One query-returns check (tags-gin-created): confirms the learner built the GIN index on tags by querying pg_indexes for a definition matching gin (tags — robust to the index name and ignoring the meta GIN. Verified on PG16 (0 before, 1 after).

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 1:30pm

…t scale

Grows docs from ~40k to ~5,000,000 rows (seed-once base branch). At that size the old demos regressed to Seq Scans, so distributions were fixed so each index genuinely wins: rare 'gin' tag / 'report' kind (~1%), a rare 'pinned' key for the GIN ? existence demo (the old 'priority' key was on every row -> always a Seq Scan), ~50k distinct emails and ~500k owners. Moved the hash demo to email (a truer wide-key example) so the covering index is the sole owner_id index and yields a real Index Only Scan. No VACUUM (the seed runs as one implicit transaction; high owner cardinality gives the Index Only Scan instead). All 7 demos verified on Postgres 16.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
query-returns check confirms the learner built the GIN index on tags via pg_indexes matching 'gin (tags' — robust to naming, ignores the meta GIN. Verified on PG16 (0 before, 1 after).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@exekias exekias merged commit 3a2f054 into main Jul 2, 2026
3 checks passed
@exekias exekias deleted the lesson/30-index-types branch July 2, 2026 13:30
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