Re: DISTINCT/Optimizer question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Beth Jen" <raelys(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: DISTINCT/Optimizer question
Date: 2006-07-14 02:53:21
Message-ID: 25726.1152845601@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Beth,

"Beth Jen" <raelys(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-07-14 03:24:15 Re: Three weeks left until feature freeze
Previous Message Kris Jurka 2006-07-14 02:06:23 include compile problems