Plan nodes · Joins

Merge Join

Joins two inputs sorted on the join key by walking them in step.

Reads both inputs in key order, advancing whichever is behind, like merging two sorted lists. Cheap when both sides come sorted already (from indexes), and it can return rows in that order. Needs a sortable equality condition.

Example

SELECT * FROM artists a JOIN albums b ON b.artist_id = a.id ORDER BY a.id

3 nodes

Run with EXPLAIN (ANALYZE, BUFFERS, TIMING OFF, SUMMARY OFF) on the sample database, PostgreSQL 19.0. Open it in the EXPLAIN visualizer →

Related

Nested Loop · Hash Join · Hash · Memoize · Materialize