Indexes & Query Performance

B-Tree Indexes

A B-tree keeps sorted separator keys in a shallow, balanced page hierarchy. Navigation finds a leaf boundary; linked or successive leaves support ranges and order, while splits, occupancy, concurrency, and row fetches shape real cost.
  • Fan-out keeps trees shallow.
  • Leaves hold the searchable order.
  • Balanced means bounded path length, not constant I/O.
  • Splits preserve order under growth.
  • B-trees can satisfy ordering.
  • Wide or random keys change economics.
Seek, range scan, and split
Seek to a boundary, then walk the range
CREATE INDEX orders_placed_idx ON orders (placed_at);

SELECT order_id, placed_at
FROM orders
WHERE placed_at >= TIMESTAMP '2026-05-01 00:00:00'
  AND placed_at <  TIMESTAMP '2026-06-01 00:00:00'
ORDER BY placed_at;
Physical stages
StageMechanicCost drivers
Root/internal descentCompare separator keys and choose childHeight, cache, key width
Leaf positioningBinary/search-method lookup within pagePage format and compression
Range advanceConsume ordered leaf entriesMatching entries and leaf pages
Row retrievalFollow locator unless coveredClustering, visibility, random access
Insert/splitPlace key; redistribute if fullFree space, key pattern, contention, logging