Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B856064FCDA for ; Tue, 2 Sep 2008 08:28:41 -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 87773-07 for ; Tue, 2 Sep 2008 08:28:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ey-out-2122.google.com (ey-out-2122.google.com [74.125.78.25]) by postgresql.org (Postfix) with ESMTP id 3F20864FCED for ; Tue, 2 Sep 2008 08:28:37 -0300 (ADT) Received: by ey-out-2122.google.com with SMTP id 6so895736eyi.61 for ; Tue, 02 Sep 2008 04:28:36 -0700 (PDT) Received: by 10.210.23.3 with SMTP id 3mr8169036ebw.41.1220354444799; Tue, 02 Sep 2008 04:20:44 -0700 (PDT) Received: from ?80.222.42.69? ( [80.222.42.69]) by mx.google.com with ESMTPS id k9sm39732692nfh.23.2008.09.02.04.20.43 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 02 Sep 2008 04:20:44 -0700 (PDT) Message-ID: <48BD2189.40400@enterprisedb.com> Date: Tue, 02 Sep 2008 14:20:41 +0300 Organization: EnterpriseDB User-Agent: Mozilla-Thunderbird 2.0.0.14 (X11/20080509) MIME-Version: 1.0 To: Simon Riggs CC: List pgsql-patches Subject: Re: WIP Join Removal 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> In-Reply-To: <1220354413.4371.365.camel@ebony.2ndQuadrant> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit From: Heikki Linnakangas 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/13 X-Sequence-Number: 7028 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) But anyway, Greg's example looks valid, and proves the point that removing a join isn't always a win. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com