Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D71AA64FD0D for ; Tue, 2 Sep 2008 08:31:09 -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 91579-04 for ; Tue, 2 Sep 2008 08:31:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail137140.authsmtp.com (outmail137140.authsmtp.com [62.13.137.140]) by postgresql.org (Postfix) with ESMTP id ABA1764FCDA for ; Tue, 2 Sep 2008 08:31:02 -0300 (ADT) Received: from mail-c187.authsmtp.com (mail-c187.authsmtp.com [62.13.128.33]) by punt6.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m82BURDG011182; Tue, 2 Sep 2008 12:30:27 +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 m82BUQx9041254; Tue, 2 Sep 2008 12:30:27 +0100 (BST) Subject: Re: WIP Join Removal From: Simon Riggs To: Heikki Linnakangas Cc: List pgsql-patches In-Reply-To: <1220348487.4371.307.camel@ebony.2ndQuadrant> References: <1220176372.4371.118.camel@ebony.2ndQuadrant> <48BC4127.30706@enterprisedb.com> <1220348487.4371.307.camel@ebony.2ndQuadrant> Content-Type: text/plain Date: Tue, 02 Sep 2008 12:38:18 +0100 Message-Id: <1220355498.4371.372.camel@ebony.2ndQuadrant> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: 8a9f4446-78e2-11dd-8155-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaAdbflxB HGQLW1xEUV97WmN/ aQ0fZQBDYEtPQQdo WVZARU1QEQdtHhxP WxYcIHwTPwxGfH9y YEIsXHBcWgpyJE8r RkpQE3ABbTJidWEe BBRFfwJRdR5Kfh5E YlUrV3QKMjRJBC9q VzwLFgwaHRhkHWxq YzlFD1UTRw4xEzs7 WRkGdXVz X-Authentic-SMTP: 61633235383639.squirrel.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/14 X-Sequence-Number: 7029 On Tue, 2008-09-02 at 10:41 +0100, Simon Riggs wrote: > On Mon, 2008-09-01 at 22:23 +0300, Heikki Linnakangas wrote: > > Couldn't we also do join removal for inner joins, when there's a foreign > > key reference that enforces that there's one and only one matching tuple > > in the removed table: > > > > SELECT child.data FROM child, parent WHERE child.fkey = parent.pkey > > Hmm, I had thought this was the same case, but the inner join > possibility wasn't something I'd seen. Guess that flaw shows this is all > original thought - I'll go back and read that optimizer blog again... > > I agree it will work. > > We would need to replace the join condition with an alteration of the > original quals on child so that we add "AND child.fkey is not null". > Which would mean we would need to re-plan the access to that base > relation so we picked up the new qual and potentially used an index for > it as well. That would be possible only if the join condition exactly > matches the FK constraint. Also, note that when we do an inner join we must not have any qualification of the rows on the checkrel. Any qualification that removes rows will alter the answer. This is a direct contrast to the left outer join case where the presence or absence of a single table qualification on the checkrel has *no effect* on the results of the query (as long as the qual is immutable). -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support