Commit afaa6b98 authored by Tom Lane's avatar Tom Lane

Marginal performance hack: avoid unnecessary work in expression_tree_mutator.

We can just palloc, instead of using makeNode, when we are going to
overwrite the whole node anyway in the FLATCOPY macro.  Also, use
FLATCOPY instead of copyObject for common node types Var and Const.
parent 39a333aa
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.242 2007/04/27 22:05:48 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.243 2007/04/30 00:14:54 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -3770,12 +3770,12 @@ expression_tree_mutator(Node *node, ...@@ -3770,12 +3770,12 @@ expression_tree_mutator(Node *node,
*/ */
#define FLATCOPY(newnode, node, nodetype) \ #define FLATCOPY(newnode, node, nodetype) \
( (newnode) = makeNode(nodetype), \ ( (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
memcpy((newnode), (node), sizeof(nodetype)) ) memcpy((newnode), (node), sizeof(nodetype)) )
#define CHECKFLATCOPY(newnode, node, nodetype) \ #define CHECKFLATCOPY(newnode, node, nodetype) \
( AssertMacro(IsA((node), nodetype)), \ ( AssertMacro(IsA((node), nodetype)), \
(newnode) = makeNode(nodetype), \ (newnode) = (nodetype *) palloc(sizeof(nodetype)), \
memcpy((newnode), (node), sizeof(nodetype)) ) memcpy((newnode), (node), sizeof(nodetype)) )
#define MUTATE(newfield, oldfield, fieldtype) \ #define MUTATE(newfield, oldfield, fieldtype) \
...@@ -3789,15 +3789,36 @@ expression_tree_mutator(Node *node, ...@@ -3789,15 +3789,36 @@ expression_tree_mutator(Node *node,
switch (nodeTag(node)) switch (nodeTag(node))
{ {
/*
* Primitive node types with no expression subnodes. Var and Const
* are frequent enough to deserve special cases, the others we just
* use copyObject for.
*/
case T_Var: case T_Var:
{
Var *var = (Var *) node;
Var *newnode;
FLATCOPY(newnode, var, Var);
return (Node *) newnode;
}
break;
case T_Const: case T_Const:
{
Const *oldnode = (Const *) node;
Const *newnode;
FLATCOPY(newnode, oldnode, Const);
/* XXX we don't bother with datumCopy; should we? */
return (Node *) newnode;
}
break;
case T_Param: case T_Param:
case T_CoerceToDomainValue: case T_CoerceToDomainValue:
case T_CaseTestExpr: case T_CaseTestExpr:
case T_SetToDefault: case T_SetToDefault:
case T_RangeTblRef: case T_RangeTblRef:
case T_OuterJoinInfo: case T_OuterJoinInfo:
/* primitive node types with no expression subnodes */
return (Node *) copyObject(node); return (Node *) copyObject(node);
case T_Aggref: case T_Aggref:
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment