Indexing & Query Optimization
Read execution plans, design indexes and rewrite queries so database workloads meet latency targets without wasting write throughput or storage.
4 objectives 6 steps about 145 min
Learn it step by step
Read the lessons in order, try the practice checks, then prove the skill with the knowledge check.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Read EXPLAIN (ANALYZE, BUFFERS) output to identify scan and join methods, row-estimate errors and the most expensive plan node.
- Choose B-tree, composite, partial, covering or expression indexes (and recognize when GIN or BRIN fit, including GIN for full-text and trigram search) for a query pattern, accounting for write overhead.
- Rewrite queries to be index-friendly (sargable predicates, keyset pagination, set-based instead of row-by-row access) and keep planner statistics current.
- Find the most expensive statements with pg_stat_statements and verify an optimization with before-and-after measurements.
Lesson plan
6 steps, about 145 min · 5 of 5 lessons available so far
- How a B-Tree Index Finds Your Rows Concept · 20 min
- Reading an Execution Plan Node by Node Worked example · 30 min
- Lab: Designing Indexes for a Workload, Text Search Included Lab · 30 min
- Index-Friendly Rewrites and Fresh Statistics Lab · 25 min
- Finding the Queries That Actually Matter Lab · 20 min
- Check: Diagnose Three Slow Queries Knowledge check · 8 questions
Practise it
Generate a 10-million-row orders table, replay a provided query workload and use pg_stat_statements to find the three costliest queries; make each at least five times faster with indexes or rewrites, serve a ranked product-name search from a full-text or trigram GIN index, and submit before-and-after EXPLAIN ANALYZE output plus the insert-throughput cost of every index you added.
Build it from scratch
Practice builds that exercise this skill by re-creating a real technology.
- Build your own DatabaseAdvanced · 30–60 h
References
Hard prerequisites
Unlocks
Nothing depends on this skill yet.
On these roadmaps
Progress and evidence for this skill are shared across all of them.