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
- Limitrows 10 (estimated 10) cost 4174.79..4174.91 buffers: 1,912 hit
- Sortrows 5 (estimated 12,443) cost 2086.58..2117.68 buffers: 956 hitsort key
tracks.mssort top-N heapsort, memory- Bitmap Heap Scan on tracksrows 12,500 (estimated 12,443) cost 140.73..1240.26 buffers: 956 hitrecheck
(genre = 'jazz'::text)944 exact heap blocks- Bitmap Index Scan using tracks_genrerows 12,500 (estimated 12,443) cost 0..137.61 buffers: 12 hitindex condition
(genre = 'jazz'::text)1 index searches
- Sortrows 6 (estimated 12,460) cost 2088.2..2119.35 buffers: 956 hitsort key
tracks_1.mssort top-N heapsort, memory- Bitmap Heap Scan on tracks tracks_1rows 12,500 (estimated 12,460) cost 140.86..1240.61 buffers: 956 hitrecheck
(genre = 'rock'::text)944 exact heap blocks- Bitmap Index Scan using tracks_genrerows 12,500 (estimated 12,460) cost 0..137.74 buffers: 12 hitindex condition
(genre = 'rock'::text)1 index searches
Run with EXPLAIN (ANALYZE, BUFFERS, TIMING OFF, SUMMARY OFF) on the sample database, PostgreSQL 19.0. Open it in the EXPLAIN visualizer →