Plan nodes · Grouping and sorting
Unique
Removes adjacent duplicates from sorted input.
Implements DISTINCT (and UNION without ALL, in some plans) on sorted input: it returns a row only when it differs from the previous one.
Example
SELECT DISTINCT album_id FROM tracks WHERE album_id < 50 ORDER BY album_id
2 nodes
- Uniquerows 49 (estimated 233) cost 0.29..8.97 buffers: 3 hit
- Index Only Scan using tracks_album on tracksrows 245 (estimated 234) cost 0.29..8.39 buffers: 3 hitindex condition
(album_id < 50)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 · WindowAgg · Limit