Re: PSQL 8.4 - partittions - join tables - not optimal plan

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: PSQL 8.4 - partittions - join tables - not optimal plan
Date: 2009-09-11 05:33:08
Message-ID: 20090911053308.GA2300@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Jason Tesser 2009-09-11 15:46:10 View vs Stored Proc Performance
Previous Message bricklen 2009-09-10 18:02:48 Re: Sub-optimal plan chosen