Plan nodes · Grouping and sorting
Group
Removes duplicate group keys from sorted input, without aggregates.
For GROUP BY with no aggregate functions: since its input is sorted on the group key, it returns one row each time the key changes.
Example
SELECT album_id FROM tracks WHERE album_id < 100 GROUP BY album_id
2 nodes
- Index Only Scan using tracks_album on tracksrows 495 (estimated 474) cost 0.29..12.59 buffers: 3 hitindex condition
(album_id < 100)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 · Unique · WindowAgg · Limit