Sobes.tech
Junior — Middle

What types of indexes have you used in your SQL queries to optimize data search?

sobes.tech AI

Answer from AI

In SQL, the following types of indexes are commonly used to optimize data search:

  • B-Tree index — the most common type, suitable for quick searches, sorting, and range queries.
  • Hash index — effective for exact key lookups but does not support range queries.
  • Unique index — ensures the uniqueness of values in a column, while also speeding up searches.
  • Composite index — built on multiple columns, useful for queries filtering by several fields.
  • Full-text index — used for fast searching within text data.

Example of creating a composite index:

CREATE INDEX idx_user_lastname_firstname ON users (lastname, firstname);

The choice of index type depends on the nature of the queries and the data structure.