Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id E609F650748 for ; Tue, 2 Sep 2008 13:52:15 -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 32792-01-2 for ; Tue, 2 Sep 2008 13:51:55 -0300 (ADT) X-Greylist: delayed 00:07:39.143025 by SQLgrey-1.7.6 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by postgresql.org (Postfix) with ESMTP id 6553465074E for ; Tue, 2 Sep 2008 13:11:00 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id c7so413132nfi.23 for ; Tue, 02 Sep 2008 09:10:58 -0700 (PDT) Received: by 10.210.82.2 with SMTP id f2mr8473453ebb.159.1220371399265; Tue, 02 Sep 2008 09:03:19 -0700 (PDT) Received: from oxford.xeocode.com.enterprisedb.com ( [82.16.16.210]) by mx.google.com with ESMTPS id g11sm16209274gve.8.2008.09.02.09.03.17 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 02 Sep 2008 09:03:18 -0700 (PDT) To: Tom Lane Cc: Simon Riggs , Heikki Linnakangas , List pgsql-patches Subject: Re: WIP Join Removal In-Reply-To: <14377.1220369736@sss.pgh.pa.us> (Tom Lane's message of "Tue\, 02 Sep 2008 11\:35\:36 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+imap.gmail.com:PG" 919) References: <1220176372.4371.118.camel@ebony.2ndQuadrant> <48BC4127.30706@enterprisedb.com> <1220348487.4371.307.camel@ebony.2ndQuadrant> <14377.1220369736@sss.pgh.pa.us> From: Gregory Stark Organization: EnterpriseDB Date: Tue, 02 Sep 2008 17:03:15 +0100 Message-ID: <87k5dusfgc.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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/24 X-Sequence-Number: 7039 Tom Lane writes: > Simon Riggs writes: >> On Mon, 2008-09-01 at 22:23 +0300, Heikki Linnakangas wrote: >>> Did plan invalidation make it safe to rely on the presence of a unique >>> index for planning decisions? > >> My understanding was "Yes" and this case was the specific reason I >> originally wanted to pursue plan invalidation back in 2006. It may be worth considering what other cases might need this info and taking them into account to be sure the solution is usable for them too. I suspect we'll probably need a generic function for determining whether a PathKey list can be proved unique. Other cases off the top of three other cases where this could be useful -- but generally anywhere the planner introduces a Unique node could benefit from looking at this. a) Turn a UNION into UNION ALL if there are unique indexes for any column in each side and at least one column is a constant in each side and none of the constants are equal. b) Remove the aggregate on IN subqueries when there's a unique constraint so that: SELECT * from a where a.fk IN (select pk FROM b) Can do a semijoin without taking care to avoid duplicating records in "a" if there should be duplicate values of "pk" in "b". c) Turn bad mysqlish queries which are really semijoins (used to work around their historic lack of subqueries) such as: SELECT DISTINCT a.pk FROM a JOIN b USING (x) into SELECT a.pk FROM a WHERE x IN (SELECT x FROM b) -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's 24x7 Postgres support!