Teach eval_const_expressions to simplify BooleanTest nodes that have

constant input.  Seems worth doing because rule rewriter inserts
IS NOT TRUE tests into WHERE clauses.
This commit is contained in:
Tom Lane 2006-08-04 14:09:51 +00:00
parent 3ceaa97b3c
commit e2d34d75e7
1 changed files with 53 additions and 1 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.216 2006/08/02 01:59:46 joe Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.217 2006/08/04 14:09:51 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@ -2092,6 +2092,58 @@ eval_const_expressions_mutator(Node *node,
newfselect->resulttypmod = fselect->resulttypmod;
return (Node *) newfselect;
}
if (IsA(node, BooleanTest))
{
BooleanTest *btest = (BooleanTest *) node;
BooleanTest *newbtest;
Node *arg;
arg = eval_const_expressions_mutator((Node *) btest->arg,
context);
if (arg && IsA(arg, Const))
{
Const *carg = (Const *) arg;
bool result;
switch (btest->booltesttype)
{
case IS_TRUE:
result = (!carg->constisnull &&
DatumGetBool(carg->constvalue));
break;
case IS_NOT_TRUE:
result = (carg->constisnull ||
!DatumGetBool(carg->constvalue));
break;
case IS_FALSE:
result = (!carg->constisnull &&
!DatumGetBool(carg->constvalue));
break;
case IS_NOT_FALSE:
result = (carg->constisnull ||
DatumGetBool(carg->constvalue));
break;
case IS_UNKNOWN:
result = carg->constisnull;
break;
case IS_NOT_UNKNOWN:
result = !carg->constisnull;
break;
default:
elog(ERROR, "unrecognized booltesttype: %d",
(int) btest->booltesttype);
result = false; /* keep compiler quiet */
break;
}
return makeBoolConst(result, false);
}
newbtest = makeNode(BooleanTest);
newbtest->arg = (Expr *) arg;
newbtest->booltesttype = btest->booltesttype;
return (Node *) newbtest;
}
/*
* For any node type not handled above, we recurse using