Plan nodes · Set operations and appends

Merge Append

Merges several sorted inputs into one sorted output.

Like Append, but each child is sorted and the output keeps that order, so ORDER BY … LIMIT over a UNION ALL or a partitioned table can stop early without sorting everything.

Example

(SELECT * FROM tracks WHERE genre = 'jazz' ORDER BY ms) UNION ALL (SELECT * FROM tracks WHERE genre = 'rock' ORDER BY ms) ORDER BY ms LIMIT 10

8 nodes

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

Related

Append · Recursive Union · SetOp