Junior
Tell me about indexes in databases — what are they for, what types are there?
sobes.tech AI
Answer from AI
Indexes in databases are needed to speed up search and data retrieval. They work like pointers, allowing quick access to the required records without scanning the entire table.
Main types of indexes:
- B-Tree index — the most common, suitable for equality and range searches.
- Hash index — effective for exact key lookups but does not support range queries.
- Unique index — guarantees the uniqueness of values in a column.
- Composite index — an index on multiple columns, useful for filtering by several fields.
- Full-text index — for fast text searches.
Example of creating an index in SQL:
CREATE INDEX idx_customer_name ON customers(name);
Indexes speed up queries but increase the time for inserting and updating data, so they should be used wisely.