A composite index covers multiple columns. Column order matters.
CREATE INDEX idx ON orders (user_id, created_at)
This index helps:
WHERE user_id = X(uses first column)WHERE user_id = X AND created_at > Y(uses both)WHERE user_id = X ORDER BY created_at(uses both)
This index does NOT help:
WHERE created_at > Y(can't skip first column)
Leftmost prefix rule: Query must use columns from left to right. No skipping.
Choose column order by: most selective first, or match your most common query patterns.