Learn VisualLearn DB Visual
JA

Order Keys by the Queries They Serve

A multicolumn B-tree (for example, (status, ordered_at)) orders entries by the leading column status, then by ordered_at within each status value. Filtering on status with equality, such as status = 'paid', narrows the search to one contiguous range in the index, while filtering on ordered_at alone leaves matching values scattered across the whole index, widening the search. Later columns can still help in some cases, so treat this as a matter of efficiency rather than a strict usable-or-not rule.

What should determine multicolumn index order?