noreindent-0001-Replace-a-long-chain-of-if-s-in-eval_const_expressio.patch
text/x-patch
Filename: noreindent-0001-Replace-a-long-chain-of-if-s-in-eval_const_expressio.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch 0001
| File | + | − |
|---|---|---|
| src/backend/optimizer/util/clauses.c | 26 | 21 |
commit e114e3a2708cab8efd64281d09cecbd6303aa329
Author: Andres Freund <andres@anarazel.de>
Date: Fri Nov 11 23:32:02 2011 +0100
Replace a long chain of if's in eval_const_expressions_mutator by a switch()
For unknown reasons the function used non chained ifs for every handled
nodeType.
Replacing the if chain with if; else if; ... resulted in a small
speedup. Replacing it with a switch() in a bigger one.
When testing with a statement containing a longer VALUES statement:
pgbench -M prepared -f stmt -T 10:
orig: 10015.287829
if: 10075.482117
switch: 10246.527402
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index 197d9c2..f6f0b11 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -2106,7 +2106,9 @@ eval_const_expressions_mutator(Node *node,
{
if (node == NULL)
return NULL;
- if (IsA(node, Param))
+ switch(nodeTag(node))
+ {
+ case T_Param:
{
Param *param = (Param *) node;
@@ -2152,7 +2154,7 @@ eval_const_expressions_mutator(Node *node,
/* Not replaceable, so just copy the Param (no need to recurse) */
return (Node *) copyObject(param);
}
- if (IsA(node, FuncExpr))
+ case T_FuncExpr:
{
FuncExpr *expr = (FuncExpr *) node;
List *args;
@@ -2210,7 +2212,7 @@ eval_const_expressions_mutator(Node *node,
newexpr->location = expr->location;
return (Node *) newexpr;
}
- if (IsA(node, OpExpr))
+ case T_OpExpr:
{
OpExpr *expr = (OpExpr *) node;
List *args;
@@ -2275,7 +2277,7 @@ eval_const_expressions_mutator(Node *node,
newexpr->location = expr->location;
return (Node *) newexpr;
}
- if (IsA(node, DistinctExpr))
+ case T_DistinctExpr:
{
DistinctExpr *expr = (DistinctExpr *) node;
List *args;
@@ -2372,7 +2374,7 @@ eval_const_expressions_mutator(Node *node,
newexpr->location = expr->location;
return (Node *) newexpr;
}
- if (IsA(node, BoolExpr))
+ case T_BoolExpr:
{
BoolExpr *expr = (BoolExpr *) node;
@@ -2440,9 +2442,8 @@ eval_const_expressions_mutator(Node *node,
break;
}
}
- if (IsA(node, SubPlan) ||
- IsA(node, AlternativeSubPlan))
- {
+ case T_SubPlan:
+ case T_AlternativeSubPlan:
/*
* Return a SubPlan unchanged --- too late to do anything with it.
*
@@ -2450,8 +2451,7 @@ eval_const_expressions_mutator(Node *node,
* never be invoked after SubPlan creation.
*/
return node;
- }
- if (IsA(node, RelabelType))
+ case T_RelabelType:
{
/*
* If we can simplify the input to a constant, then we don't need the
@@ -2493,7 +2493,7 @@ eval_const_expressions_mutator(Node *node,
return (Node *) newrelabel;
}
}
- if (IsA(node, CoerceViaIO))
+ case T_CoerceViaIO:
{
CoerceViaIO *expr = (CoerceViaIO *) node;
Expr *arg;
@@ -2569,7 +2569,7 @@ eval_const_expressions_mutator(Node *node,
newexpr->location = expr->location;
return (Node *) newexpr;
}
- if (IsA(node, ArrayCoerceExpr))
+ case T_ArrayCoerceExpr:
{
ArrayCoerceExpr *expr = (ArrayCoerceExpr *) node;
Expr *arg;
@@ -2607,7 +2607,7 @@ eval_const_expressions_mutator(Node *node,
/* Else we must return the partially-simplified node */
return (Node *) newexpr;
}
- if (IsA(node, CollateExpr))
+ case T_CollateExpr:
{
/*
* If we can simplify the input to a constant, then we don't need the
@@ -2652,7 +2652,7 @@ eval_const_expressions_mutator(Node *node,
return (Node *) relabel;
}
}
- if (IsA(node, CaseExpr))
+ case T_CaseExpr:
{
/*----------
* CASE expressions can be simplified if there are constant
@@ -2783,7 +2783,7 @@ eval_const_expressions_mutator(Node *node,
newcase->location = caseexpr->location;
return (Node *) newcase;
}
- if (IsA(node, CaseTestExpr))
+ case T_CaseTestExpr:
{
/*
* If we know a constant test value for the current CASE construct,
@@ -2795,7 +2795,7 @@ eval_const_expressions_mutator(Node *node,
else
return copyObject(node);
}
- if (IsA(node, ArrayExpr))
+ case T_ArrayExpr:
{
ArrayExpr *arrayexpr = (ArrayExpr *) node;
ArrayExpr *newarray;
@@ -2831,7 +2831,7 @@ eval_const_expressions_mutator(Node *node,
return (Node *) newarray;
}
- if (IsA(node, CoalesceExpr))
+ case T_CoalesceExpr:
{
CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
CoalesceExpr *newcoalesce;
@@ -2878,7 +2878,7 @@ eval_const_expressions_mutator(Node *node,
newcoalesce->location = coalesceexpr->location;
return (Node *) newcoalesce;
}
- if (IsA(node, FieldSelect))
+ case T_FieldSelect:
{
/*
* We can optimize field selection from a whole-row Var into a simple
@@ -2941,7 +2941,7 @@ eval_const_expressions_mutator(Node *node,
newfselect->resultcollid = fselect->resultcollid;
return (Node *) newfselect;
}
- if (IsA(node, NullTest))
+ case T_NullTest:
{
NullTest *ntest = (NullTest *) node;
NullTest *newntest;
@@ -3024,7 +3024,7 @@ eval_const_expressions_mutator(Node *node,
newntest->argisrow = ntest->argisrow;
return (Node *) newntest;
}
- if (IsA(node, BooleanTest))
+ case T_BooleanTest:
{
BooleanTest *btest = (BooleanTest *) node;
BooleanTest *newbtest;
@@ -3076,7 +3076,8 @@ eval_const_expressions_mutator(Node *node,
newbtest->booltesttype = btest->booltesttype;
return (Node *) newbtest;
}
- if (IsA(node, PlaceHolderVar) &&context->estimate)
+ case T_PlaceHolderVar:
+ if(context->estimate)
{
/*
* In estimation mode, just strip the PlaceHolderVar node altogether;
@@ -3090,6 +3091,10 @@ eval_const_expressions_mutator(Node *node,
return eval_const_expressions_mutator((Node *) phv->phexpr,
context);
}
+ //fall through
+ default:
+ ;
+ }
/*
* For any node type not handled above, we recurse using