mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
A little further tweaking of the range-query selectivity logic:
to avoid undue sensitivity to roundoff error, believe that a zero or slightly negative range estimate should represent a small positive selectivity, rather than falling back on a generic default estimate.
This commit is contained in:
parent
6d79d6027c
commit
7177bbac29
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.32 2000/03/23 00:58:36 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.33 2000/03/23 23:35:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -186,21 +186,33 @@ clauselist_selectivity(Query *root,
|
|||||||
/* Successfully matched a pair of range clauses */
|
/* Successfully matched a pair of range clauses */
|
||||||
Selectivity s2 = rqlist->hibound + rqlist->lobound - 1.0;
|
Selectivity s2 = rqlist->hibound + rqlist->lobound - 1.0;
|
||||||
|
|
||||||
if (s2 > 0.0)
|
/*
|
||||||
|
* A zero or slightly negative s2 should be converted into a
|
||||||
|
* small positive value; we probably are dealing with a very
|
||||||
|
* tight range and got a bogus result due to roundoff errors.
|
||||||
|
* However, if s2 is very negative, then we probably have
|
||||||
|
* default selectivity estimates on one or both sides of the
|
||||||
|
* range. In that case, insert a not-so-wildly-optimistic
|
||||||
|
* default estimate.
|
||||||
|
*/
|
||||||
|
if (s2 <= 0.0)
|
||||||
{
|
{
|
||||||
/* All our hard work has paid off! */
|
if (s2 < -0.01)
|
||||||
s1 *= s2;
|
{
|
||||||
|
/* No data available --- use a default estimate that
|
||||||
|
* is small, but not real small.
|
||||||
|
*/
|
||||||
|
s2 = 0.01;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* One or both is probably a default estimate,
|
/* It's just roundoff error; use a small positive value */
|
||||||
* so supply a default estimate for the selectivity
|
s2 = 1.0e-10;
|
||||||
* of the range query. We rather optimistically assume
|
|
||||||
* that the range is tight...
|
|
||||||
*/
|
|
||||||
s1 *= 0.01;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Merge in the selectivity of the pair of clauses */
|
||||||
|
s1 *= s2;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Only found one of a pair, merge it in generically */
|
/* Only found one of a pair, merge it in generically */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user