B+ Tree vs Hash Index

Indexes are the fundamental unit of database performance. There are many index types, but the two most common are the B+ Tree (probably the most common) and the hash index.

Intro to each index type

B+ Tree index

A B+ Tree is a tree data structure with some interesting characteristics that make it great for fast lookups with relatively few disk IOs.

Here is a great tool for visualizing what a B+ Tree does!

Hash index

A hash index takes the key of the value you’re indexing and hashes it into buckets. In case you’re not aware, a hash function is something that takes an input, and produces a different, somewhat random, and hopefully unique, output.

When to use each type