Re: PSQL 8.4 - partittions - join tables - not optimal plan - Mailing list pgsql-performance

From A. Kretschmer
Subject Re: PSQL 8.4 - partittions - join tables - not optimal plan
Date
Msg-id 20090911053308.GA2300@a-kretschmer.de
Whole thread Raw
In response to PSQL 8.4 - partittions - join tables - not optimal plan  (Vratislav Benes <benes@optisolutions.cz>)
List pgsql-performance
In response to Vratislav Benes :
> but when I try make a condition by join table, the query plan is not optimal:
>
>
> select period_id from periods where y=2009 and w=14;
>  period_id
> -----------
>        704
> (1 row)
>
>
> explain select sum(s_pcs),sum(s_val)
> from data d inner join periods p on d.period_id=p.period_id
> where p.y=2009 and p.w=14;

How about

select sum(s_pcs),sum(s_val)
from data d inner join periods p on d.period_id=p.period_id
where p.y=2009 and p.w=14
and p.period_id in (select period_id from periods where y=2009 and w=14);

Untested.


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)

pgsql-performance by date:

Previous
From: Eugene Morozov
Date:
Subject: Re: Forcing postgresql to use an index
Next
From: Jason Tesser
Date:
Subject: View vs Stored Proc Performance