diff options
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r-- | src/backend/optimizer/plan/createplan.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index ab69742482a..70a73821641 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.81 2000/01/26 05:56:37 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.82 2000/01/27 18:11:30 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1342,16 +1342,19 @@ make_group(List *tlist, } /* - * The uniqueAttr argument must be a null-terminated string, - * either the name of the attribute to select unique on - * or "*" + * distinctList is a list of SortClauses, identifying the targetlist items + * that should be considered by the Unique filter. */ Unique * -make_unique(List *tlist, Plan *lefttree, char *uniqueAttr) +make_unique(List *tlist, Plan *lefttree, List *distinctList) { Unique *node = makeNode(Unique); Plan *plan = &node->plan; + int numCols = length(distinctList); + int keyno = 0; + AttrNumber *uniqColIdx; + List *slitem; copy_plan_costsize(plan, lefttree); plan->state = (EState *) NULL; @@ -1361,10 +1364,22 @@ make_unique(List *tlist, Plan *lefttree, char *uniqueAttr) plan->righttree = NULL; node->nonameid = _NONAME_RELATION_ID_; node->keycount = 0; - if (strcmp(uniqueAttr, "*") == 0) - node->uniqueAttr = NULL; - else - node->uniqueAttr = pstrdup(uniqueAttr); + + /* convert SortClause list into array of attr indexes, as wanted by exec */ + Assert(numCols > 0); + uniqColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols); + + foreach(slitem, distinctList) + { + SortClause *sortcl = (SortClause *) lfirst(slitem); + TargetEntry *tle = get_sortgroupclause_tle(sortcl, tlist); + + uniqColIdx[keyno++] = tle->resdom->resno; + } + + node->numCols = numCols; + node->uniqColIdx = uniqColIdx; + return node; } |