Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C3CE9632982 for ; Sun, 6 Jun 2010 12:36:14 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 99940-02 for ; Sun, 6 Jun 2010 15:36:07 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from frubble.xen.chris-lamb.co.uk (frubble.xen.chris-lamb.co.uk [89.16.166.12]) by mail.postgresql.org (Postfix) with ESMTP id 88B656328CC for ; Sun, 6 Jun 2010 12:36:07 -0300 (ADT) Received: from sam by frubble.xen.chris-lamb.co.uk with local (Exim 4.63) (envelope-from ) id 1OLHtM-0007wC-Vk for pgsql-general@postgresql.org; Sun, 06 Jun 2010 16:36:04 +0100 Date: Sun, 6 Jun 2010 16:36:04 +0100 From: Sam Mason To: pgsql-general@postgresql.org Subject: Re: [SQL] Difference between these two queries ? Message-ID: <20100606153604.GV20550@samason.me.uk> References: <8585BA53443004458E0BAA6134C5A7FB066731E7@EGEXCMB01.oww.root.lcl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8585BA53443004458E0BAA6134C5A7FB066731E7@EGEXCMB01.oww.root.lcl> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201006/278 X-Sequence-Number: 163815 On Sun, Jun 06, 2010 at 10:15:52AM -0500, Little, Douglas wrote: > They should generate equivalent results, > But the difference is the constraint on bu.bid=5. > In the 1st case it's being done after the join. > In the 2nd case it is being done before the join. In PG version 8.1 (?) and onwards, the query planner knows that they are equivalent and will choose from the same types of plans. I.e. it's just a syntax issue, do whichever you think is "prettier", the semantics are the same. -- Sam http://samason.me.uk/