diff options
Diffstat (limited to 'src/backend/parser/parse_relation.c')
-rw-r--r-- | src/backend/parser/parse_relation.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 77a48b039d9..4dd81507a78 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -1044,6 +1044,7 @@ static void buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref) { int maxattrs = tupdesc->natts; + List *aliaslist; ListCell *aliaslc; int numaliases; int varattno; @@ -1053,13 +1054,15 @@ buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref) if (alias) { - aliaslc = list_head(alias->colnames); - numaliases = list_length(alias->colnames); + aliaslist = alias->colnames; + aliaslc = list_head(aliaslist); + numaliases = list_length(aliaslist); /* We'll rebuild the alias colname list */ alias->colnames = NIL; } else { + aliaslist = NIL; aliaslc = NULL; numaliases = 0; } @@ -1081,7 +1084,7 @@ buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref) { /* Use the next user-supplied alias */ attrname = (Value *) lfirst(aliaslc); - aliaslc = lnext(aliaslc); + aliaslc = lnext(aliaslist, aliaslc); alias->colnames = lappend(alias->colnames, attrname); } else @@ -2287,7 +2290,7 @@ expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, *colvars = lappend(*colvars, varnode); } - aliasp_item = lnext(aliasp_item); + aliasp_item = lnext(rte->eref->colnames, aliasp_item); } } break; @@ -2514,7 +2517,7 @@ expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, *colnames = lappend(*colnames, makeString(pstrdup(""))); - aliasp_item = lnext(aliasp_item); + aliasp_item = lnext(rte->eref->colnames, aliasp_item); } if (colvars) @@ -2586,19 +2589,11 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, int location, bool include_dropped, List **colnames, List **colvars) { - ListCell *aliascell = list_head(eref->colnames); + ListCell *aliascell; int varattno; - if (colnames) - { - int i; - - for (i = 0; i < offset; i++) - { - if (aliascell) - aliascell = lnext(aliascell); - } - } + aliascell = (offset < list_length(eref->colnames)) ? + list_nth_cell(eref->colnames, offset) : NULL; Assert(count <= tupdesc->natts); for (varattno = 0; varattno < count; varattno++) @@ -2622,7 +2617,7 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, } } if (aliascell) - aliascell = lnext(aliascell); + aliascell = lnext(eref->colnames, aliascell); continue; } @@ -2633,7 +2628,7 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, if (aliascell) { label = strVal(lfirst(aliascell)); - aliascell = lnext(aliascell); + aliascell = lnext(eref->colnames, aliascell); } else { |