B-Tree Index
ELI5 — The Vibe Check
A B-Tree index is the default index type that most databases create when you say CREATE INDEX. It organizes data in a balanced tree structure so the database can find any value in logarithmic time. It's like a phone book - sorted so you can quickly jump to the right section instead of reading every page.
Real Talk
A B-Tree (Balanced Tree) index is the most common index structure in relational databases. It maintains sorted data in a balanced tree with logarithmic lookup, insert, and delete operations. B-Trees support equality and range queries, ordering, and are the default index type in PostgreSQL, MySQL, and most RDBMS.
Show Me The Code
-- Default index type (B-Tree)
CREATE INDEX idx_email ON users(email);
-- Equivalent explicit syntax
CREATE INDEX idx_email ON users USING btree(email);
-- Supports range queries efficiently
SELECT * FROM orders WHERE created_at BETWEEN '2024-01-01' AND '2024-12-31';
When You'll Hear This
"B-Tree indexes are your bread and butter for most queries." / "If you're doing equality or range lookups, a B-Tree index is almost always the right choice."
Related Terms
Composite Index
A composite index indexes multiple columns together, like a phone book sorted by last name AND first name. The order matters a lot.
Covering Index
A covering index includes all the columns your query needs, so the database never has to look at the actual table.
GIN Index
A GIN index is like a book's index on steroids. Instead of pointing to one location per entry, each entry can point to thousands of locations.
Partial Index
A partial index only indexes the rows you actually care about. Why index 10 million archived orders when you only ever query the active ones?