Plan nodes · Grouping and sorting
WindowAgg
Computes window functions such as row_number() and sums OVER (…).
Reads input sorted by the PARTITION BY and ORDER BY of the window, and computes each window function for each row from the rows of its frame. Several windows with different orders need several WindowAgg nodes, each with a Sort below.
Example
SELECT name, row_number() OVER (PARTITION BY album_id ORDER BY ms) FROM tracks WHERE album_id < 10
4 nodes
- WindowAggrows 45 (estimated 43) cost 150.8..151.66 buffers: 47 hit
- Sortrows 45 (estimated 43) cost 150.8..150.91 buffers: 47 hitsort key
album_id, mssort quicksort, memory- Bitmap Heap Scan on tracksrows 45 (estimated 43) cost 4.63..149.63 buffers: 47 hitrecheck
(album_id < 10)45 exact heap blocks- Bitmap Index Scan using tracks_albumrows 45 (estimated 43) cost 0..4.62 buffers: 2 hitindex condition
(album_id < 10)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 →
Related
Sort · Incremental Sort · Aggregate · Group · Unique · Limit