Add lesson 28: Indexes basics#87
Merged
Merged
Conversation
Part of #6 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
43 tasks
Grows the events seed from ~50k to ~3,000,000 rows (30k distinct users) so an index's benefit is perceptible in real query time, and adds before/after EXPLAIN ANALYZE beats so learners see Execution Time drop from tens of ms to a fraction of one. Verified on Postgres 16: seq scan ~37ms -> index scan ~0.2ms; seed loads in ~2-3s. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Since the DB is seeded once into a base branch (learners get copy-on-write branches), the table can be much larger. Grows events from 3M to ~25,000,000 rows (250k users). Seq scan now ~370ms vs index ~0.3ms (~1000x) — the win is unmistakable on query time. Prose and seed comment updated; comment flags that CREATE INDEX writes per-learner so index size scales with the knob. Verified on Postgres 16. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
query-returns check confirms the learner created the user_id B-tree index by querying pg_indexes for a definition matching (user_id). Robust to index naming and ignores the composite (user_id, status). Verified on Postgres 16: 0 before, 1 after CREATE INDEX. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the first lesson of the new Module 7: Performance & indexing — indexes basics (roadmap item
28-indexes-basics).What's in the lesson
CREATE INDEX, with a light before/afterEXPLAIN(deep plan-reading is the next lesson)=, ranges,BETWEEN,IN,IS NULL, sorting, prefixLIKE)Seed
One
eventstable populated to ~50k rows viagenerate_series, with a skewedstatus(low-selectivity demo) and ~5k distinctuser_ids (high-selectivity demo), plusANALYZE. Thegenerate_seriesapproach keeps the seed file tiny.Checks
One
query-returnscheck (user-id-index-created): confirms the learner created theuser_idB-tree index by queryingpg_indexesfor a definition matching(user_id). It's robust to whatever the learner names the index and ignores the composite(user_id, status). Verified on Postgres 16 (0 beforeCREATE INDEX, 1 after).Notes
This PR also bootstraps
lessons/07-performance-and-indexing/module.yaml, byte-identical across the Module 7 lesson PRs so the shared folder merges cleanly.npm run lessons:validateandnext buildboth pass.Part of #6
🤖 Generated with Claude Code