Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 8E5FA64FFF4 for ; Tue, 2 Sep 2008 10:41:33 -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 28896-01 for ; Tue, 2 Sep 2008 10:41:24 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail129143.authsmtp.com (outmail129143.authsmtp.com [62.13.129.143]) by postgresql.org (Postfix) with ESMTP id 8975964FCF5 for ; Tue, 2 Sep 2008 10:41:27 -0300 (ADT) Received: from mail-c187.authsmtp.com (mail-c187.authsmtp.com [62.13.128.33]) by punt2.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m82DerfB014371; Tue, 2 Sep 2008 14:40:53 +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 m82Deqv5096406; Tue, 2 Sep 2008 14:40:52 +0100 (BST) Subject: Re: WIP Join Removal From: Simon Riggs To: Gregory Stark Cc: Heikki Linnakangas , List pgsql-patches In-Reply-To: <87od36u7st.fsf@oxford.xeocode.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> <87od36u7st.fsf@oxford.xeocode.com> Content-Type: text/plain Date: Tue, 02 Sep 2008 14:48:44 +0100 Message-Id: <1220363324.4371.421.camel@ebony.2ndQuadrant> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: c2f2ee67-78f4-11dd-8155-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadRtFaAdbflxB HGQLW1xEUVl7XWN/ bggfZQBDYEtPQQdo WVZARU1QEQdtHhxP WxYcJkwzMQBGcXh0 ZUAsXHJSVAopdxB/ FxtSEnABbTFkdWEe BBRFfwJRdR5Kfh5E YlUrV3QKMjRJBC9q VzASB3gTOjRZYB5Y RwYTJFZ6 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/17 X-Sequence-Number: 7032 On Tue, 2008-09-02 at 12:05 +0100, Gregory Stark wrote: > I wonder if it would be more worthwhile to remove them and have a subsequent > phase where we look for possible joins to *add*. So even if the user writes > "select * from invoices where customer_id=?" the planner might be able to > discover that it can find those records quicker by scanning customer, finding > the matching and then using an index to look them up > in invoices. This seems a less useful idea now just simply because it is such a special case. We would need to have a case where we have a table A that does not have an index on a specific column, yet table B does have an index on the specific column. But also when A references B as a foreign key and where the column is a subset of the columns of the primary key of B. That means only queries like select ... from a where a.col2 = x; can be transformed into select ... from a join b on (foreign key cols) where a.col2 = x; and then because a.col2 is a subset of foreign key columns we can infer that b.col2 = x. So the pre-conditions for this to be useful are: * constraint on subset of a FK * subset of FK is indexed on B * subset of FK is not indexed on A Which doesn't seem that likely to occur. Thanks both to Heikki and Greg for good, fast input on this patch. Nothing more needed now while I rework patch. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support