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

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