Skip site navigation (1) Skip section navigation (2)

Re: WIP Join Removal

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: List pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: WIP Join Removal
Date: 2008-09-02 10:41:52
Message-ID: 1220352112.4371.349.camel@ebony.2ndQuadrant (view raw or flat)
Thread:
Lists: pgsql-patches
On Tue, 2008-09-02 at 13:20 +0300, Heikki Linnakangas wrote:
> Simon Riggs wrote:
> > It turns out that a join like this
> > 
> > select a.col2
> > from a left outer join b on a.col1 = b.col1
> > where b.col2 = 1;
> > 
> > can be cheaper if we don't remove the join, when there is an index on
> > a.col1 and b.col2, because the presence of b allows the values returned
> > from b to be used for an index scan on a.
> 
> Umm, you *can't* remove that join. 

Yes, you can. The presence or absence of rows in b is not important to
the result of the query because of the "left outer join".

I spent nearly a whole day going down that deadend also.

> Because of the condition "b.col2 = 
> 1", which implies that "b.col1 IS NOT NULL", 

No it doesn't, but as above, it is irrelevant anyway.

> that's actually equal to:

> select a.col2
> from a inner join b on a.col1 = b.col1
> where b.col2 = 1;

-- 
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support


In response to

Responses

pgsql-patches by date

Next:From: Simon RiggsDate: 2008-09-02 10:54:58
Subject: Re: WIP Join Removal
Previous:From: Heikki LinnakangasDate: 2008-09-02 10:41:22
Subject: Re: WIP Join Removal

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group