@@ -222,7 +222,7 @@ register_ENR(QueryEnvironment *queryEnv, EphemeralNamedRelation enr)
222222 * as false, same as parent since table variable don't follow transactional
223223 * semantics.
224224 */
225- EphemeralNamedRelation parent_enr = GetENRTempTableWithOid (enr -> md .parent_oid );
225+ EphemeralNamedRelation parent_enr = GetENRTempTableWithOid (enr -> md .parent_oid , true );
226226 if (parent_enr )
227227 enr -> md .is_bbf_temp_table = parent_enr -> md .is_bbf_temp_table ;
228228 else
@@ -316,19 +316,26 @@ get_ENR(QueryEnvironment *queryEnv, const char *name, bool search)
316316 * Same as get_ENR() but just search for relation oid
317317 */
318318EphemeralNamedRelation
319- get_ENR_withoid (QueryEnvironment * queryEnv , Oid id , EphemeralNameRelationType type )
319+ get_ENR_withoid (QueryEnvironment * queryEnv , Oid id , EphemeralNameRelationType type , bool recurse )
320320{
321321 ListCell * lc ;
322+ QueryEnvironment * qe = queryEnv ;
322323
323324 if (queryEnv == NULL || !OidIsValid (id ))
324325 return NULL ;
325326
326- foreach ( lc , queryEnv -> namedRelList )
327+ while ( qe )
327328 {
328- EphemeralNamedRelation enr = (EphemeralNamedRelation ) lfirst (lc );
329+ foreach (lc , qe -> namedRelList )
330+ {
331+ EphemeralNamedRelation enr = (EphemeralNamedRelation ) lfirst (lc );
329332
330- if (enr -> md .reliddesc == id && enr -> md .enrtype == type )
331- return enr ;
333+ if (enr -> md .reliddesc == id && enr -> md .enrtype == type )
334+ return enr ;
335+ }
336+ if (!recurse )
337+ break ;
338+ qe = qe -> parentEnv ;
332339 }
333340
334341 return NULL ;
@@ -339,9 +346,9 @@ get_ENR_withoid(QueryEnvironment *queryEnv, Oid id, EphemeralNameRelationType ty
339346 * provided arguments of currentQueryEnv and ENR_TSQL_TEMP.
340347 */
341348EphemeralNamedRelation
342- GetENRTempTableWithOid (Oid id )
349+ GetENRTempTableWithOid (Oid id , bool recurse )
343350{
344- return get_ENR_withoid (currentQueryEnv , id , ENR_TSQL_TEMP );
351+ return get_ENR_withoid (currentQueryEnv , id , ENR_TSQL_TEMP , recurse );
345352}
346353
347354/*
@@ -821,7 +828,7 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
821828 switch (catalog_oid ) {
822829 case RelationRelationId :
823830 rel_oid = ((Form_pg_class ) GETSTRUCT (tup ))-> oid ;
824- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
831+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
825832 list_ptr = & enr -> md .cattups [ENR_CATTUP_CLASS ];
826833 lc = list_head (enr -> md .cattups [ENR_CATTUP_CLASS ]);
827834 ret = true;
@@ -883,7 +890,7 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
883890 {
884891 Form_pg_shdepend tf1 = (Form_pg_shdepend ) GETSTRUCT ((HeapTuple )tup );
885892 rel_oid = ((Form_pg_shdepend ) GETSTRUCT (tup ))-> objid ;
886- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
893+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
887894 ListCell * curlc ;
888895 Form_pg_shdepend tf2 ; /* tuple forms*/
889896
@@ -916,7 +923,7 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
916923 }
917924 case IndexRelationId :
918925 rel_oid = ((Form_pg_index ) GETSTRUCT (tup ))-> indrelid ;
919- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
926+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
920927 list_ptr = & enr -> md .cattups [ENR_CATTUP_INDEX ];
921928 lc = list_head (enr -> md .cattups [ENR_CATTUP_INDEX ]);
922929 ret = true;
@@ -934,7 +941,7 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
934941 /* Composite type */
935942 if (((Form_pg_type ) GETSTRUCT (tup ))-> typelem == InvalidOid ) {
936943 rel_oid = ((Form_pg_type ) GETSTRUCT (tup ))-> typrelid ;
937- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
944+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
938945 list_ptr = & enr -> md .cattups [ENR_CATTUP_TYPE ];
939946 lc = list_head (enr -> md .cattups [ENR_CATTUP_TYPE ]);
940947 ret = true;
@@ -970,7 +977,7 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
970977 break ;
971978 case AttributeRelationId :
972979 rel_oid = ((Form_pg_attribute ) GETSTRUCT (tup ))-> attrelid ;
973- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
980+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
974981 ListCell * curlc ;
975982 Form_pg_attribute tf1 , tf2 ; /* tuple forms*/
976983
@@ -997,7 +1004,7 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
9971004 break ;
9981005 case ConstraintRelationId :
9991006 rel_oid = ((Form_pg_constraint ) GETSTRUCT (tup ))-> conrelid ;
1000- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
1007+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
10011008 Form_pg_constraint tf1 , tf2 ; /* tuple forms*/
10021009 ListCell * curlc ;
10031010
@@ -1016,7 +1023,7 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
10161023 break ;
10171024 case StatisticRelationId :
10181025 rel_oid = ((Form_pg_statistic ) GETSTRUCT (tup ))-> starelid ;
1019- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
1026+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
10201027 Form_pg_statistic tf1 , tf2 ; /* tuple forms*/
10211028 ListCell * curlc ;
10221029
@@ -1035,7 +1042,7 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
10351042 break ;
10361043 case StatisticExtRelationId :
10371044 rel_oid = ((Form_pg_statistic_ext ) GETSTRUCT (tup ))-> stxrelid ;
1038- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
1045+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
10391046 Form_pg_statistic_ext tf1 , tf2 ; /* tuple forms*/
10401047 ListCell * curlc ;
10411048
@@ -1054,15 +1061,15 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
10541061 break ;
10551062 case SequenceRelationId :
10561063 rel_oid = ((Form_pg_sequence ) GETSTRUCT (tup ))-> seqrelid ;
1057- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
1064+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
10581065 list_ptr = & enr -> md .cattups [ENR_CATTUP_SEQUENCE ];
10591066 lc = list_head (enr -> md .cattups [ENR_CATTUP_SEQUENCE ]);
10601067 ret = true;
10611068 }
10621069 break ;
10631070 case AttrDefaultRelationId :
10641071 rel_oid = ((Form_pg_attrdef ) GETSTRUCT (tup ))-> adrelid ;
1065- if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP ))) {
1072+ if ((enr = get_ENR_withoid (queryEnv , rel_oid , ENR_TSQL_TEMP , false ))) {
10661073 list_ptr = & enr -> md .cattups [ENR_CATTUP_ATTR_DEF_REL ];
10671074 lc = list_head (enr -> md .cattups [ENR_CATTUP_ATTR_DEF_REL ]);
10681075 ret = true;
@@ -1143,7 +1150,7 @@ static EphemeralNamedRelation find_enr(Form_pg_depend entry)
11431150 * to register the dependency of the ENR relation to this object.
11441151 */
11451152 case RelationRelationId :
1146- return get_ENR_withoid (queryEnv , entry -> objid , ENR_TSQL_TEMP );
1153+ return get_ENR_withoid (queryEnv , entry -> objid , ENR_TSQL_TEMP , false );
11471154
11481155 case TypeRelationId :
11491156 foreach (curlc , queryEnv -> namedRelList ) {
@@ -1171,7 +1178,7 @@ static EphemeralNamedRelation find_enr(Form_pg_depend entry)
11711178
11721179 case ConstraintRelationId :
11731180 case AttrDefaultRelationId :
1174- return get_ENR_withoid (queryEnv , entry -> refobjid , ENR_TSQL_TEMP );
1181+ return get_ENR_withoid (queryEnv , entry -> refobjid , ENR_TSQL_TEMP , false );
11751182
11761183 default :
11771184 break ;
@@ -1192,7 +1199,7 @@ void ENRDropEntry(Oid id)
11921199 if (sql_dialect != SQL_DIALECT_TSQL || !currentQueryEnv )
11931200 return ;
11941201
1195- if ((enr = GetENRTempTableWithOid (id )) == NULL )
1202+ if ((enr = GetENRTempTableWithOid (id , false )) == NULL )
11961203 return ;
11971204
11981205 oldcxt = MemoryContextSwitchTo (currentQueryEnv -> memctx );
@@ -1313,7 +1320,7 @@ void ENRDropCatalogEntry(Relation catalog_relation, Oid relid)
13131320 {
13141321 switch (catalog_oid ) {
13151322 case AttributeRelationId :
1316- if ((enr = get_ENR_withoid (queryEnv , relid , ENR_TSQL_TEMP ))) {
1323+ if ((enr = get_ENR_withoid (queryEnv , relid , ENR_TSQL_TEMP , false ))) {
13171324 list_ptr = & enr -> md .cattups [ENR_CATTUP_ATTRIBUTE ];
13181325 ret = true;
13191326 }
@@ -1706,7 +1713,7 @@ ENRRollbackUncommittedTuple(QueryEnvironment *queryEnv, ENRUncommittedTuple unco
17061713 */
17071714
17081715 Form_pg_index idx_form = (Form_pg_index ) GETSTRUCT (uncommitted_tup -> tup );
1709- if (get_ENR_withoid (queryEnv , idx_form -> indrelid , ENR_TSQL_TEMP ))
1716+ if (get_ENR_withoid (queryEnv , idx_form -> indrelid , ENR_TSQL_TEMP , false ))
17101717 {
17111718 skip_cache_inval = true;
17121719 }
@@ -1838,7 +1845,7 @@ bool UseTempOidBuffer()
18381845bool UseTempOidBufferForOid (Oid relId )
18391846{
18401847 return UseTempOidBuffer ()
1841- && GetENRTempTableWithOid (relId );
1848+ && GetENRTempTableWithOid (relId , false );
18421849}
18431850
18441851bool has_existing_enr_relations ()
0 commit comments