Verified Jobs Live
SQL & Relational Databases Medium Level ~3 min read

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.
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.