Make some minor formatting improvements to what pgindent did.

Moving the code two full tab stops to the right requires rethinking of
cosmetic code layout choices, which pgindent isn't really able to do for
us.  Whitespace and comment adjustments only, no code changes.
This commit is contained in:
Tom Lane 2011-11-28 20:19:29 -05:00
parent 871dd024a6
commit 43dc4adf58

View File

@ -2123,7 +2123,8 @@ eval_const_expressions_mutator(Node *node,
if (OidIsValid(prm->ptype)) if (OidIsValid(prm->ptype))
{ {
/* OK to substitute parameter value? */ /* OK to substitute parameter value? */
if (context->estimate || (prm->pflags & PARAM_FLAG_CONST)) if (context->estimate ||
(prm->pflags & PARAM_FLAG_CONST))
{ {
/* /*
* Return a Const representing the param value. * Return a Const representing the param value.
@ -2136,7 +2137,8 @@ eval_const_expressions_mutator(Node *node,
Datum pval; Datum pval;
Assert(prm->ptype == param->paramtype); Assert(prm->ptype == param->paramtype);
get_typlenbyval(param->paramtype, &typLen, &typByVal); get_typlenbyval(param->paramtype,
&typLen, &typByVal);
if (prm->isnull || typByVal) if (prm->isnull || typByVal)
pval = prm->value; pval = prm->value;
else else
@ -2192,11 +2194,14 @@ eval_const_expressions_mutator(Node *node,
*/ */
simple = simplify_function((Expr *) expr, simple = simplify_function((Expr *) expr,
expr->funcid, expr->funcid,
expr->funcresulttype, exprTypmod(node), expr->funcresulttype,
exprTypmod(node),
expr->funccollid, expr->funccollid,
expr->inputcollid, expr->inputcollid,
&args, &args,
has_named_args, true, context); has_named_args,
true,
context);
if (simple) /* successfully simplified it */ if (simple) /* successfully simplified it */
return (Node *) simple; return (Node *) simple;
@ -2262,7 +2267,8 @@ eval_const_expressions_mutator(Node *node,
if (expr->opno == BooleanEqualOperator || if (expr->opno == BooleanEqualOperator ||
expr->opno == BooleanNotEqualOperator) expr->opno == BooleanNotEqualOperator)
{ {
simple = (Expr *) simplify_boolean_equality(expr->opno, args); simple = (Expr *) simplify_boolean_equality(expr->opno,
args);
if (simple) /* successfully simplified it */ if (simple) /* successfully simplified it */
return (Node *) simple; return (Node *) simple;
} }
@ -2395,12 +2401,15 @@ eval_const_expressions_mutator(Node *node,
bool haveNull = false; bool haveNull = false;
bool forceTrue = false; bool forceTrue = false;
newargs = simplify_or_arguments(expr->args, context, newargs = simplify_or_arguments(expr->args,
&haveNull, &forceTrue); context,
&haveNull,
&forceTrue);
if (forceTrue) if (forceTrue)
return makeBoolConst(true, false); return makeBoolConst(true, false);
if (haveNull) if (haveNull)
newargs = lappend(newargs, makeBoolConst(false, true)); newargs = lappend(newargs,
makeBoolConst(false, true));
/* If all the inputs are FALSE, result is FALSE */ /* If all the inputs are FALSE, result is FALSE */
if (newargs == NIL) if (newargs == NIL)
return makeBoolConst(false, false); return makeBoolConst(false, false);
@ -2420,12 +2429,15 @@ eval_const_expressions_mutator(Node *node,
bool haveNull = false; bool haveNull = false;
bool forceFalse = false; bool forceFalse = false;
newargs = simplify_and_arguments(expr->args, context, newargs = simplify_and_arguments(expr->args,
&haveNull, &forceFalse); context,
&haveNull,
&forceFalse);
if (forceFalse) if (forceFalse)
return makeBoolConst(false, false); return makeBoolConst(false, false);
if (haveNull) if (haveNull)
newargs = lappend(newargs, makeBoolConst(false, true)); newargs = lappend(newargs,
makeBoolConst(false, true));
/* If all the inputs are TRUE, result is TRUE */ /* If all the inputs are TRUE, result is TRUE */
if (newargs == NIL) if (newargs == NIL)
return makeBoolConst(true, false); return makeBoolConst(true, false);
@ -2541,8 +2553,10 @@ eval_const_expressions_mutator(Node *node,
* Note that the coercion functions are assumed not to care * Note that the coercion functions are assumed not to care
* about input collation, so we just pass InvalidOid for that. * about input collation, so we just pass InvalidOid for that.
*/ */
getTypeOutputInfo(exprType((Node *) arg), &outfunc, &outtypisvarlena); getTypeOutputInfo(exprType((Node *) arg),
getTypeInputInfo(expr->resulttype, &infunc, &intypioparam); &outfunc, &outtypisvarlena);
getTypeInputInfo(expr->resulttype,
&infunc, &intypioparam);
simple = simplify_function(NULL, simple = simplify_function(NULL,
outfunc, outfunc,
@ -2559,12 +2573,20 @@ eval_const_expressions_mutator(Node *node,
* complain. * complain.
*/ */
args = list_make3(simple, args = list_make3(simple,
makeConst(OIDOID, -1, InvalidOid, sizeof(Oid), makeConst(OIDOID,
-1,
InvalidOid,
sizeof(Oid),
ObjectIdGetDatum(intypioparam), ObjectIdGetDatum(intypioparam),
false, true), false,
makeConst(INT4OID, -1, InvalidOid, sizeof(int32), true),
makeConst(INT4OID,
-1,
InvalidOid,
sizeof(int32),
Int32GetDatum(-1), Int32GetDatum(-1),
false, true)); false,
true));
simple = simplify_function(NULL, simple = simplify_function(NULL,
infunc, infunc,
@ -2681,19 +2703,20 @@ eval_const_expressions_mutator(Node *node,
* condition clauses: * condition clauses:
* FALSE (or NULL): drop the alternative * FALSE (or NULL): drop the alternative
* TRUE: drop all remaining alternatives * TRUE: drop all remaining alternatives
* If the first non-FALSE alternative is a constant TRUE, we can * If the first non-FALSE alternative is a constant TRUE,
* simplify the entire CASE to that alternative's expression. * we can simplify the entire CASE to that alternative's
* If there are no non-FALSE alternatives, we simplify the entire * expression. If there are no non-FALSE alternatives,
* CASE to the default result (ELSE result). * we simplify the entire CASE to the default result (ELSE).
* *
* If we have a simple-form CASE with constant test expression, * If we have a simple-form CASE with constant test
* we substitute the constant value for contained CaseTestExpr * expression, we substitute the constant value for contained
* placeholder nodes, so that we have the opportunity to reduce * CaseTestExpr placeholder nodes, so that we have the
* constant test conditions. For example this allows * opportunity to reduce constant test conditions. For
* example this allows
* CASE 0 WHEN 0 THEN 1 ELSE 1/0 END * CASE 0 WHEN 0 THEN 1 ELSE 1/0 END
* to reduce to 1 rather than drawing a divide-by-0 error. Note * to reduce to 1 rather than drawing a divide-by-0 error.
* that when the test expression is constant, we don't have to * Note that when the test expression is constant, we don't
* include it in the resulting CASE; for example * have to include it in the resulting CASE; for example
* CASE 0 WHEN x THEN y ELSE z END * CASE 0 WHEN x THEN y ELSE z END
* is transformed by the parser to * is transformed by the parser to
* CASE 0 WHEN CaseTestExpr = x THEN y ELSE z END * CASE 0 WHEN CaseTestExpr = x THEN y ELSE z END
@ -2723,8 +2746,7 @@ eval_const_expressions_mutator(Node *node,
if (newarg && IsA(newarg, Const)) if (newarg && IsA(newarg, Const))
{ {
context->case_val = newarg; context->case_val = newarg;
newarg = NULL; /* not needed anymore, see comment newarg = NULL; /* not needed anymore, see above */
* above */
} }
else else
context->case_val = NULL; context->case_val = NULL;
@ -2741,8 +2763,7 @@ eval_const_expressions_mutator(Node *node,
Assert(IsA(oldcasewhen, CaseWhen)); Assert(IsA(oldcasewhen, CaseWhen));
/* Simplify this alternative's test condition */ /* Simplify this alternative's test condition */
casecond = casecond = eval_const_expressions_mutator((Node *) oldcasewhen->expr,
eval_const_expressions_mutator((Node *) oldcasewhen->expr,
context); context);
/* /*
@ -2756,15 +2777,13 @@ eval_const_expressions_mutator(Node *node,
if (const_input->constisnull || if (const_input->constisnull ||
!DatumGetBool(const_input->constvalue)) !DatumGetBool(const_input->constvalue))
continue; /* drop alternative with FALSE continue; /* drop alternative with FALSE cond */
* condition */
/* Else it's constant TRUE */ /* Else it's constant TRUE */
const_true_cond = true; const_true_cond = true;
} }
/* Simplify this alternative's result value */ /* Simplify this alternative's result value */
caseresult = caseresult = eval_const_expressions_mutator((Node *) oldcasewhen->result,
eval_const_expressions_mutator((Node *) oldcasewhen->result,
context); context);
/* If non-constant test condition, emit a new WHEN node */ /* If non-constant test condition, emit a new WHEN node */
@ -2790,8 +2809,7 @@ eval_const_expressions_mutator(Node *node,
/* Simplify the default result, unless we replaced it above */ /* Simplify the default result, unless we replaced it above */
if (!const_true_cond) if (!const_true_cond)
defresult = defresult = eval_const_expressions_mutator((Node *) caseexpr->defresult,
eval_const_expressions_mutator((Node *) caseexpr->defresult,
context); context);
context->case_val = save_case_val; context->case_val = save_case_val;