mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Support "x IS NOT NULL" clauses as indexscan conditions. This turns out
to be just a minor extension of the previous patch that made "x IS NULL" indexable, because we can treat the IS NOT NULL condition as if it were "x < NULL" or "x > NULL" (depending on the index's NULLS FIRST/LAST option), just like IS NULL is treated like "x = NULL". Aside from any possible usefulness in its own right, this is an important improvement for index-optimized MAX/MIN aggregates: it is now reliably possible to get a column's min or max value cheaply, even when there are a lot of nulls cluttering the interesting end of the index.
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.264 2009/12/29 20:11:45 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.265 2010/01/01 21:53:49 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -5614,7 +5614,7 @@ btcostestimate(PG_FUNCTION_ARGS)
|
||||
int indexcol;
|
||||
bool eqQualHere;
|
||||
bool found_saop;
|
||||
bool found_null_op;
|
||||
bool found_is_null_op;
|
||||
double num_sa_scans;
|
||||
ListCell *l;
|
||||
|
||||
@ -5639,7 +5639,7 @@ btcostestimate(PG_FUNCTION_ARGS)
|
||||
indexcol = 0;
|
||||
eqQualHere = false;
|
||||
found_saop = false;
|
||||
found_null_op = false;
|
||||
found_is_null_op = false;
|
||||
num_sa_scans = 1;
|
||||
foreach(l, indexQuals)
|
||||
{
|
||||
@ -5680,12 +5680,14 @@ btcostestimate(PG_FUNCTION_ARGS)
|
||||
{
|
||||
NullTest *nt = (NullTest *) clause;
|
||||
|
||||
Assert(nt->nulltesttype == IS_NULL);
|
||||
leftop = (Node *) nt->arg;
|
||||
rightop = NULL;
|
||||
clause_op = InvalidOid;
|
||||
found_null_op = true;
|
||||
is_null_op = true;
|
||||
if (nt->nulltesttype == IS_NULL)
|
||||
{
|
||||
found_is_null_op = true;
|
||||
is_null_op = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -5725,12 +5727,7 @@ btcostestimate(PG_FUNCTION_ARGS)
|
||||
}
|
||||
}
|
||||
/* check for equality operator */
|
||||
if (is_null_op)
|
||||
{
|
||||
/* IS NULL is like = for purposes of selectivity determination */
|
||||
eqQualHere = true;
|
||||
}
|
||||
else
|
||||
if (OidIsValid(clause_op))
|
||||
{
|
||||
op_strategy = get_op_opfamily_strategy(clause_op,
|
||||
index->opfamily[indexcol]);
|
||||
@ -5738,6 +5735,11 @@ btcostestimate(PG_FUNCTION_ARGS)
|
||||
if (op_strategy == BTEqualStrategyNumber)
|
||||
eqQualHere = true;
|
||||
}
|
||||
else if (is_null_op)
|
||||
{
|
||||
/* IS NULL is like = for purposes of selectivity determination */
|
||||
eqQualHere = true;
|
||||
}
|
||||
/* count up number of SA scans induced by indexBoundQuals only */
|
||||
if (IsA(clause, ScalarArrayOpExpr))
|
||||
{
|
||||
@ -5760,7 +5762,7 @@ btcostestimate(PG_FUNCTION_ARGS)
|
||||
indexcol == index->ncolumns - 1 &&
|
||||
eqQualHere &&
|
||||
!found_saop &&
|
||||
!found_null_op)
|
||||
!found_is_null_op)
|
||||
numIndexTuples = 1.0;
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user