X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 327C09DC80D for ; Wed, 15 Mar 2006 20:24:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02941-01 for ; Wed, 15 Mar 2006 20:24:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by postgresql.org (Postfix) with ESMTP id EEEB19DCCFC for ; Wed, 15 Mar 2006 20:24:44 -0400 (AST) Received: from [192.168.0.5] (unknown [84.12.26.47]) by smtp.nildram.co.uk (Postfix) with ESMTP id 5DE4F3360C4; Thu, 16 Mar 2006 00:24:47 +0000 (GMT) Subject: Re: BETWEEN optimizer problems with single-value From: Simon Riggs To: Tom Lane Cc: Kevin Grittner , pgsql-performance@postgresql.org, Andreas Kretschmer In-Reply-To: <1142467626.3859.207.camel@localhost.localdomain> References: <44180105.EE98.0025.0@wicourts.gov> <20060315181735.GA22240@KanotixBox> <44180D33.EE98.0025.0@wicourts.gov> <28798.1142450270@sss.pgh.pa.us> <1142467626.3859.207.camel@localhost.localdomain> Content-Type: text/plain Date: Thu, 16 Mar 2006 00:24:38 +0000 Message-Id: <1142468678.3859.221.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200603/227 X-Sequence-Number: 17664 On Thu, 2006-03-16 at 00:07 +0000, Simon Riggs wrote: > On Wed, 2006-03-15 at 14:17 -0500, Tom Lane wrote: > > > It looks to me like this is a matter of bad cost estimation, ie, it's > > thinking the other index is cheaper to use. Why that is is not clear. > > Can we see the pg_stats rows for ctofcNo and calDate? > > ISTM that when the BETWEEN constants match we end up in this part of > clauselist_selectivity()... (and now for the whole email...) /* * It's just roundoff error; use a small positive * value */ s2 = 1.0e-10; so that the planner underestimates the cost of using "Cal_CalDate" so that it ends up the same as "Cal_CtofcNo", and then we pick "Cal_CalDate" because it was created first. Using 1.0e-10 isn't very useful... the selectivity for a range should never be less than the selectivity for an equality, so we should simply put in a test against one of the pseudo constants and use that as the minimal value. That should lead to raising the apparent cost of Cal_CalDate so that Cal_CtofcNo can take precedence. Best Regards, Simon Riggs