Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 6BDD39FB558 for ; Tue, 10 Jul 2007 22:25:09 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 16646-09 for ; Tue, 10 Jul 2007 22:25:00 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id B20419FB52A for ; Tue, 10 Jul 2007 22:25:05 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l6B1P3ss013643; Tue, 10 Jul 2007 21:25:03 -0400 (EDT) To: Craig James cc: pgsql-performance@postgresql.org Subject: Re: Equivalent queries produce different plans In-reply-to: <469429FD.6080504@emolecules.com> References: <46898AB3.7090409@emolecules.com> <87hcom5p41.fsf@oxford.xeocode.com> <469429FD.6080504@emolecules.com> Comments: In-reply-to Craig James message dated "Tue, 10 Jul 2007 17:53:17 -0700" Date: Tue, 10 Jul 2007 21:25:03 -0400 Message-ID: <13642.1184117103@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/79 X-Sequence-Number: 25763 Craig James writes: > The two queries below produce different plans. > select r.version_id, r.row_num, m.molkeys from my_rownum r > join my_molkeys m on (r.version_id = m.version_id) > where r.version_id >= 3200000 > and r.version_id < 3300000 > order by r.version_id; > select r.version_id, r.row_num, m.molkeys from my_rownum r > join my_molkeys m on (r.version_id = m.version_id) > where r.version_id >= 3200000 > and r.version_id < 3300000 > and m.version_id >= 3200000 > and m.version_id < 3300000 > order by r.version_id; Yeah, the planner does not make any attempt to infer implied inequalities, so it will not generate the last two clauses for you. There is machinery in there to infer implied *equalities*, which is cheaper (fewer operators to consider) and much more useful across typical queries such as multiway joins on the same keys. I'm pretty dubious that it'd be worth the cycles to search for implied inequalities. regards, tom lane