Sobes.tech
Junior — Middle

How is a composite index formed in a database management system?

sobes.tech AI

Answer from AI

A composite index in a DBMS is formed from multiple table columns combined into a single index. This allows faster queries that filter or sort data based on multiple fields simultaneously.

For example, in MySQL, a composite index can be created as follows:

CREATE INDEX idx_name ON table_name (column1, column2);

The order of columns is important: the index is effective for queries that use the first columns in the same order. For instance, an index on (column1, column2) will help with filtering by column1 or by column1 and column2, but not by column2 alone.

A composite index stores the values of all specified columns together, which speeds up search and sorting on them.