Plan nodes · Grouping and sorting

Sort

Sorts its input.

For ORDER BY, and to feed a Merge Join, a GroupAggregate or a Unique. In memory it uses quicksort, or a top-N heapsort when a LIMIT means only the first rows are needed; past work_mem it writes sorted runs to disk and merges them ("external merge").

What to look for

"external merge" with disk use is a sort that did not fit in work_mem.

Example

SELECT * FROM artists ORDER BY name

2 nodes

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

Related

Incremental Sort · Aggregate · Group · Unique · WindowAgg · Limit