Middle+
What are indexes in databases? What types of indexes are there?
sobes.tech AI
Answer from AI
Indexes in databases are special data structures that speed up the search and retrieval of data based on specific table columns. They work like pointers, allowing quick access to the needed records without scanning the entire table.
Main types of indexes:
- B-Tree index — the most common type, suitable for equality and range queries.
- Hash index — efficient for fast equality searches but does not support range queries.
- Bitmap index — used for columns with a small number of unique values, often in analytical databases.
- Full-text index — for text search.
- Spatial indexes — for geographic data.
In Go, indexes are not created directly, but when working with a database, it is important to understand what indexes exist to write optimal queries. For example, in SQL, you can create an index like this:
CREATE INDEX idx_user_email ON users(email);
This will speed up user searches by email.