Middle
What are indexes in databases, what types are there, and which have you worked with?
sobes.tech AI
Answer from AI
Indexes in databases are data structures that speed up searching and data retrieval based on certain columns.
Main types of indexes:
- B-Tree index — the most common, suitable for equality and range queries.
- Hash index — fast for exact matches, but does not support range queries.
- Bitmap index — effective for columns with a small number of unique values.
- Full-text index — for text search.
- Composite index — an index on multiple columns.
In my experience with Go and SQL, I have worked with B-Tree indexes to speed up key-based retrievals and composite indexes for complex filters. For example, in PostgreSQL, I created an index:
CREATE INDEX idx_user_lastname_firstname ON users(lastname, firstname);
This speeds up queries filtering by last name and first name simultaneously.