Module lessons (3/4)
Composite and Partial Indexes
Design multi-column indexes (leftmost-prefix rule) and filtered partial indexes.
What you'll learn in this lesson
- Design composite indexes (
(colA, colB)) strictly respecting the leftmost prefix\* order. - Dramatically reduce size and cost by writing partial indices (
CREATE INDEX ... WHERE ...) on the hot subsets. - Avoid non-sargable conditions (functions applied to the column or leading
%inLIKE) that nullify the index.
Overview
Real queries almost always filter on multiple columns (country = 'Italia' AND city = 'Milano') or concern only a small active slice of the table (for example only orders still 'pending'). composite indices and partial indices solve both problems in a targeted way.
Test prefix ((A, B) without A), wildcard (%abc%) and func (LOWER(col)) in the simulation panel to observe exactly when the B-Tree stops and folds back into sequential scanning:
Sections covered in this lesson
- 11. Mental Model: Left Prefix Rule & Partial Indexes
- 22. Progressive & Annotated Examples
- 33. Interactive Lab: Why
(country, city)Fails onWHERE city = ... - 44. Diagnostic Verification (Quiz)
- 55. Progressive Practical Laboratory
Unlock "Composite and Partial Indexes" and the full SQL Course curriculum
Design multi-column indexes (leftmost-prefix rule) and filtered partial indexes.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in SQL Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.