Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id CB9859FA304 for ; Thu, 8 Feb 2007 23:50:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 41607-08 for ; Thu, 8 Feb 2007 23:50:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id E00949FA1D6 for ; Thu, 8 Feb 2007 23:50:08 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l193o5el014274; Thu, 8 Feb 2007 22:50:05 -0500 (EST) To: Alvaro Herrera cc: George Pavlov , pgsql-sql@postgresql.org Subject: Re: huge disparities in =/IN/BETWEEN performance In-reply-to: <20070209021414.GU24069@alvh.no-ip.org> References: <8C5B026B51B6854CBE88121DBF097A86815F42@ehost010-33.exch010.intermedia.net> <7377.1170986068@sss.pgh.pa.us> <8C5B026B51B6854CBE88121DBF097A86815F81@ehost010-33.exch010.intermedia.net> <20070209021414.GU24069@alvh.no-ip.org> Comments: In-reply-to Alvaro Herrera message dated "Thu, 08 Feb 2007 23:14:14 -0300" Date: Thu, 08 Feb 2007 22:50:05 -0500 Message-ID: <14273.1170993005@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/112 X-Sequence-Number: 27446 Alvaro Herrera writes: > I think the principle here is that the system is not gonna waste cycles > on dumb queries. Supposedly, morphing "foo BETWEEN 10 and 10" into > "foo=10" is not a trivial transformation, and it'd impose a planning > cost on all non-dumb BETWEEN queries. There's a datatype abstraction issue involved: what does it take to prove that "x >= 10 AND x <= 10" is equivalent to "x = 10"? This requires a nontrivial amount of knowledge about the operators involved. We could probably do it for operators appearing in a btree operator class, but as Alvaro says, it'd be cycles wasted for non-dumb queries. As for the IN case, I think we do simplify "x IN (one-expression)" to "x = one-expression", but "x IN (sub-select)" is a whole 'nother matter, especially when you're comparing it to a case where one-expression is a constant and so the planner can get good statistics about how many rows are likely to match. regards, tom lane