How would you choose a composite index for a filtered, ordered query?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
Start with the actual predicates, sort order, selected columns, and data distribution. For a query filtering customer_id by equality and ordering by created_at and id, an index beginning with customer_id followed by the ordering keys may help. Check the query plan and measured workload rather than relying only on a rule of thumb. Indexes consume storage and add write overhead. Range predicates, selectivity, collation, and database capabilities affect which columns can efficiently support filtering or ordering. Recheck plans after meaningful data growth.
Related Questions in SQL & Relational Databases
What are Clustered and Non-Clustered Indexes in SQL, and when should you use each?
Intermediate level • 388 views
Explain SQL ACID properties and the differences between READ COMMITTED and REPEATABLE READ isolation levels.
Intermediate level • 3 views
Explain Database Normalization from 1NF through BCNF with real-world anomaly examples.
Intermediate level • 3 views
What is Database Indexing, how does a B+ Tree index work, and when should you avoid creating indexes?
Intermediate level • 2 views
Explain Redis In-Memory Data Structures and Common Caching Patterns (Cache-Aside, Write-Through, Write-Behind).
Intermediate level • 2 views