Senior
What are indexes? What types are there?
sobes.tech AI
Answer from AI
Indexes are special data structures in a database that speed up the search and retrieval of data based on certain columns.
Main types of indexes:
- B-Tree index: the most common type, suitable for quick searches, sorting, and range queries.
- Hash index: effective for exact key searches but does not support range queries.
- Full-text index: used for text searches, for example, in documents.
- Composite key index: an index built on multiple columns.
- Unique index: guarantees the uniqueness of values in a column or set of columns.
Indexes reduce the time of executing SELECT queries but increase the time for insert, update, and delete operations, as the index needs to be maintained.
Example of creating an index in SQL:
CREATE INDEX idx_user_email ON Users (Email);
In C# when working with Entity Framework, indexes can be specified using Fluent API or attributes.