@@ -65,6 +65,7 @@ static ParseNamespaceItem *scanNameSpaceForRelid(ParseState *pstate, Oid relid,
65
65
static void check_lateral_ref_ok (ParseState * pstate , ParseNamespaceItem * nsitem ,
66
66
int location );
67
67
static int scanRTEForColumn (ParseState * pstate , RangeTblEntry * rte ,
68
+ Alias * eref ,
68
69
const char * colname , int location ,
69
70
int fuzzy_rte_penalty ,
70
71
FuzzyAttrMatchState * fuzzystate );
@@ -184,7 +185,6 @@ scanNameSpaceForRefname(ParseState *pstate, const char *refname, int location)
184
185
foreach (l , pstate -> p_namespace )
185
186
{
186
187
ParseNamespaceItem * nsitem = (ParseNamespaceItem * ) lfirst (l );
187
- RangeTblEntry * rte = nsitem -> p_rte ;
188
188
189
189
/* Ignore columns-only items */
190
190
if (!nsitem -> p_rel_visible )
@@ -193,7 +193,7 @@ scanNameSpaceForRefname(ParseState *pstate, const char *refname, int location)
193
193
if (nsitem -> p_lateral_only && !pstate -> p_lateral_active )
194
194
continue ;
195
195
196
- if (strcmp (rte -> eref -> aliasname , refname ) == 0 )
196
+ if (strcmp (nsitem -> p_names -> aliasname , refname ) == 0 )
197
197
{
198
198
if (result )
199
199
ereport (ERROR ,
@@ -420,7 +420,7 @@ checkNameSpaceConflicts(ParseState *pstate, List *namespace1,
420
420
{
421
421
ParseNamespaceItem * nsitem1 = (ParseNamespaceItem * ) lfirst (l1 );
422
422
RangeTblEntry * rte1 = nsitem1 -> p_rte ;
423
- const char * aliasname1 = rte1 -> eref -> aliasname ;
423
+ const char * aliasname1 = nsitem1 -> p_names -> aliasname ;
424
424
ListCell * l2 ;
425
425
426
426
if (!nsitem1 -> p_rel_visible )
@@ -430,10 +430,11 @@ checkNameSpaceConflicts(ParseState *pstate, List *namespace1,
430
430
{
431
431
ParseNamespaceItem * nsitem2 = (ParseNamespaceItem * ) lfirst (l2 );
432
432
RangeTblEntry * rte2 = nsitem2 -> p_rte ;
433
+ const char * aliasname2 = nsitem2 -> p_names -> aliasname ;
433
434
434
435
if (!nsitem2 -> p_rel_visible )
435
436
continue ;
436
- if (strcmp (rte2 -> eref -> aliasname , aliasname1 ) != 0 )
437
+ if (strcmp (aliasname2 , aliasname1 ) != 0 )
437
438
continue ; /* definitely no conflict */
438
439
if (rte1 -> rtekind == RTE_RELATION && rte1 -> alias == NULL &&
439
440
rte2 -> rtekind == RTE_RELATION && rte2 -> alias == NULL &&
@@ -466,7 +467,7 @@ check_lateral_ref_ok(ParseState *pstate, ParseNamespaceItem *nsitem,
466
467
{
467
468
/* SQL:2008 demands this be an error, not an invisible item */
468
469
RangeTblEntry * rte = nsitem -> p_rte ;
469
- char * refname = rte -> eref -> aliasname ;
470
+ char * refname = nsitem -> p_names -> aliasname ;
470
471
471
472
ereport (ERROR ,
472
473
(errcode (ERRCODE_INVALID_COLUMN_REFERENCE ),
@@ -672,10 +673,10 @@ scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem,
672
673
Var * var ;
673
674
674
675
/*
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
676
677
* multiple matches.
677
678
*/
678
- attnum = scanRTEForColumn (pstate , rte ,
679
+ attnum = scanRTEForColumn (pstate , rte , nsitem -> p_names ,
679
680
colname , location ,
680
681
0 , NULL );
681
682
@@ -712,7 +713,7 @@ scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem,
712
713
(errcode (ERRCODE_UNDEFINED_COLUMN ),
713
714
errmsg ("column \"%s\" of relation \"%s\" does not exist" ,
714
715
colname ,
715
- rte -> eref -> aliasname )));
716
+ nsitem -> p_names -> aliasname )));
716
717
717
718
var = makeVar (nscol -> p_varno ,
718
719
nscol -> p_varattno ,
@@ -765,6 +766,7 @@ scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem,
765
766
*/
766
767
static int
767
768
scanRTEForColumn (ParseState * pstate , RangeTblEntry * rte ,
769
+ Alias * eref ,
768
770
const char * colname , int location ,
769
771
int fuzzy_rte_penalty ,
770
772
FuzzyAttrMatchState * fuzzystate )
@@ -786,7 +788,7 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte,
786
788
* Callers interested in finding match with shortest distance need to
787
789
* defend against this directly, though.
788
790
*/
789
- foreach (c , rte -> eref -> colnames )
791
+ foreach (c , eref -> colnames )
790
792
{
791
793
const char * attcolname = strVal (lfirst (c ));
792
794
@@ -970,7 +972,7 @@ searchRangeTableForCol(ParseState *pstate, const char *alias, const char *colnam
970
972
* Scan for a matching column; if we find an exact match, we're
971
973
* done. Otherwise, update fuzzystate.
972
974
*/
973
- if (scanRTEForColumn (orig_pstate , rte , colname , location ,
975
+ if (scanRTEForColumn (orig_pstate , rte , rte -> eref , colname , location ,
974
976
fuzzy_rte_penalty , fuzzystate )
975
977
&& fuzzy_rte_penalty == 0 )
976
978
{
@@ -1252,6 +1254,7 @@ buildNSItemFromTupleDesc(RangeTblEntry *rte, Index rtindex, TupleDesc tupdesc)
1252
1254
1253
1255
/* ... and build the nsitem */
1254
1256
nsitem = (ParseNamespaceItem * ) palloc (sizeof (ParseNamespaceItem ));
1257
+ nsitem -> p_names = rte -> eref ;
1255
1258
nsitem -> p_rte = rte ;
1256
1259
nsitem -> p_rtindex = rtindex ;
1257
1260
nsitem -> p_nscolumns = nscolumns ;
@@ -1313,6 +1316,7 @@ buildNSItemFromLists(RangeTblEntry *rte, Index rtindex,
1313
1316
1314
1317
/* ... and build the nsitem */
1315
1318
nsitem = (ParseNamespaceItem * ) palloc (sizeof (ParseNamespaceItem ));
1319
+ nsitem -> p_names = rte -> eref ;
1316
1320
nsitem -> p_rte = rte ;
1317
1321
nsitem -> p_rtindex = rtindex ;
1318
1322
nsitem -> p_nscolumns = nscolumns ;
@@ -2198,6 +2202,7 @@ addRangeTableEntryForJoin(ParseState *pstate,
2198
2202
* list --- caller must do that if appropriate.
2199
2203
*/
2200
2204
nsitem = (ParseNamespaceItem * ) palloc (sizeof (ParseNamespaceItem ));
2205
+ nsitem -> p_names = rte -> eref ;
2201
2206
nsitem -> p_rte = rte ;
2202
2207
nsitem -> p_rtindex = list_length (pstate -> p_rtable );
2203
2208
nsitem -> p_nscolumns = nscolumns ;
@@ -2356,7 +2361,7 @@ addRangeTableEntryForCTE(ParseState *pstate,
2356
2361
*/
2357
2362
if (rte -> ctelevelsup > 0 )
2358
2363
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;
2360
2365
2361
2366
return psi ;
2362
2367
}
@@ -3037,7 +3042,7 @@ expandNSItemVars(ParseNamespaceItem *nsitem,
3037
3042
if (colnames )
3038
3043
* colnames = NIL ;
3039
3044
colindex = 0 ;
3040
- foreach (lc , nsitem -> p_rte -> eref -> colnames )
3045
+ foreach (lc , nsitem -> p_names -> colnames )
3041
3046
{
3042
3047
Value * colnameval = (Value * ) lfirst (lc );
3043
3048
const char * colname = strVal (colnameval );
0 commit comments