Lab 03 — Composite Indexes
Source reference
This lab extends the composite-index and SARGability guidance in SQL/Query Optimization with PostgreSQL column-order and write-cost experiments.
Scenario
The Orders API filters by customer and status, orders by newest first, and returns 50 rows. A useful index must account for filtering, ordering, and the position of equality and range-like requirements.
Run the exercise
Investigate
- Record scan, sort, row, loop, and buffer evidence.
- Determine which predicates are equality conditions.
- Check whether PostgreSQL sorts explicitly or reads in the needed order.
- Compare candidate column orders using the leftmost-prefix rule.
- Consider write cost and redundant-index risk before proposing a change.
Diagnostic question
Which column order supports this exact filter-and-order pattern, and which parts of the plan should disappear or shrink if your hypothesis is correct?