The Runtime Theory

Index Lookup Path: B-Tree Descent to Heap Fetch

Trace a point lookup from query to index selection, B-tree descent to the leaf, and the heap fetch that retrieves the actual row version from the table.

The Runtime Theory Team08 stages

trace / request.md

PREDICATE ARRIVESPLANNER PICKSTHE INDEXDESCENDTHE B-TREELEAF PAGEHOLDS THE KEYENTRY YIELDSA ROW POINTERHEAP PAGEIS FETCHEDTUPLE VERSIONIS CHECKEDROW STREAMSTO THE CLIENT

readyA predicate such as WHERE id = 42 arrives. The planner checks which indexes exist on the table and estimates how selective each access path would be for this predicate.

An index lookup is two random reads wearing a fancy coat. The first is the B-tree descent: a series of page reads, one per tree level, each deciding which child pointer to follow by comparing the key. That's the part everyone draws. The second read is the heap fetch — following the row pointer stored in the leaf to the table page itself — and it's the one everyone forgets. This diagram shows both, plus the two ways the second read disappears: a covering index makes the leaf entry sufficient, and a miss on the leaf means no heap access at all.

The order matters because each stage decides whether the next happens. The planner's selectivity estimate decides whether the index is used; the descent decides which leaf is read; the leaf decides whether the heap is touched. Index design is really about making stage six unnecessary as often as possible.