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

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