Re: DISTINCT vs. GROUP BY - Mailing list pgsql-hackers

From Tom Lane
Subject Re: DISTINCT vs. GROUP BY
Date
Msg-id 29125.1127159447@sss.pgh.pa.us
Whole thread Raw
In response to Re: DISTINCT vs. GROUP BY  (Greg Stark <gsstark@mit.edu>)
Responses Re: DISTINCT vs. GROUP BY
List pgsql-hackers
Greg Stark <gsstark@mit.edu> writes:
> DISTINCT is really just special a case of GROUP BY. Even DISTINCT ON is just
> GROUP BY with a kind of "first()" aggregate function. What would be really
> neat would be to teach GROUP BY about first() and last() and how it can skip
> over some index entries and still satisfy the query. Then make DISTINCT and
> DISTINCT ON be handled through the exact same code path.

You've missed the point entirely.

first() is not a substitute for sorting the input; it is only useful
if the input comes pre-sorted.  And if you are going to sort the input,
you might as well use the current implementation of DISTINCT ON and
skip the effort and memory-overflow-risk associated with a hashtable.

I do think hash aggregation is a plausible alternative implementation of
plain DISTINCT, but I don't see the case for using it for DISTINCT ON.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Patrick Welche
Date:
Subject: Re: postmaster core dump
Next
From: Tom Lane
Date:
Subject: Re: postmaster core dump