pg.ddx.io  pgsql-patches@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Simon Riggs <simon@2ndQuadrant.com>
To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Cc: List pgsql-patches <pgsql-patches@postgresql.org>
Subject: Re: WIP Join Removal
Date: Tue, 02 Sep 2008 13:33:34 +0100
Message-ID: <1220358814.4371.406.camel@ebony.2ndQuadrant> (raw)
In-Reply-To: <48BD2189.40400@enterprisedb.com>
References: <1220176372.4371.118.camel@ebony.2ndQuadrant>
	<48BC4127.30706@enterprisedb.com>
	<1220348487.4371.307.camel@ebony.2ndQuadrant>
	<48BD1374.4030504@enterprisedb.com>
	<1220352112.4371.349.camel@ebony.2ndQuadrant>
	<48BD1852.1070904@enterprisedb.com>
	<1220352898.4371.355.camel@ebony.2ndQuadrant>
	<48BD1D7C.6090002@enterprisedb.com>
	<1220354413.4371.365.camel@ebony.2ndQuadrant>
	<48BD2189.40400@enterprisedb.com>


On Tue, 2008-09-02 at 14:20 +0300, Heikki Linnakangas wrote:
> Simon Riggs wrote:
> > select a.col2
> > from a left outer join b on a.col1 = b.col1
> > where b.col2 = 1;
> > 
> > is logically equivalent to 
> > 
> > select a.col2
> > from a;
> 
> No, it's not:
> 
> postgres=# CREATE TABLE a (col1 int4, col2 int4);
> CREATE TABLE
> postgres=# CREATE TABLE b (col1 int4, col2 int4);
> CREATE TABLE
> postgres=# INSERT INTO a VALUES (1,1);
> INSERT 0 1
> postgres=# select a.col2 from a;
>   col2
> ------
>      1
> (1 row)
> 
> postgres=# select a.col2 from a left outer join b on a.col1 = b.col1 
> where b.col2 = 1;
>   col2
> ------
> (0 rows)

You raise an interesting and important point that shows an error of
mine. Notice that

 select a.col2 from a left outer join b on a.col1 = b.col1 
 *and* b.col2 = 1;

can be re-written as

 select a.col2 from a;

whereas

 select a.col2 from a left outer join b on a.col1 = b.col1 
 where b.col2 = 1;

cannot, as you show.

It seems I wrote my original tests using "and" instead of "where" and
hadn't noticed the distinction. Thanks for helping me catch that error.

I will put back the code that looks for an empty filter condition on the
checkrel. That day was not wasted after all.

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




view thread (26+ messages)  latest in thread

Message-ID: <1220358814.4371.406.camel@ebony.2ndQuadrant>
Permalink:  ../1220358814.4371.406.camel@ebony.2ndQuadrant/
Also on:    postgresql.org/message-id/1220358814.4371.406.camel@ebony.2ndQuadrant

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-patches@postgresql.org
  Cc: simon@2ndQuadrant.com, heikki.linnakangas@enterprisedb.com
  Subject: Re: WIP Join Removal
  In-Reply-To: <1220358814.4371.406.camel@ebony.2ndQuadrant>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox