Junior — Middle
When performing a range query in a database, which index type is preferable: hash index or B-tree?
sobes.tech AI
Answer from AI
For range queries in a database, it is preferable to use a B-tree index.
Why:
- B-trees support ordered data, which allows efficient range searches (e.g.,
BETWEEN,>,<). - Hash indexes are suitable for exact key lookups but do not support range searches, as hashing does not preserve order.
Therefore, if you need to find records within a certain range of values, a B-tree will be more efficient and appropriate.