Re: Select distinct sorting all rows 8.0rc1

From: "Guy Rouillier" <guyr(at)masergy(dot)com>
To: "PostgreSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Select distinct sorting all rows 8.0rc1
Date: 2004-12-06 02:21:16
Message-ID: CC1CF380F4D70844B01D45982E671B2348E46B@mtxexch01.add0.masergy.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Pierre-Frédéric Caillaud wrote:
> The planner is smarter with GROUP BY than with DISTINCT, so you can
> rewrite your query as the following, whihc will probaly use a
> HashAggregate, and be a lot faster :
>
> SELECT service_id FROM five_min_stats_200408 GROUP BY service_id;

Pierre-Frédéric, thanks! Vast improvement - this is definitely acceptable. It did indeed use a seq scan followed by a hash aggregate.

Total runtime: 76295.775 ms

>> estat=> explain analyze select distinct(service_id) from
>> five_min_stats_200408; QUERY PLAN
>> ------------------------------------------------------------------------
>> ------------------------------------------------------------------------
>>
>> Time: 1284213.359 ms

--
Guy Rouillier

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2004-12-06 04:21:13 Re: source control integration
Previous Message Joeseph P. Blow 2004-12-06 01:59:32 Re: 3rd RFD: comp.databases.postgresql (was: comp.databases.postgresql.*)