diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-31 22:47:56 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-31 22:47:56 +0000 |
| commit | 63247bec284a935b3145d5302c834967049e5dea (patch) | |
| tree | 5ec4c97c2b144ee82e67d53f407818083f581b87 /src/backend/optimizer/prep/prepunion.c | |
| parent | b1fb3b2a7f0eec20502e4e7309ff52fc0288434a (diff) | |
Fix parser so that we don't modify the user-written ORDER BY list in order
to represent DISTINCT or DISTINCT ON. This gets rid of a longstanding
annoyance that a view or rule using SELECT DISTINCT will be dumped out
with an overspecified ORDER BY list, and is one small step along the way
to decoupling DISTINCT and ORDER BY enough so that hash-based implementation
of DISTINCT will be possible. In passing, improve transformDistinctClause
so that it doesn't reject duplicate DISTINCT ON items, as was reported by
Steve Midgley a couple weeks ago.
Diffstat (limited to 'src/backend/optimizer/prep/prepunion.c')
| -rw-r--r-- | src/backend/optimizer/prep/prepunion.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index ed18cf5e3fe..b30cedee9fc 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -22,7 +22,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.147 2008/06/19 00:46:04 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.148 2008/07/31 22:47:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -69,6 +69,7 @@ static List *generate_setop_tlist(List *colTypes, int flag, static List *generate_append_tlist(List *colTypes, bool flag, List *input_plans, List *refnames_tlist); +static List *generate_setop_sortlist(List *targetlist); static void expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti); static void make_inh_translation_lists(Relation oldrelation, @@ -319,7 +320,7 @@ generate_union_plan(SetOperationStmt *op, PlannerInfo *root, { List *sortList; - sortList = addAllTargetsToSortList(NULL, NIL, tlist, false); + sortList = generate_setop_sortlist(tlist); if (sortList) { plan = (Plan *) make_sort_from_sortclauses(root, sortList, plan); @@ -384,7 +385,7 @@ generate_nonunion_plan(SetOperationStmt *op, PlannerInfo *root, * Sort the child results, then add a SetOp plan node to generate the * correct output. */ - sortList = addAllTargetsToSortList(NULL, NIL, tlist, false); + sortList = generate_setop_sortlist(tlist); if (sortList == NIL) /* nothing to sort on? */ { @@ -675,6 +676,31 @@ generate_append_tlist(List *colTypes, bool flag, return tlist; } +/* + * generate_setop_sortlist + * Build a SortClause list enumerating all the non-resjunk tlist entries, + * using default ordering properties. + */ +static List * +generate_setop_sortlist(List *targetlist) +{ + List *sortlist = NIL; + ListCell *l; + + foreach(l, targetlist) + { + TargetEntry *tle = (TargetEntry *) lfirst(l); + + if (!tle->resjunk) + sortlist = addTargetToSortList(NULL, tle, + sortlist, targetlist, + SORTBY_DEFAULT, + SORTBY_NULLS_DEFAULT, + NIL, false); + } + return sortlist; +} + /* * find_all_inheritors - |
