Turning Learners Into Developers
Codekilla
CODEKILLA
Medium
SQL-O03sql

Choosing Composite Index Column Order

Problem

A frequent query is `WHERE country = ? AND city = ? AND signup_d >= ?`. Should you create the index as `(country, city, signup_d)` or `(signup_d, country, city)`? Explain.

Input
Conceptual.
Output
Explanation
Constraints
Sample input
Sample output
Equality predicates first, then range. `(country, city, signup_d)` because country and city are equalities and signup_d is a range.
Explanation
Indexes only use the leftmost equality columns; once a range is hit, deeper columns can't be index-seeked.
optimisationindexescomposite@LinkedIn
Visible test cases
in: explain
out: ok
Your solution — run it, use AI if stuck
sql