Junior — Middle
Kas saaksite selgitada, mis on koostatud indeks ja millised on selle omadused andmebaasides?
sobes.tech AI
Vastus AI-lt
A composite index is an index in a database that is created based on multiple columns (fields) of a table. It allows for faster search and sorting based on the combination of these fields.
Features of a composite index:
- The index stores the values of multiple columns together, which is useful for queries that filter on multiple fields simultaneously.
- The order of columns in the index is important: the index is used effectively if queries filter on the first columns of the index.
- A composite index can replace several individual indexes, saving space and improving performance in complex queries.
Example of creating a composite index in SQL:
CREATE INDEX idx_name ON table_name (column1, column2);
This index will be useful for queries with conditions on column1 and column2, for example:
SELECT * FROM table_name WHERE column1 = 'value' AND column2 = 'value2';