Composite Indexes and Column Order
Pick the column order for composite indexes, understand the left-prefix rule, and design indexes that cover multiple queries.
What Is a Composite Index?
An index on more than one column. PostgreSQL B-trees can index up to 32 columns; in practice 2–4 is typical.
CREATE INDEX orders_user_created_idx ON orders(user_id, created_at DESC);Why Use Composite?
Two scenarios:
- The query filters on multiple columns at once
- The query filters on one column and sorts by another
All lessons in this course
- B-tree vs Hash vs GiST vs GIN Indexes
- Composite Indexes and Column Order
- Partial and Expression Indexes
- Index Maintenance and Bloat