@@ -65,6 +65,7 @@ static ParseNamespaceItem *scanNameSpaceForRelid(ParseState *pstate, Oid relid,
6565static void check_lateral_ref_ok (ParseState * pstate , ParseNamespaceItem * nsitem ,
6666 int location );
6767static int scanRTEForColumn (ParseState * pstate , RangeTblEntry * rte ,
68+ Alias * eref ,
6869 const char * colname , int location ,
6970 int fuzzy_rte_penalty ,
7071 FuzzyAttrMatchState * fuzzystate );
@@ -184,7 +185,6 @@ scanNameSpaceForRefname(ParseState *pstate, const char *refname, int location)
184185 foreach (l , pstate -> p_namespace )
185186 {
186187 ParseNamespaceItem * nsitem = (ParseNamespaceItem * ) lfirst (l );
187- RangeTblEntry * rte = nsitem -> p_rte ;
188188
189189 /* Ignore columns-only items */
190190 if (!nsitem -> p_rel_visible )
@@ -193,7 +193,7 @@ scanNameSpaceForRefname(ParseState *pstate, const char *refname, int location)
193193 if (nsitem -> p_lateral_only && !pstate -> p_lateral_active )
194194 continue ;
195195
196- if (strcmp (rte -> eref -> aliasname , refname ) == 0 )
196+ if (strcmp (nsitem -> p_names -> aliasname , refname ) == 0 )
197197 {
198198 if (result )
199199 ereport (ERROR ,
@@ -420,7 +420,7 @@ checkNameSpaceConflicts(ParseState *pstate, List *namespace1,
420420 {
421421 ParseNamespaceItem * nsitem1 = (ParseNamespaceItem * ) lfirst (l1 );
422422 RangeTblEntry * rte1 = nsitem1 -> p_rte ;
423- const char * aliasname1 = rte1 -> eref -> aliasname ;
423+ const char * aliasname1 = nsitem1 -> p_names -> aliasname ;
424424 ListCell * l2 ;
425425
426426 if (!nsitem1 -> p_rel_visible )
@@ -430,10 +430,11 @@ checkNameSpaceConflicts(ParseState *pstate, List *namespace1,
430430 {
431431 ParseNamespaceItem * nsitem2 = (ParseNamespaceItem * ) lfirst (l2 );
432432 RangeTblEntry * rte2 = nsitem2 -> p_rte ;
433+ const char * aliasname2 = nsitem2 -> p_names -> aliasname ;
433434
434435 if (!nsitem2 -> p_rel_visible )
435436 continue ;
436- if (strcmp (rte2 -> eref -> aliasname , aliasname1 ) != 0 )
437+ if (strcmp (aliasname2 , aliasname1 ) != 0 )
437438 continue ; /* definitely no conflict */
438439 if (rte1 -> rtekind == RTE_RELATION && rte1 -> alias == NULL &&
439440 rte2 -> rtekind == RTE_RELATION && rte2 -> alias == NULL &&
@@ -466,7 +467,7 @@ check_lateral_ref_ok(ParseState *pstate, ParseNamespaceItem *nsitem,
466467 {
467468 /* SQL:2008 demands this be an error, not an invisible item */
468469 RangeTblEntry * rte = nsitem -> p_rte ;
469- char * refname = rte -> eref -> aliasname ;
470+ char * refname = nsitem -> p_names -> aliasname ;
470471
471472 ereport (ERROR ,
472473 (errcode (ERRCODE_INVALID_COLUMN_REFERENCE ),
@@ -672,10 +673,10 @@ scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem,
672673 Var * var ;
673674
674675 /*
675- * Scan the RTE 's column names (or aliases) for a match. Complain if
676+ * Scan the nsitem 's column names (or aliases) for a match. Complain if
676677 * multiple matches.
677678 */
678- attnum = scanRTEForColumn (pstate , rte ,
679+ attnum = scanRTEForColumn (pstate , rte , nsitem -> p_names ,
679680 colname , location ,
680681 0 , NULL );
681682
@@ -712,7 +713,7 @@ scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem,
712713 (errcode (ERRCODE_UNDEFINED_COLUMN ),
713714 errmsg ("column \"%s\" of relation \"%s\" does not exist" ,
714715 colname ,
715- rte -> eref -> aliasname )));
716+ nsitem -> p_names -> aliasname )));
716717
717718 var = makeVar (nscol -> p_varno ,
718719 nscol -> p_varattno ,
@@ -765,6 +766,7 @@ scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem,
765766 */
766767static int
767768scanRTEForColumn (ParseState * pstate , RangeTblEntry * rte ,
769+ Alias * eref ,
768770 const char * colname , int location ,
769771 int fuzzy_rte_penalty ,
770772 FuzzyAttrMatchState * fuzzystate )
@@ -786,7 +788,7 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte,
786788 * Callers interested in finding match with shortest distance need to
787789 * defend against this directly, though.
788790 */
789- foreach (c , rte -> eref -> colnames )
791+ foreach (c , eref -> colnames )
790792 {
791793 const char * attcolname = strVal (lfirst (c ));
792794
@@ -970,7 +972,7 @@ searchRangeTableForCol(ParseState *pstate, const char *alias, const char *colnam
970972 * Scan for a matching column; if we find an exact match, we're
971973 * done. Otherwise, update fuzzystate.
972974 */
973- if (scanRTEForColumn (orig_pstate , rte , colname , location ,
975+ if (scanRTEForColumn (orig_pstate , rte , rte -> eref , colname , location ,
974976 fuzzy_rte_penalty , fuzzystate )
975977 && fuzzy_rte_penalty == 0 )
976978 {
@@ -1252,6 +1254,7 @@ buildNSItemFromTupleDesc(RangeTblEntry *rte, Index rtindex, TupleDesc tupdesc)
12521254
12531255 /* ... and build the nsitem */
12541256 nsitem = (ParseNamespaceItem * ) palloc (sizeof (ParseNamespaceItem ));
1257+ nsitem -> p_names = rte -> eref ;
12551258 nsitem -> p_rte = rte ;
12561259 nsitem -> p_rtindex = rtindex ;
12571260 nsitem -> p_nscolumns = nscolumns ;
@@ -1313,6 +1316,7 @@ buildNSItemFromLists(RangeTblEntry *rte, Index rtindex,
13131316
13141317 /* ... and build the nsitem */
13151318 nsitem = (ParseNamespaceItem * ) palloc (sizeof (ParseNamespaceItem ));
1319+ nsitem -> p_names = rte -> eref ;
13161320 nsitem -> p_rte = rte ;
13171321 nsitem -> p_rtindex = rtindex ;
13181322 nsitem -> p_nscolumns = nscolumns ;
@@ -2198,6 +2202,7 @@ addRangeTableEntryForJoin(ParseState *pstate,
21982202 * list --- caller must do that if appropriate.
21992203 */
22002204 nsitem = (ParseNamespaceItem * ) palloc (sizeof (ParseNamespaceItem ));
2205+ nsitem -> p_names = rte -> eref ;
22012206 nsitem -> p_rte = rte ;
22022207 nsitem -> p_rtindex = list_length (pstate -> p_rtable );
22032208 nsitem -> p_nscolumns = nscolumns ;
@@ -2356,7 +2361,7 @@ addRangeTableEntryForCTE(ParseState *pstate,
23562361 */
23572362 if (rte -> ctelevelsup > 0 )
23582363 for (int i = 0 ; i < n_dontexpand_columns ; i ++ )
2359- psi -> p_nscolumns [list_length (psi -> p_rte -> eref -> colnames ) - 1 - i ].p_dontexpand = true;
2364+ psi -> p_nscolumns [list_length (psi -> p_names -> colnames ) - 1 - i ].p_dontexpand = true;
23602365
23612366 return psi ;
23622367}
@@ -3037,7 +3042,7 @@ expandNSItemVars(ParseNamespaceItem *nsitem,
30373042 if (colnames )
30383043 * colnames = NIL ;
30393044 colindex = 0 ;
3040- foreach (lc , nsitem -> p_rte -> eref -> colnames )
3045+ foreach (lc , nsitem -> p_names -> colnames )
30413046 {
30423047 Value * colnameval = (Value * ) lfirst (lc );
30433048 const char * colname = strVal (colnameval );
0 commit comments