Skip site navigation (1) Skip section navigation (2)

Re: distinct vs group by

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: distinct vs group by
Date: 2005-01-29 22:14:07
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com> writes:
> Should the expressions
>   select distinct x from t
> and 
>   select          x from t group by x
> have the same effect?  

Offhand I think they are theoretically equivalent.

> It seems the optimizer sometimes chooses different plans for those
> expressions.   Could the select distinct have used the slightly
> faster hash aggregate?

This is partly historical (the DISTINCT code hasn't been rewritten in a
long time) and partly intentional --- you can choose one phrasing or the
other to control what plan you get.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Tom LaneDate: 2005-01-29 22:16:48
Subject: Re: Postgres database access problem
Previous:From: Dmitry KonnovDate: 2005-01-29 11:06:44
Subject: History question. Please name all clones of PostGre

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group