Junior — Middle
Explain the concept of a composite index and its application in databases.
sobes.tech AI
Answer from AI
A composite index is an index in a database that is created on multiple columns of a table simultaneously. It helps to speed up search and sorting based on the combination of these fields. For example, if queries frequently filter by two columns, creating a composite index on them will improve performance.
Application:
- Accelerating complex queries with multiple conditions.
- Optimizing JOIN operations on multiple keys.
It is important to remember that the order of columns in a composite index affects its efficiency: the index is most effective when queries filter by the first columns of the index.
Example in SQL:
CREATE INDEX idx_name ON table_name (column1, column2);