View Single Post

   
  #3 (permalink)  
Old 04-15-2008, 10:53 PM
=?UTF-8?Q?Filip_Rembia=C5=82kowski?=
 
Posts: n/a
Default Re: left outer join vs subplan

2007/9/6, Simon Riggs <simon@2ndquadrant.com>:

> The query formulation does seem a fairly common one.
>
> > First query:
> > explain analyze
> > select *
> > from
> > a
> > left outer join (
> > select b.id, sum(b.val)
> > from b
> > group by b.id
> > ) bagg
> > on bagg.id = a.id
> > where
> > a.id > 10000
> > order by a.addon, a.id
> > limit 100;


>
> The value of sum(b.val) is never used in the query, so the aggregate
> itself could be discarded. I suspect there are other conditions you
> aren't showing us that would make this impossible?


The value of sum(b.val) is being output in the "select *", so saying
it's never used is an oversimplification. But it's actually not used
in any join, or filter. That should be enough to optimize...

>
> The aggregate prevents the condition bagg.id = a.id from being pushed
> down so that we know b.id = a.id. If we knew that then we could use b.id
> = ? as an index condition to retrieve the rows.


That's exactly the point... But if we all can see it, maybe it's
possible to code it?


Cheers,
Filip RembiaƂkowski

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Reply With Quote