diff options
| author | Jan Wieck <JanWieck@Yahoo.com> | 1999-05-12 15:02:39 +0000 |
|---|---|---|
| committer | Jan Wieck <JanWieck@Yahoo.com> | 1999-05-12 15:02:39 +0000 |
| commit | 79c2576f775b962c67cac136722c5c7cc98201aa (patch) | |
| tree | 3da66174208ed6b258542dde2ba9f00c0e706c07 /src/backend/optimizer/prep | |
| parent | 1a87c14c9cf2c58009dd653c5356f68d605dff2f (diff) | |
| download | postgresql-79c2576f775b962c67cac136722c5c7cc98201aa.tar.gz | |
Replaced targetlist entry in GroupClause by reference number
in Resdom and GroupClause so changing of resno's doesn't confuse
the grouping any more.
Jan
Diffstat (limited to 'src/backend/optimizer/prep')
| -rw-r--r-- | src/backend/optimizer/prep/preptlist.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index 084809c9d9..5b70b368ca 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.18 1999/02/13 23:16:38 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.19 1999/05/12 15:01:41 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -229,6 +229,49 @@ replace_matching_resname(List *new_tlist, List *old_tlist) new_tl = makeTargetEntry(newresno, old_tle->expr); t_list = lappend(t_list, new_tl); } + + /* + * Also it is possible that the parser or rewriter added + * some junk attributes to hold GROUP BY expressions which + * are not part of the result attributes. + * We can simply identify them by looking at the resgroupref + * in the TLE's resdom, which is a unique number telling which + * TLE belongs to which GroupClause. + */ + if (old_tle->resdom->resgroupref > 0) + { + bool already_there = FALSE; + TargetEntry *new_tle; + Resdom *newresno; + + /* + * Check if the tle is already in the new list + */ + foreach(i, t_list) + { + new_tle = (TargetEntry *)lfirst(i); + + if (new_tle->resdom->resgroupref == + old_tle->resdom->resgroupref) + { + already_there = TRUE; + break; + } + + } + + /* + * If not, add it and make sure it is now a junk attribute + */ + if (!already_there) + { + newresno = (Resdom *) copyObject((Node *) old_tle->resdom); + newresno->resno = length(t_list) + 1; + newresno->resjunk = 1; + new_tl = makeTargetEntry(newresno, old_tle->expr); + t_list = lappend(t_list, new_tl); + } + } } return t_list; |
