DELAPARRA
Index
Color
NL
Category: SQL

composite index

Explained by Updated

What is composite index?

composite index: An index on multiple columns. Order matters — it can serve queries that use a leftmost prefix of the columns. A composite index covers several columns, such as (customer_id, created_at). The database sorts by the first column, then by the second within each value of the first. The order of columns is everything. This index helps a query that filters on customer_id, or on customer_id and created_at together. It does not help a query that only filters on created_at, just as a phone book sorted by surname does not help you find everyone named Jan.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about composite index

What should you keep in mind with composite index?

Put the column used for exact matches first and the range or sort column last. One well-chosen composite index can replace several single-column indexes and speed up common queries like "this customer's latest orders". Use EXPLAIN to check which index a query really uses.

What does an example of composite index look like?

CREATE INDEX idx_orders_user_date ON orders (user_id, created_at);

At a glance

CategorySQL
Explained by
Updated

More SQL terms

All terms starting with C

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.