Join
Merge Join
Join algorithm that consumes two sorted inputs in lockstep and emits matching rows.
A Merge Join requires both inputs to be sorted by the join keys. It walks the two streams together, advancing whichever side has the smaller key, emitting a row whenever the keys match.
It is efficient when the inputs are already sorted — for example, returned in order from an index — because the join itself is cheap. When the planner has to add an explicit Sort step, a Hash Join is often faster.
Merge Joins are most often picked for large pre-sorted inputs or queries against indexed range conditions. They preserve sort order, which can let the next operator skip a sort of its own.