Skip to main content
Module 10 · Lesson 3 of 439/57 in the course~15 min
Module lessons (3/4)

Composite and Partial Indexes

Lesson preview5 hands-on exercises readySQL Course · Module 10 — Optimization and 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 % in LIKE) 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

  1. 11. Mental Model: Left Prefix Rule & Partial Indexes
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Lab: Why (country, city) Fails on WHERE city = ...
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 10 — Optimization and Indexes

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.