multi_logical_optimizer: replace ListCopyDeep with copyObject, stack allocate WorkerAggregateWalkerContext

pull/3614/head
Philip Dubé 2020-03-12 20:25:51 +00:00
parent e5237b9e20
commit 7b382e43bc
1 changed files with 17 additions and 41 deletions

View File

@ -171,7 +171,6 @@ static List * OrSelectClauseList(List *selectClauseList);
static void PushDownNodeLoop(MultiUnaryNode *currentNode); static void PushDownNodeLoop(MultiUnaryNode *currentNode);
static void PullUpCollectLoop(MultiCollect *collectNode); static void PullUpCollectLoop(MultiCollect *collectNode);
static void AddressProjectSpecialConditions(MultiProject *projectNode); static void AddressProjectSpecialConditions(MultiProject *projectNode);
static List * ListCopyDeep(List *nodeList);
static PushDownStatus CanPushDown(MultiUnaryNode *parentNode); static PushDownStatus CanPushDown(MultiUnaryNode *parentNode);
static PullUpStatus CanPullUp(MultiUnaryNode *childNode); static PullUpStatus CanPullUp(MultiUnaryNode *childNode);
static PushDownStatus Commutative(MultiUnaryNode *parentNode, static PushDownStatus Commutative(MultiUnaryNode *parentNode,
@ -688,7 +687,7 @@ AddressProjectSpecialConditions(MultiProject *projectNode)
MultiProject *projectChildNode = (MultiProject *) childNode; MultiProject *projectChildNode = (MultiProject *) childNode;
List *projectColumnList = projectChildNode->columnList; List *projectColumnList = projectChildNode->columnList;
childColumnList = ListCopyDeep(projectColumnList); childColumnList = copyObject(projectColumnList);
} }
else if (childNodeTag == T_MultiPartition) else if (childNodeTag == T_MultiPartition)
{ {
@ -696,7 +695,7 @@ AddressProjectSpecialConditions(MultiProject *projectNode)
Var *partitionColumn = partitionNode->partitionColumn; Var *partitionColumn = partitionNode->partitionColumn;
List *partitionColumnList = list_make1(partitionColumn); List *partitionColumnList = list_make1(partitionColumn);
childColumnList = ListCopyDeep(partitionColumnList); childColumnList = copyObject(partitionColumnList);
} }
else if (childNodeTag == T_MultiSelect) else if (childNodeTag == T_MultiSelect)
{ {
@ -704,7 +703,7 @@ AddressProjectSpecialConditions(MultiProject *projectNode)
Node *selectClauseList = (Node *) selectNode->selectClauseList; Node *selectClauseList = (Node *) selectNode->selectClauseList;
List *selectList = pull_var_clause_default(selectClauseList); List *selectList = pull_var_clause_default(selectClauseList);
childColumnList = ListCopyDeep(selectList); childColumnList = copyObject(selectList);
} }
else if (childNodeTag == T_MultiJoin) else if (childNodeTag == T_MultiJoin)
{ {
@ -712,7 +711,7 @@ AddressProjectSpecialConditions(MultiProject *projectNode)
Node *joinClauseList = (Node *) joinNode->joinClauseList; Node *joinClauseList = (Node *) joinNode->joinClauseList;
List *joinList = pull_var_clause_default(joinClauseList); List *joinList = pull_var_clause_default(joinClauseList);
childColumnList = ListCopyDeep(joinList); childColumnList = copyObject(joinList);
} }
/* /*
@ -729,25 +728,6 @@ AddressProjectSpecialConditions(MultiProject *projectNode)
} }
/* Deep copies the given node list, and returns the deep copied list. */
static List *
ListCopyDeep(List *nodeList)
{
List *nodeCopyList = NIL;
ListCell *nodeCell = NULL;
foreach(nodeCell, nodeList)
{
Node *node = (Node *) lfirst(nodeCell);
Node *nodeCopy = copyObject(node);
nodeCopyList = lappend(nodeCopyList, nodeCopy);
}
return nodeCopyList;
}
/* /*
* CanPushDown determines if a particular node can be moved below its child. The * CanPushDown determines if a particular node can be moved below its child. The
* criteria for pushing down a node is determined by multi-relational algebra's * criteria for pushing down a node is determined by multi-relational algebra's
@ -1422,10 +1402,10 @@ MasterExtendedOpNode(MultiExtendedOp *originalOpNode,
ListCell *targetEntryCell = NULL; ListCell *targetEntryCell = NULL;
Node *originalHavingQual = originalOpNode->havingQual; Node *originalHavingQual = originalOpNode->havingQual;
Node *newHavingQual = NULL; Node *newHavingQual = NULL;
MasterAggregateWalkerContext walkerContext = { 0 }; MasterAggregateWalkerContext walkerContext = {
.extendedOpNodeProperties = extendedOpNodeProperties,
walkerContext.extendedOpNodeProperties = extendedOpNodeProperties; .columnId = 1,
walkerContext.columnId = 1; };
/* iterate over original target entries */ /* iterate over original target entries */
foreach(targetEntryCell, targetEntryList) foreach(targetEntryCell, targetEntryList)
@ -2330,10 +2310,9 @@ ProcessTargetListForWorkerQuery(List *targetEntryList,
QueryGroupClause *queryGroupClause) QueryGroupClause *queryGroupClause)
{ {
ListCell *targetEntryCell = NULL; ListCell *targetEntryCell = NULL;
WorkerAggregateWalkerContext workerAggContext = { 0 }; WorkerAggregateWalkerContext workerAggContext = {
.extendedOpNodeProperties = extendedOpNodeProperties,
workerAggContext.extendedOpNodeProperties = extendedOpNodeProperties; };
workerAggContext.expressionList = NIL;
/* iterate over original target entries */ /* iterate over original target entries */
foreach(targetEntryCell, targetEntryList) foreach(targetEntryCell, targetEntryList)
@ -2408,19 +2387,16 @@ ProcessHavingClauseForWorkerQuery(Node *originalHavingQual,
* If the GROUP BY or PARTITION BY is not on the distribution column * If the GROUP BY or PARTITION BY is not on the distribution column
* then we need to combine the aggregates in the HAVING across shards. * then we need to combine the aggregates in the HAVING across shards.
*/ */
WorkerAggregateWalkerContext *workerAggContext = palloc0( WorkerAggregateWalkerContext workerAggContext = {
sizeof(WorkerAggregateWalkerContext)); .extendedOpNodeProperties = extendedOpNodeProperties,
};
workerAggContext->extendedOpNodeProperties = extendedOpNodeProperties; WorkerAggregateWalker(originalHavingQual, &workerAggContext);
workerAggContext->expressionList = NIL; List *newExpressionList = workerAggContext.expressionList;
workerAggContext->createGroupByClause = false;
WorkerAggregateWalker(originalHavingQual, workerAggContext);
List *newExpressionList = workerAggContext->expressionList;
TargetEntry *targetEntry = NULL; TargetEntry *targetEntry = NULL;
ExpandWorkerTargetEntry(newExpressionList, targetEntry, ExpandWorkerTargetEntry(newExpressionList, targetEntry,
workerAggContext->createGroupByClause, workerAggContext.createGroupByClause,
queryTargetList, queryGroupClause); queryTargetList, queryGroupClause);
} }