X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id ECF779FB326 for ; Thu, 17 Aug 2006 23:21:37 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 04518-03 for ; Thu, 17 Aug 2006 23:21:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.envysolutions.com (mark.mielke.cc [206.248.142.186]) by postgresql.org (Postfix) with ESMTP id C1C2A9FB231 for ; Thu, 17 Aug 2006 23:21:33 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.envysolutions.com (Postfix) with ESMTP id CD98B540BC; Thu, 17 Aug 2006 22:21:31 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.envysolutions.com Received: from mail.envysolutions.com ([127.0.0.1]) by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1r2qq65LLU9m; Thu, 17 Aug 2006 22:21:31 -0400 (EDT) Received: by mail.envysolutions.com (Postfix, from userid 500) id 95D39540BF; Thu, 17 Aug 2006 22:21:31 -0400 (EDT) Date: Thu, 17 Aug 2006 22:21:31 -0400 From: mark@mark.mielke.cc To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: Q: Performance of join vs embedded query for simple queries? Message-ID: <20060818022131.GA15599@mark.mielke.cc> References: <20060818003326.GA11682@mark.mielke.cc> <1484.1155864093@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1484.1155864093@sss.pgh.pa.us> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.18 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, NO_REAL_NAME, SPF_HELO_PASS, SPF_PASS X-Spam-Level: * X-Archive-Number: 200608/294 X-Sequence-Number: 20479 On Thu, Aug 17, 2006 at 09:21:33PM -0400, Tom Lane wrote: > mark@mark.mielke.cc writes: > > I have two simple queries that do what I believe to be the exact same > > thing. > These are actually not equivalent per spec. > ... > This still isn't equivalent to the join: it'll return at most one copy > of any sm_change row, whereas you can get multiple copies of the same > sm_change row from the join, if there were multiple matching sm_system > rows. (Hm, given the unique index on (system_dbid, uid), I guess that > couldn't actually happen --- but you have to reason about it knowing > that that index is there, it's not obvious from the form of the query.) > Anyway: given the way that the planner works, the IN form and the join > form will probably take comparable amounts of time to plan. The "= > subselect" form is much more constrained in terms of the number of > alternative implementations we have, so it doesn't surprise me that it > takes less time to plan. That makes sense. Would it be reasonable for the planner to eliminate plan considerations based on the existence of unique indexes, or is this a fundamentally difficult thing to get right in the general case? I did the elimination in my head, which is why I considered the plans to be the same. Can the planner do it? Sub-millisecond planning/execution for simple queries on moderate hardware seems sexy... :-) Thanks, mark -- mark@mielke.cc / markm@ncf.ca / markm@nortel.com __________________________ . . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder |\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | | | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada One ring to rule them all, one ring to find them, one ring to bring them all and in the darkness bind them... http://mark.mielke.cc/