pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Simon Riggs <simon@2ndquadrant.com>
Cc: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: pgsql-performance@postgresql.org, Andreas Kretschmer <akretschmer@spamfence.net>
Subject: Re: BETWEEN optimizer problems with single-value
Date: Wed, 15 Mar 2006 21:05:24 -0500
Message-ID: <11428.1142474724@sss.pgh.pa.us> (raw)
In-Reply-To: <1142468678.3859.221.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>
	<1142468678.3859.221.camel@localhost.localdomain>

Simon Riggs <simon@2ndquadrant.com> writes:
>> ISTM that when the BETWEEN constants match we end up in this part of
>> clauselist_selectivity()...

Yeah, I think you are right.

> 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.

No, it doesn't end up the same --- but the difference is small enough to
be in the roundoff-error regime.  The real issue here is that we're
effectively assuming that one row will be fetched from the index in both
cases, and this is clearly not the case for the Cal_CalDate index.  So
we need a more accurate estimate for the boundary case.

> 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's easier said than done, because you'd first have to find the
appropriate equality operator to use (ie, one having semantics that
agree with the inequality operators).  Another point is that the above
statement is simply wrong, consider
	calDate BETWEEN '2006-03-15' AND '2006-03-14'
for which an estimate of zero really is correct.

Possibly we could drop this code's reliance on seeing
SCALARLTSEL/SCALARGTSEL as the estimators, and instead try to locate a
common btree opclass for the operators --- which would then let us
identify the right equality operator to use, and also let us distinguish
> from >= etc.  If we're trying to get the boundary cases right I
suspect we have to account for that.  I could see such an approach being
tremendously slow though :-(, because we'd go looking for btree
opclasses even for operators that have nothing to do with < or >.

			regards, tom lane



view thread (20+ messages)  latest in thread

Message-ID: <11428.1142474724@sss.pgh.pa.us>
Permalink:  ../11428.1142474724@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/11428.1142474724@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, simon@2ndquadrant.com, Kevin.Grittner@wicourts.gov, akretschmer@spamfence.net
  Subject: Re: BETWEEN optimizer problems with single-value
  In-Reply-To: <11428.1142474724@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox