Sweaty Imposter

Hash Index

TechniqueDatabase InternalsJuniorMidUpdated
Hash table over a column; O(1) average point lookup, but no order, so no range scans or ORDER BY.

When to Use Hash Index

Equality-only workloads on a single key, especially in memory. Redis hashes, Postgres USING HASH indexes, Memcached, and join hash tables in query execution.

In Practice

Postgres CREATE INDEX ... USING HASH (email) for WHERE email = ? only. A B-tree on the same column also costs O(log n) and adds range support, which is why hash indexes are rare in practice.

How Hash Index Comes Up in Interviews

Scenario

You need point lookups by email AND range queries by signup_date on the same table. Which index strategy?

Hash indexes give O(1) point lookups but cannot serve range scans or ORDER BY. B-trees handle both at O(log n), which is why they're the default in essentially every general-purpose RDBMS.

Bitmap indexes shine on low-cardinality columns in data warehouses, not on email. Composite B-trees follow the leftmost-prefix rule: (a, b) helps queries on a or (a, b), not on b alone.