Sobes.tech
Middle

Mis on indeksid andmebaasides, millised tüübid on ja millistega olete töötanud?

sobes.tech AI

Vastus AI-lt

Database indexes are data structures that speed up searching and retrieving data in specific 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 — efficient for columns with a small number of unique values.
  • Full-text index — for searching within text.
  • Composite index — on multiple columns.

In my experience with Go and SQL, I have worked with B-Tree indexes to accelerate key-based lookups and with 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.