Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 884B89FB48B for ; Thu, 3 May 2007 08:46:39 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 57576-04 for ; Thu, 3 May 2007 08:46:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from oxford.xeocode.com (unknown [62.232.55.118]) by postgresql.org (Postfix) with ESMTP id D08C69FB310 for ; Thu, 3 May 2007 08:46:33 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.63) (envelope-from ) id 1HjZlX-0000vD-Q0; Thu, 03 May 2007 12:46:31 +0100 From: Gregory Stark To: "Brian Herlihy" Cc: "Postgresql Performance" Subject: Re: Join vs Subquery In-Reply-To: <243066.5712.qm@web52308.mail.re2.yahoo.com> (Brian Herlihy's message of "Wed, 2 May 2007 23:07:57 -0700 (PDT)") Organization: EnterpriseDB References: <243066.5712.qm@web52308.mail.re2.yahoo.com> X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.performance" 139) Date: Thu, 03 May 2007 12:46:31 +0100 Message-ID: <874pmu2kq0.fsf@oxford.xeocode.com> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/18 X-Sequence-Number: 24408 "Brian Herlihy" writes: > There is a unique index mapping domains to domain_ids. ... > The issue: the second query results in a lower cost estimate. I am wondering > why the second query plan was not chosen for the first query. Well the unique index you mentioned is critical to being able to conclude the queries are equivalent. Postgres in the past hasn't been able to use things like unique indexes to make planning decisions because it had no infrastructure to replan if you dropped the index. We do have such infrastructure now so it may be possible to add features like this in the future. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com