Suggest an editImprove this articleRefine the answer for “What is a composite index?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)A composite index is an index built **on several columns at once**: it helps speed up queries that filter or sort **by a combination of those fields**, e.g. `CREATE INDEX idx_users_city_age ON users(city, age)`. **Key point:** the leftmost prefix rule applies - the index gets used when a query filters on the first field (`city`) or on the first and second together (`city`, `age`), but **not** on just the second field (`age`) alone if the first isn't used.Shown above the full answer for quick recall.Answer (EN)ImageA composite index is an index built **on several columns at once**. It helps speed up queries that filter or sort **by a combination of those fields**. ### Example ```sql CREATE INDEX idx_users_city_age ON users(city, age); ``` Such an index is useful for queries like: ```sql SELECT * FROM users WHERE city = 'Kyiv' AND age > 25; ``` ### How it works - The index stores rows **sorted first by** `city`**, then by** `age`. - The database can quickly find every user from `Kyiv`, then quickly filter them by age. ### The order rule (leftmost prefix rule) This index gets used when the query involves: - only the first field (`city`), - or the first plus the second (`city`, `age`), but **not** just the second field (`age`) alone, if the first (`city`) isn't used. ### Where it applies Composite indexes are especially effective when: - `WHERE` filters often cover several columns; - queries sort or group by several fields (`ORDER BY city, age`). **Summary:** A composite index is an ordered "multi-level table of contents" that speeds up searches on a combination of fields, but is sensitive to their order.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.