Junior — Middle
What are the main advantages and disadvantages of using indexes in a database?
sobes.tech AI
Answer from AI
Indexes in a database significantly speed up search and data retrieval operations, as they allow quick access to the required records without scanning the entire table. Main advantages:
- Speeding up SELECT queries — especially when filtering and sorting.
- Improving the performance of JOIN operations.
- Ensuring data uniqueness (e.g., unique indexes).
Disadvantages:
- Additional disk space consumption for storing indexes.
- Slowing down insert, update, and delete operations, as indexes need to be updated.
- Complexity in choosing the right indexes — excessive indexing can degrade performance.
Example: if you have a user table with millions of records, an index on the email field will allow you to quickly find a user by email instead of scanning all records.