Index
Composite index
Index built on two or more columns, useful for queries that filter or sort on the leading columns.
A composite index sorts rows first by its leading column, then by the next, and so on. A query can use the index whenever its WHERE clause uses an equality predicate on a contiguous prefix of the columns, and a range or sort on the next.
Order matters. An index on (user_id, created_at) accelerates WHERE user_id = ? ORDER BY created_at, but does little for WHERE created_at > ? alone — that query needs created_at to be the leading column.
Rule of thumb: lead with the column you always filter on (usually high-selectivity equality), then add columns used for ordering or further filtering. Watch out for overlap with single-column indexes — an index on (user_id, created_at) makes a separate index on user_id redundant.