Index multiple columns in query order.
Section: Create and use indexes
Create a composite index
sql
sql
CREATE INDEX idx_posts_user_created_at ON posts(user_id, created_at DESC);Explanation
Composite indexes work best when they match common WHERE and ORDER BY patterns.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Create and use indexes