Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 7EC7565007C for ; Tue, 2 Sep 2008 07:47:54 -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 51126-01 for ; Tue, 2 Sep 2008 07:47:46 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail137153.authsmtp.net (outmail137153.authsmtp.net [62.13.137.153]) by postgresql.org (Postfix) with ESMTP id 51320650000 for ; Tue, 2 Sep 2008 07:47:49 -0300 (ADT) Received: from mail-c188.authsmtp.com (mail-c188.authsmtp.com [62.13.128.25]) by punt6.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m82AlFbW084782; Tue, 2 Sep 2008 11:47:15 +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 m82Al7CT040696; Tue, 2 Sep 2008 11:47:07 +0100 (BST) Subject: Re: WIP Join Removal From: Simon Riggs To: Heikki Linnakangas Cc: List pgsql-patches In-Reply-To: <48BD1852.1070904@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> Content-Type: text/plain Date: Tue, 02 Sep 2008 11:54:58 +0100 Message-Id: <1220352898.4371.355.camel@ebony.2ndQuadrant> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: 7d07948f-78dc-11dd-aecc-001871e930f4 X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaAdbflxB HGQLW1xEUVx7XWR/ aw0fZQBDYEtPQQdo WVZARU1QEQdtHhxP WxYcI0V1BGFGfH52 bEAsX3lYWwp9IUZ6 S0pcQ3ABbTMzdWEe BBRFJlYHIx5Kfh5N bVEqXXANN2FJBC9q VzASB3gTOjRZYB5Y RwYTJFZ6 X-Authentic-SMTP: 61633235383639.cat.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/9 X-Sequence-Number: 7024 On Tue, 2008-09-02 at 13:41 +0300, Heikki Linnakangas wrote: > Simon Riggs wrote: > > 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. > > Oh. How does the query look like after removing the join, then? Same answer, just slower. Removing the join makes the access to a into a SeqScan, whereas it was a two-table index plan when both tables present. The two table plan is added by the immediately preceding call add_... - i.e. that plan is only added during join time not during planning of base relations. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support