Re: DISTINCT/Optimizer question - Mailing list pgsql-hackers

From Tom Lane
Subject Re: DISTINCT/Optimizer question
Date
Msg-id 25726.1152845601@sss.pgh.pa.us
Whole thread Raw
In response to DISTINCT/Optimizer question  ("Beth Jen" <raelys@gmail.com>)
Responses Re: DISTINCT/Optimizer question  (Gregory Stark <gsstark@mit.edu>)
List pgsql-hackers
Hi Beth,

"Beth Jen" <raelys@gmail.com> writes:
> Right now, the distinct clause adds its targets to the sort clause list when
> it is parsed.

Yeah, the DISTINCT/DISTINCT ON implementation is currently rather
tightly tied to sorting :-(.  This is ancient code and badly in need of
redesign, but it's not clear how to clean it up without breaking the
expected behavior of DISTINCT ON.  There may not be any alternative
except to divorce DISTINCT from DISTINCT ON and make them two separate
code paths, but that's hardly appealing.  On the other side of the coin,
there's the analogy to GROUP BY that Greg points out --- there's some
duplicated functionality there, but again it doesn't carry over to
DISTINCT ON, AFAICS.

It might work to have parse analysis not add the DISTINCT list to the
ORDER BY list, but instead store them as separate Query fields, and have
the planner add DISTINCT to ORDER BY if it decides to use sort-based
distinct-ing.  I'm not sure if there's any good way to merge all three
constructs (DISTINCT, DISTINCT ON, GROUP BY).
        regards, tom lane


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Three weeks left until feature freeze
Next
From: Tom Lane
Date:
Subject: Re: Three weeks left until feature freeze