mirror of https://github.com/citusdata/citus.git
Update postgres_planning_functions.c
parent
b26422e301
commit
32b492571e
|
@ -16,18 +16,73 @@
|
||||||
#include "distributed/multi_master_planner.h"
|
#include "distributed/multi_master_planner.h"
|
||||||
#include "nodes/plannodes.h"
|
#include "nodes/plannodes.h"
|
||||||
#if PG_VERSION_NUM >= 120000
|
#if PG_VERSION_NUM >= 120000
|
||||||
|
#include "nodes/nodeFuncs.h"
|
||||||
#include "optimizer/optimizer.h"
|
#include "optimizer/optimizer.h"
|
||||||
#else
|
#else
|
||||||
#include "optimizer/tlist.h"
|
#include "optimizer/tlist.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* make_unique_from_sortclauses creates and returns a unique node
|
* make_unique_from_sortclauses creates and returns a unique node
|
||||||
* from provided distinct clause list.
|
* from provided distinct clause list.
|
||||||
* The functions is copied from postgresql from
|
* The functions is copied from postgresql from
|
||||||
* src/backend/optimizer/plan/createplan.c.
|
* src/backend/optimizer/plan/createplan.c.
|
||||||
*
|
*/
|
||||||
|
|
||||||
|
#if PG_VERSION_NUM >= 120000
|
||||||
|
/*
|
||||||
|
* distinctList is a list of SortGroupClauses, identifying the targetlist items
|
||||||
|
* that should be considered by the Unique filter. The input path must
|
||||||
|
* already be sorted accordingly.
|
||||||
|
*/
|
||||||
|
Unique *
|
||||||
|
make_unique_from_sortclauses(Plan *lefttree, List *distinctList)
|
||||||
|
{
|
||||||
|
Unique *node = makeNode(Unique);
|
||||||
|
Plan *plan = &node->plan;
|
||||||
|
int numCols = list_length(distinctList);
|
||||||
|
int keyno = 0;
|
||||||
|
AttrNumber *uniqColIdx;
|
||||||
|
Oid *uniqOperators;
|
||||||
|
Oid *uniqCollations;
|
||||||
|
ListCell *slitem;
|
||||||
|
|
||||||
|
plan->targetlist = lefttree->targetlist;
|
||||||
|
plan->qual = NIL;
|
||||||
|
plan->lefttree = lefttree;
|
||||||
|
plan->righttree = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* convert SortGroupClause list into arrays of attr indexes and equality
|
||||||
|
* operators, as wanted by executor
|
||||||
|
*/
|
||||||
|
Assert(numCols > 0);
|
||||||
|
uniqColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols);
|
||||||
|
uniqOperators = (Oid *) palloc(sizeof(Oid) * numCols);
|
||||||
|
uniqCollations = (Oid *) palloc(sizeof(Oid) * numCols);
|
||||||
|
|
||||||
|
foreach(slitem, distinctList)
|
||||||
|
{
|
||||||
|
SortGroupClause *sortcl = (SortGroupClause *) lfirst(slitem);
|
||||||
|
TargetEntry *tle = get_sortgroupclause_tle(sortcl, plan->targetlist);
|
||||||
|
|
||||||
|
uniqColIdx[keyno] = tle->resno;
|
||||||
|
uniqOperators[keyno] = sortcl->eqop;
|
||||||
|
uniqCollations[keyno] = exprCollation((Node *) tle->expr);
|
||||||
|
Assert(OidIsValid(uniqOperators[keyno]));
|
||||||
|
keyno++;
|
||||||
|
}
|
||||||
|
|
||||||
|
node->numCols = numCols;
|
||||||
|
node->uniqColIdx = uniqColIdx;
|
||||||
|
node->uniqOperators = uniqOperators;
|
||||||
|
node->uniqCollations = uniqCollations;
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/*
|
||||||
* distinctList is a list of SortGroupClauses, identifying the targetlist items
|
* distinctList is a list of SortGroupClauses, identifying the targetlist items
|
||||||
* that should be considered by the Unique filter. The input path must
|
* that should be considered by the Unique filter. The input path must
|
||||||
* already be sorted accordingly.
|
* already be sorted accordingly.
|
||||||
|
@ -73,3 +128,4 @@ make_unique_from_sortclauses(Plan *lefttree, List *distinctList)
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue