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

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

Related

Sort · Aggregate · Group · Unique · WindowAgg · Limit