↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Plan Nodes

Incremental Sort

Extends an existing ordering by sorting groups that share the presorted key prefix.

Reading PG 18·Select a recorded version

Core node tag
T_IncrementalSort
Structured EXPLAIN Node Type
Incremental Sort
Inputs
One partly ordered child plan
Output
Tuples ordered by the full sort key
Executor initializer
ExecInitIncrementalSort
Memory mechanism
tuplesort
evidence kind
source and documentation
explain names
Incremental Sort
explain prefixes
Parallel, Async
node tag
T_IncrementalSort
parallel callbacks
ExecIncrementalSortEstimate, ExecIncrementalSortInitializeDSM, ExecIncrementalSortInitializeWorker, ExecIncrementalSortRetrieveInstrumentation
partial modes
Unknown
runtime verified
false
strategies
Unknown

Definition PG 18

Extends an existing ordering by sorting groups that share the presorted key prefix.

EXPLAIN labels in this source build

Text-format labelStructured node identity
Incremental SortIncremental Sort

Compare versions

Complete source facts

memory

{"description":"The node passes work_mem to tuplesort. Sorting can use memory or temporary files; the actual method and space use depend on the input and plan.","evidence":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeIncrementalSort.c","path":"src/backend/executor/nodeIncrementalSort.c","sha256":"9fd15ce79cd3dd5c131c5bfb322039213cba9232fdfaa5b53e5f40e7d17195cf","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/utils/sort/tuplesort.c","path":"src/backend/utils/sort/tuplesort.c","sha256":"509d4cef598613bbf0725f697e1e1e33f3dfc8debed20169a6c4bf1ac9e5c2e3","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"mechanism":"tuplesort","source_notes":["Incremental sort may be more efficient than plain sort, particularly on large datasets, as it reduces the amount of data to sort at once, making it more likely it fits into work_mem (eliminating the need to spill to disk). But the main advantage of incremental sort is that it can start producing rows early, before sorting the whole dataset, which is a significant benefit especially for queries with LIMIT.","Because incremental sort processes (potentially many) sort batches, we need to capture tuplesort stats each time we finalize a sort state. This summary data is later used for EXPLAIN ANALYZE output."]}

source inventory

{"executor":"src/backend/executor/execProcnode.c","explain":"src/backend/commands/explain.c","implementation":"src/backend/executor/nodeIncrementalSort.c"}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

Text language: en · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f