Re: left outer join vs subplan - Mailing list pgsql-hackers

From Filip Rembiałkowski
Subject Re: left outer join vs subplan
Date
Msg-id 92869e660709070207l34ad59e9r577871d24a51b09d@mail.gmail.com
Whole thread Raw
In response to Re: left outer join vs subplan  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
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

pgsql-hackers by date:

Previous
From: "Heikki Linnakangas"
Date:
Subject: GIN readme is out of date
Next
From: Richard Huxton
Date:
Subject: Re: Installation problem and a question