Databases · interactive
Composite indexes and column order
An index on (country, city, age) is sorted by country, then city within each country, then age. Like a phone book sorted by surname then first name: great for some questions, useless for others.
SELECT * FROM users WHERE country = 'PK' AND city = 'Lahore'
INDEX ON users (country, city, age)
- DEBerlin29
- DEBerlin41
- DEMunich35
- PKKarachi22
- PKKarachi38
- PKLahore19match
- PKLahore27match
- PKLahore33match
- PKLahore45match
- UKLeeds31
- UKLondon26
- UKLondon52
index columns used: country, city · entries read 4 · matches 4
Equality on the leading column(s): one seek to a contiguous slice of the index.
WHERE
Step 2 of 4 · read left to right
In production
Tools and technologies
Column order in an index decides which queries it helps.
Not tied to one language — use these names when you search docs or design a system.