Why is my query slow? An indexing story
summary
Postgres-focused, hands-on guide to why a million-row table suddenly runs in 27 ms and then 0.2 ms after adding the right multi-column B-tree index, or why a sequential scan drops from 33 ms to 11.8 ms with a selective index. Covers creating indexes concurrently, reading planner output with EXPLAIN ANALYZE, using index only scan and partial index to avoid heap fetches, warns of write slowdowns, operator/function pitfalls, selectivity/cardinality thresholds and the rule of thumb that more than five indexes looks smelly.
AI-written summary · about
chapters (20)
- 0:00Introduction to indexing
- 1:25Project and table overview
- 2:46Sequential scan explained
- 3:49What is a database index
- 5:58When to create indexes
- 7:22Trade-offs of indexing
- 8:25Knowing your queries
- 9:27Creating indexes safely
- 10:08Debugging with EXPLAIN
- 13:16Multi-column indexes
- 15:45Selectivity and cardinality
- 17:30Indexing strategy
- 19:17Range queries and order
- 21:05Covering indexes
- 23:11Sorting and index order
- 25:21Partial indexes
- 27:49Function-based indexes
- 29:54Why indexes aren't used
- 31:57Further learning resources
- 33:22Key takeaways and closing
