What is an index, why does it speed up queries, and why do databases use B+trees?
Short answer
An index is an extra structure that keeps one or more columns' values pre-sorted, with pointers to the rows, so a lookup takes a few page reads instead of a full table scan. Databases use a B+tree because it is short and wide: a billion-row table needs only 3–4 levels.
3 points to say:
- Index = pre-sorted data + row pointers: a few page reads instead of a table scan.
- B+tree fan-out ~500, only 3–4 levels for a billion rows; linked leaves make range scans and sorting cheap.
- Indexes slow down writes; skip them for low-selectivity columns or small tables.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.