Part 2 of 5 · 1 min read
An ordered structure built for range queries
Keys are kept in sorted order, so both exact matches and ranges are efficient.
Think of a phone book. Names are kept in strict alphabetical order, so finding one name, or every name between two letters, both work by flipping to roughly the right place.
In plain words: a B+-tree keeps its indexed values, called keys, in sorted order across its leaf nodes. This ordering means a B+-tree supports range queries efficiently, not just exact-match lookups: once the start of a range is found, the matching rows for the rest of the range are read by simply walking forward through the sorted leaves. A hash index, covered on the next page, cannot do this, since it has no concept of order.
A worked example. An index on orders.placed_on can answer both WHERE placed_on = '2026-01-01' and WHERE placed_on BETWEEN '2026-01-01' AND '2026-01-31' efficiently, because the dates are stored in sorted order.
The key lines.
CREATE INDEX idx_orders_date ON orders (placed_on);
SELECT * FROM orders WHERE placed_on BETWEEN '2026-01-01' AND '2026-01-31';
-- the index walks sorted leaves forward from the range's start
B+-tree
A B+-tree is a balanced, ordered tree index that keeps its keys sorted across leaf nodes, supporting both exact-match and range queries efficiently.
Example: a phone book's alphabetical ordering supports both "find this name" and "find every name from A to C," the same way a B+-tree supports both exact matches and ranges.