Build fluency in the vocabulary of a wide, balanced tree locating a row in only a handful of reads.
0 / 5 completed
1 / 5
At standup, a dev mentions a database index built as a wide, shallow, always-balanced tree, where each node holds many sorted keys and child pointers, so a lookup reaches any row in only a handful of disk reads. What is this structure called?
A B-tree index is exactly this wide, shallow, always-balanced tree, where each node holds many sorted keys and pointers to children, so even a huge table can be searched in only a handful of node reads because the tree's height grows so slowly as rows are added. A hash collision is an unrelated hash-table concept about two keys sharing a bucket, not about a sorted, balanced tree. This shallow, wide shape is exactly why a B-tree index is the default choice for range queries and equality lookups in most relational databases.
2 / 5
During a design review, the team confirms the B-tree index stays perfectly balanced after every insert and delete, by splitting a full node or merging an under-full one rather than letting one branch grow far deeper than another. Which capability does this self-balancing provide?
This self-balancing provides predictable lookup time that doesn't degrade as rows are added over years, since splitting a full node or merging an under-full one keeps every path from root to leaf close to the same length, so the tree's height grows only slowly even as the table grows enormously. An unbalanced tree left to grow deep down one branch would let some lookups take far longer than others as that branch keeps extending. This automatic split-and-merge balancing is exactly what a B-tree index guarantees on every write, not just at creation time.
3 / 5
In a code review, a dev notices a query filters on a column that has no B-tree index at all, forcing the database to scan every single row in the table to find matches. What does this represent?
This is a full table scan, which a B-tree index on the filtered column would let the database avoid entirely, since the index lets it walk directly down to the matching rows in a handful of reads instead of examining every row one by one. A cache eviction policy is an unrelated concept about discarding cached entries. This full-scan cost is exactly why an unindexed filter column is one of the first things a query-performance review looks for, especially as a table's row count grows.
4 / 5
An incident report shows a report query that used to run in milliseconds started taking several seconds once the table grew past a few million rows, because the column it filtered on had no B-tree index and the database was forced into a full table scan on every run. What practice would prevent this?
Adding a B-tree index on the filtered column lets the database jump directly to the matching rows in a handful of reads instead of scanning every row in the table, which is exactly the fix for the slowdown described in this incident. Continuing to run the query against the unindexed column is exactly what let the full table scan get slower and slower as the table grew past a few million rows. This is a standard, low-risk fix, though it does add a small ongoing cost to every insert and update, since the index itself has to be kept up to date.
5 / 5
During a PR review, a teammate asks why the team is selective about which columns get a B-tree index instead of just indexing every column in every table to make every possible query fast. What is the reasoning?
Every additional index adds real overhead to every insert, update, and delete against that table, since the database has to keep each index's own balanced tree in sync with the underlying rows on every write, not just build it once. Indexing every column trades away that write performance for read speed on queries that may never actually filter or sort on most of those columns, often for no real benefit. The tradeoff is precisely why indexing decisions are usually driven by actual query patterns, adding a B-tree index only where a real, frequent query needs it rather than indexing indiscriminately.