Datahash tablehash functionload factorrehashing

Hash index

Definition

A hash index applies a hash function to each key to pick a bucket that stores the key and its location, so an equality lookup costs O(1) on average.

In practice

Hashing skips the search entirely, which makes hash indexes ideal for exact-match lookups at very high rates: in-memory key-value stores, join hash tables, and log-structured stores like Bitcask. Collisions are normal and resolved by chaining or probing; keeping the load factor (entries per bucket) bounded keeps lookups short.

Hashing destroys key order, so range queries, sorting and prefix matches cannot use the index. When the table grows past its load factor it must be resized and every key rehashed; doing that all at once causes a pause, which is why stores such as Redis rehash incrementally. For general database use, a B-tree is usually the better default.

Example

A store with 10 million keys and 16 million buckets has a load factor of about 0.6; GET user:42 hashes the key and reads one bucket, while user:40 to user:50 would need a full scan.