Replace ARRAY_OUT_FUNC_ID with postgres's F_ARRAY_OUT

Also use stack allocation for walkerContext in multi_logical_optimizer
pull/3372/head
Philip Dubé 2020-01-10 00:26:07 +00:00
parent c7efbf9711
commit e71386af33
3 changed files with 17 additions and 20 deletions

View File

@ -1409,11 +1409,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 = palloc0( MasterAggregateWalkerContext walkerContext = { 0 };
sizeof(MasterAggregateWalkerContext));
walkerContext->extendedOpNodeProperties = extendedOpNodeProperties; walkerContext.extendedOpNodeProperties = extendedOpNodeProperties;
walkerContext->columnId = 1; walkerContext.columnId = 1;
/* iterate over original target entries */ /* iterate over original target entries */
foreach(targetEntryCell, targetEntryList) foreach(targetEntryCell, targetEntryList)
@ -1434,7 +1433,7 @@ MasterExtendedOpNode(MultiExtendedOp *originalOpNode,
!extendedOpNodeProperties->groupedByDisjointPartitionColumn) !extendedOpNodeProperties->groupedByDisjointPartitionColumn)
{ {
Node *newNode = MasterAggregateMutator((Node *) originalExpression, Node *newNode = MasterAggregateMutator((Node *) originalExpression,
walkerContext); &walkerContext);
newExpression = (Expr *) newNode; newExpression = (Expr *) newNode;
} }
else else
@ -1447,9 +1446,9 @@ MasterExtendedOpNode(MultiExtendedOp *originalOpNode,
const uint32 masterTableId = 1; /* only one table on master node */ const uint32 masterTableId = 1; /* only one table on master node */
Var *column = makeVarFromTargetEntry(masterTableId, originalTargetEntry); Var *column = makeVarFromTargetEntry(masterTableId, originalTargetEntry);
column->varattno = walkerContext->columnId; column->varattno = walkerContext.columnId;
column->varoattno = walkerContext->columnId; column->varoattno = walkerContext.columnId;
walkerContext->columnId++; walkerContext.columnId++;
if (column->vartype == RECORDOID || column->vartype == RECORDARRAYOID) if (column->vartype == RECORDOID || column->vartype == RECORDARRAYOID)
{ {
@ -1473,7 +1472,7 @@ MasterExtendedOpNode(MultiExtendedOp *originalOpNode,
if (originalHavingQual != NULL) if (originalHavingQual != NULL)
{ {
newHavingQual = MasterAggregateMutator(originalHavingQual, walkerContext); newHavingQual = MasterAggregateMutator(originalHavingQual, &walkerContext);
} }
} }
@ -2309,11 +2308,10 @@ ProcessTargetListForWorkerQuery(List *targetEntryList,
QueryGroupClause *queryGroupClause) QueryGroupClause *queryGroupClause)
{ {
ListCell *targetEntryCell = NULL; ListCell *targetEntryCell = NULL;
WorkerAggregateWalkerContext *workerAggContext = WorkerAggregateWalkerContext workerAggContext = { 0 };
palloc0(sizeof(WorkerAggregateWalkerContext));
workerAggContext->extendedOpNodeProperties = extendedOpNodeProperties; workerAggContext.extendedOpNodeProperties = extendedOpNodeProperties;
workerAggContext->expressionList = NIL; workerAggContext.expressionList = NIL;
/* iterate over original target entries */ /* iterate over original target entries */
foreach(targetEntryCell, targetEntryList) foreach(targetEntryCell, targetEntryList)
@ -2325,8 +2323,8 @@ ProcessTargetListForWorkerQuery(List *targetEntryList,
bool hasWindowFunction = contain_window_function((Node *) originalExpression); bool hasWindowFunction = contain_window_function((Node *) originalExpression);
/* reset walker context */ /* reset walker context */
workerAggContext->expressionList = NIL; workerAggContext.expressionList = NIL;
workerAggContext->createGroupByClause = false; workerAggContext.createGroupByClause = false;
/* /*
* If the query has a window function, we currently assume it's safe to push * If the query has a window function, we currently assume it's safe to push
@ -2339,9 +2337,9 @@ ProcessTargetListForWorkerQuery(List *targetEntryList,
if (!hasWindowFunction && hasAggregates && if (!hasWindowFunction && hasAggregates &&
!extendedOpNodeProperties->groupedByDisjointPartitionColumn) !extendedOpNodeProperties->groupedByDisjointPartitionColumn)
{ {
WorkerAggregateWalker((Node *) originalExpression, workerAggContext); WorkerAggregateWalker((Node *) originalExpression, &workerAggContext);
newExpressionList = workerAggContext->expressionList; newExpressionList = workerAggContext.expressionList;
} }
else else
{ {
@ -2349,7 +2347,7 @@ ProcessTargetListForWorkerQuery(List *targetEntryList,
} }
ExpandWorkerTargetEntry(newExpressionList, originalTargetEntry, ExpandWorkerTargetEntry(newExpressionList, originalTargetEntry,
workerAggContext->createGroupByClause, workerAggContext.createGroupByClause,
queryTargetList, queryGroupClause); queryTargetList, queryGroupClause);
} }
} }

View File

@ -3953,7 +3953,7 @@ DatumArrayString(Datum *datumArray, uint32 datumCount, Oid datumTypeId)
/* convert the array object to its string representation */ /* convert the array object to its string representation */
FmgrInfo *arrayOutFunction = (FmgrInfo *) palloc0(sizeof(FmgrInfo)); FmgrInfo *arrayOutFunction = (FmgrInfo *) palloc0(sizeof(FmgrInfo));
fmgr_info(ARRAY_OUT_FUNC_ID, arrayOutFunction); fmgr_info(F_ARRAY_OUT, arrayOutFunction);
Datum arrayStringDatum = FunctionCall1(arrayOutFunction, arrayObjectDatum); Datum arrayStringDatum = FunctionCall1(arrayOutFunction, arrayObjectDatum);
char *arrayString = DatumGetCString(arrayStringDatum); char *arrayString = DatumGetCString(arrayStringDatum);

View File

@ -30,7 +30,6 @@
/* Definitions local to the physical planner */ /* Definitions local to the physical planner */
#define ARRAY_OUT_FUNC_ID 751
#define NON_PRUNABLE_JOIN -1 #define NON_PRUNABLE_JOIN -1
#define RESERVED_HASHED_COLUMN_ID MaxAttrNumber #define RESERVED_HASHED_COLUMN_ID MaxAttrNumber
#define MERGE_COLUMN_FORMAT "merge_column_%u" #define MERGE_COLUMN_FORMAT "merge_column_%u"