Middle
Why are indexes needed in databases? What are the disadvantages? What data structure is used for a standard index?
sobes.tech AI
Answer from AI
Indexes in a database are needed to speed up search and data retrieval. They allow quick finding of records without scanning all rows of the table.
Disadvantages of indexes:
- They take up additional disk space.
- They slow down insert, update, and delete operations because the index needs to be updated.
The standard data structure for an index is a B-tree. It provides a balanced tree with fast search, insert, and delete operations in logarithmic time.
Example: if you have a users table with an email field, an index on email will allow you to quickly find a user by email without scanning the entire table.