B-tree internals, clustered vs non-clustered, and the cost every index adds to writes
Indexes are the primary performance lever available to engineers without changing application code. A missing index on a join column turns a millisecond lookup into a full table scan. But every index slows down writes — INSERT, UPDATE, DELETE must update every index on the table. Understanding B-tree internals explains both why indexes help reads and why they have write costs.
A B-tree index is a self-balancing sorted tree. Internal nodes store key ranges that guide traversal; leaf nodes store the actual keys and pointers to rows. Finding a value is O(log n) — typically 3–4 page reads even for tables with millions of rows (tree height stays shallow). A full table scan is O(n) pages — potentially thousands of reads.
A clustered index physically orders the table's rows by the index key — the leaf nodes ARE the rows. Every table can have only one. A non-clustered index stores key + pointer to the actual row; following the pointer is an extra random read.