Re: DISTINCT vs. GROUP BY

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Neil Conway <neilc(at)samurai(dot)com>, Hans-Jürgen Schönig <postgres(at)cybertec(dot)at>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: DISTINCT vs. GROUP BY
Date: 2005-09-20 02:16:36
Message-ID: 200509200216.j8K2Gar15108@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Added to TODO:

* Allow DISTINCT to use hashing like GROUP BY

---------------------------------------------------------------------------

Greg Stark wrote:
>
> Neil Conway <neilc(at)samurai(dot)com> writes:
>
> > On Mon, 2005-19-09 at 16:27 +0200, Hans-J?rgen Sch?nig wrote:
> > > I was wondering whether it is possible to teach the planner to handle
> > > DISTINCT in a more efficient way:
> > [...]
> > > Isn't it possible to perform the same operation using a
> > > HashAggregate?
> >
> > One problem is that DISTINCT ON is defined to return the first unique
> > row (according to the query's ORDER BY) for the set of DISTINCT ON
> > columns, which can't easily be done via hashing.
>
> Uhm. Sure it can.
>
>
> 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.
>
> For bonus points teach it that min() and max() can sometimes be treated the
> same way if the path is presenting records sorted on that column.
>
>
> --
> greg
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2005-09-20 02:40:57 Re: logging blemishes
Previous Message Alexander Kirpa 2005-09-20 02:11:31 Re: Spinlocks, yet again: analysis and proposed patches