From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dimi Paun <dimi@lattica.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: DISTINCT vs. GROUP BY
Date: Tue, 09 Feb 2010 17:38:21 -0500
Message-ID: <25105.1265755101@sss.pgh.pa.us> (raw)
In-Reply-To: <1265751976.2513.34.camel@localhost>
References: <1265751976.2513.34.camel@localhost>
Dimi Paun <dimi@lattica.com> writes:
>> From what I've read on the net, these should be very similar,
> and should generate equivalent plans, in such cases:
> SELECT DISTINCT x FROM mytable
> SELECT x FROM mytable GROUP BY x
> However, in my case (postgresql-server-8.1.18-2.el5_4.1),
> they generated different results with quite different
> execution times (73ms vs 40ms for DISTINCT and GROUP BY
> respectively):
The results certainly ought to be the same (although perhaps not with
the same ordering) --- if they aren't, please provide a reproducible
test case.
As for efficiency, though, 8.1 didn't understand how to use hash
aggregation for DISTINCT. Less-obsolete versions do know how to do
that.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, dimi@lattica.com
Subject: Re: DISTINCT vs. GROUP BY
In-Reply-To: <25105.1265755101@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox