Skip to content

Commit e2d34d7

Browse files
committed
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.
1 parent 3ceaa97 commit e2d34d7

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.216 2006/08/02 01:59:46 joe Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.217 2006/08/04 14:09:51 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHOR DATE MAJOR EVENT
@@ -2092,6 +2092,58 @@ eval_const_expressions_mutator(Node *node,
20922092
newfselect->resulttypmod = fselect->resulttypmod;
20932093
return (Node *) newfselect;
20942094
}
2095+
if (IsA(node, BooleanTest))
2096+
{
2097+
BooleanTest *btest = (BooleanTest *) node;
2098+
BooleanTest *newbtest;
2099+
Node *arg;
2100+
2101+
arg = eval_const_expressions_mutator((Node *) btest->arg,
2102+
context);
2103+
if (arg && IsA(arg, Const))
2104+
{
2105+
Const *carg = (Const *) arg;
2106+
bool result;
2107+
2108+
switch (btest->booltesttype)
2109+
{
2110+
case IS_TRUE:
2111+
result = (!carg->constisnull &&
2112+
DatumGetBool(carg->constvalue));
2113+
break;
2114+
case IS_NOT_TRUE:
2115+
result = (carg->constisnull ||
2116+
!DatumGetBool(carg->constvalue));
2117+
break;
2118+
case IS_FALSE:
2119+
result = (!carg->constisnull &&
2120+
!DatumGetBool(carg->constvalue));
2121+
break;
2122+
case IS_NOT_FALSE:
2123+
result = (carg->constisnull ||
2124+
DatumGetBool(carg->constvalue));
2125+
break;
2126+
case IS_UNKNOWN:
2127+
result = carg->constisnull;
2128+
break;
2129+
case IS_NOT_UNKNOWN:
2130+
result = !carg->constisnull;
2131+
break;
2132+
default:
2133+
elog(ERROR, "unrecognized booltesttype: %d",
2134+
(int) btest->booltesttype);
2135+
result = false; /* keep compiler quiet */
2136+
break;
2137+
}
2138+
2139+
return makeBoolConst(result, false);
2140+
}
2141+
2142+
newbtest = makeNode(BooleanTest);
2143+
newbtest->arg = (Expr *) arg;
2144+
newbtest->booltesttype = btest->booltesttype;
2145+
return (Node *) newbtest;
2146+
}
20952147

20962148
/*
20972149
* For any node type not handled above, we recurse using

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy