← Concepts
Data·3 min read

Database Indexes

Pre-computed lookup structures that turn O(n) table scans into O(log n) or O(1) lookups.

First time reading this? Start here

Plain English: a database index is like the index at the back of a book. Without it, finding a topic means flipping through every page. With it, you jump straight to the right page. Same idea, applied to rows.

Used in:URL ShortenerSearch EngineYelp
What it is

An auxiliary data structure that maps column values to row locations. The most common type is a B-tree (or B+-tree): sorted, balanced, range-query-friendly. LSM-trees are the alternative used by write-heavy stores (Cassandra, RocksDB).

The problem it solves

Without an index, finding a row by some column means scanning every row, an O(n) operation. On a table with billions of rows, that's intolerable. An index turns that into a fast lookup.

How it works

B-tree: sorted by indexed column; lookups walk the tree (log n). Updates are in-place but require rebalancing. LSM-tree: writes go to a memory buffer, periodically flushed to immutable sorted files; reads check multiple files and a Bloom filter to skip ones that don't have the key. Writes are much faster (append-only) but reads are amortized.

Why use it
What it costs you
Where it shows up in our architectures
Gotchas

Your notes

Private to you