QamoosTech
DatabasesPerformanceIntermediate

Composite Index

PronunciationKOM-po-zit IN-deks

Definition

A composite index is a database index created on two or more columns of a table. It allows the database to efficiently search for rows based on combinations of those columns.

Where you hear it

Database performance tuning sessions, schema design reviews, and when optimizing slow SQL queries.

Examples

  • We added a composite index on (last_name, first_name) to speed up our user search feature.
  • The query is slow because it filters by category and created_at without a matching composite index.
  • The composite index on the customer and date columns speeds up the monthly report.

Common mistake

Assuming that a composite index on (A, B) automatically speeds up queries that only filter by column B alone; it usually only works if the query includes the leftmost column A.

Don't confuse with

A composite index is one index over several columns. Column order matters: it helps queries that filter on the first column, or on the first and second together, but not on the second column alone.

Say it at work

  • In a meeting or chatWe should consider adding a composite index on these two columns to reduce the query execution time.
  • In an email or ticketI have identified that the slow performance is due to a missing composite index on the filtering criteria.