Buckets Not Trees
A hash index applies a hash function to the indexed key and stores the entry in the resulting bucket. To look up a value, it hashes the search key and goes straight to that bucket. There is no tree to descend, so an equality match is roughly constant time.
Where It Wins
- Equality lookups like find the row whose key equals a value are very fast.
- For pure point lookups, a hash index can be smaller and quicker than a B tree, since it stores no sorted structure.
What It Gives Up
The price is that hashing destroys order:
- No range queries: values near each other land in unrelated buckets, so between and greater than cannot be served.
- No sorting or prefix matching: the index cannot return rows in order or seek a prefix.
- Collisions must be handled, and a poor hash or many duplicate keys can degrade buckets into longer chains.
Because B trees handle equality well and also do ranges, hash indexes are a niche tool for workloads that are purely equality based.
Key idea
A hash index hashes keys into buckets for fast constant time equality lookups, but it cannot do ranges, ordering, or prefix matching, so it suits purely equality based workloads.