From: | Simon Riggs <simon(at)2ndquadrant(dot)com> |
---|---|
To: | Richard Huxton <dev(at)archonet(dot)com> |
Cc: | "Ключников А(dot)С(dot)" <alexs(at)analytic(dot)mv(dot)ru>, pgsql-performance(at)postgresql(dot)org |
Subject: | Re: query from partitions |
Date: | 2005-12-13 22:48:02 |
Message-ID: | 1134514082.27873.116.camel@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Tue, 2005-12-13 at 15:59 +0000, Richard Huxton wrote:
> Ключников А.С. wrote:
> > And
> > select * from base
> > where id in (1,2) and datatime between '2005-05-15' and '2005-05-17';
> > 10 seconds
> >
> > select * from base
> > where id in (select id from device where id = 1 or id = 2) and
> > datatime between '2005-05-15' and '2005-05-17';
> > 10 minits
> >
> > Why?
>
> Run EXPLAIN ANALYSE on both queries to see how the plan has changed.
>
> My guess for why the plans are different is that in the first case your
> query ends up as ...where (id=1 or id=2)...
>
> In the second case, the planner doesn't know what it's going to get back
> from the subquery until it's executed it, so can't tell it just needs to
> scan base_1,base_2. Result: you'll scan all child tables of base.
>
> I think the planner will occasionally evaluate constants before
> planning, but I don't think it will ever execute a subquery and then
> re-plan the outer query based on those results. Of course, someone might
> pop up and tell me I'm wrong now...
Thats right. Partitioning doesn't work for joins in 8.1.
Best Regards, Simon Riggs
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2005-12-13 23:17:05 | Re: Table Partitions / Partial Indexes |
Previous Message | Tom Lane | 2005-12-13 17:58:22 | Re: Memory Leakage Problem |