Plan nodes · Grouping and sorting
Incremental Sort
Finishes sorting input that is already sorted on a prefix of the key.
When rows arrive sorted on the first key columns (from an index, say), only the rows within each group of equal prefixes need sorting. That needs little memory and can return the first rows early, which helps with LIMIT. Added in PostgreSQL 13.
Example
SELECT * FROM tracks ORDER BY ms, name LIMIT 10
3 nodes
- Limitrows 10 (estimated 10) cost 0.37..1.45 buffers: 13 hit
- Incremental Sortrows 10 (estimated 100,000) cost 0.37..10876.29 buffers: 13 hitsort key
ms, namealready sorted onms- Index Scan using tracks_ms on tracksrows 11 (estimated 100,000) cost 0.29..6376.29 buffers: 13 hit1 index searches
Run with EXPLAIN (ANALYZE, BUFFERS, TIMING OFF, SUMMARY OFF) on the sample database, PostgreSQL 19.0. Open it in the EXPLAIN visualizer →