0Pricing
SQL Academy · Lesson

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

  1. B-tree vs Hash vs GiST vs GIN Indexes
  2. Composite Indexes and Column Order
  3. Partial and Expression Indexes
  4. Index Maintenance and Bloat
← Back to SQL Academy