Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A6CF364FD0D for ; Tue, 2 Sep 2008 09:26:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 46488-10 for ; Tue, 2 Sep 2008 09:25:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail137138.authsmtp.net (outmail137138.authsmtp.net [62.13.137.138]) by postgresql.org (Postfix) with ESMTP id E2CF264FCF5 for ; Tue, 2 Sep 2008 09:25:50 -0300 (ADT) Received: from punt7.authsmtp.com (punt7.authsmtp.com [62.13.128.13]) by punt6.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m82CPjPu059491 for ; Tue, 2 Sep 2008 13:25:45 +0100 (BST) Received: from mail-c189.authsmtp.com (mail-c189.authsmtp.com [62.13.128.71]) by punt7.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m82CPiRa007466; Tue, 2 Sep 2008 13:25:44 +0100 (BST) Received: from [192.168.0.2] (85-211-229-97.dyn.gotadsl.co.uk [85.211.229.97]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m82CPhDs001231; Tue, 2 Sep 2008 13:25:43 +0100 (BST) Subject: Re: WIP Join Removal From: Simon Riggs To: Heikki Linnakangas Cc: List pgsql-patches 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> Content-Type: text/plain Date: Tue, 02 Sep 2008 13:33:34 +0100 Message-Id: <1220358814.4371.406.camel@ebony.2ndQuadrant> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: 4354547a-78ea-11dd-bc7a-001f29070be2 X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaAdbflxB HGQLW1xEUV97W2Z/ bwkfZQBDYEtPQQdo WVZARU1QEQdtHhxP WxYcIXkqA0ZGeH9y ZkcsXHFSWwp+dkN5 R0pTRHABbTIxdWEe BBRFJVBTIR5Kfh4T aFl/U3NfNGdJBC9q VzASB3gTOjRZYB5Y RwYTJFZ6 X-Authentic-SMTP: 61633235383639.kestrel.dmpriest.net.uk:1186/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200809/16 X-Sequence-Number: 7031 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