Re: Re-Reason of Slowness of Query - Mailing list pgsql-performance

From tv@fuzzy.cz
Subject Re: Re-Reason of Slowness of Query
Date
Msg-id 557a8c61e87e5e54ae205daadd8f0ca4.squirrel@sq.gransy.com
Whole thread Raw
In response to Re: Re-Reason of Slowness of Query  (Shaun Thomas <sthomas@peak6.com>)
Responses Re: Re-Reason of Slowness of Query
Re: Re-Reason of Slowness of Query
List pgsql-performance
> On 03/23/2011 04:17 AM, Adarsh Sharma wrote:
>
>> explain analyze select distinct(p.crawled_page_id) from page_content
>> p where NOT EXISTS (select 1 from clause2 c where c.source_id =
>> p.crawled_page_id);
>
> You know... I'm surprised nobody has mentioned this, but DISTINCT is
> very slow unless you have a fairly recent version of Postgres that
> replaces it with something faster. Try this:

Nobody mentioned that because the explain plan already uses hash aggregate
(instead of the old sort)

 HashAggregate  (cost=100278.16..104104.75 rows=382659 width=8) (actual
time=7047.259..7050.261 rows=72 loops=1)

which means this is at least 8.4. Plus the 'distinct' step uses less than
1% of total time, so even if you improve it the impact will be minimal.

regards
Tomas


pgsql-performance by date:

Previous
From: Uwe Bartels
Date:
Subject: Re: buffercache/bgwriter
Next
From: Shaun Thomas
Date:
Subject: Re: Re-Reason of Slowness of Query