@@ -3819,15 +3819,14 @@ SetRelationTableSpace(Relation rel,
38193819 ItemPointerData otid;
38203820 Form_pg_class rd_rel;
38213821 Oid reloid = RelationGetRelid(rel);
3822- bool is_enr = (sql_dialect == SQL_DIALECT_TSQL && get_ENR_withoid(currentQueryEnv, reloid, ENR_TSQL_TEMP ));
3822+ bool is_enr = (sql_dialect == SQL_DIALECT_TSQL && GetENRTempTableWithOid( reloid));
38233823
38243824 Assert(CheckRelationTableSpaceMove(rel, newTableSpaceId));
38253825
38263826 /* Get a modifiable copy of the relation's pg_class row. */
38273827 pg_class = table_open(RelationRelationId, RowExclusiveLock);
3828-
38293828 if (is_enr)
3830- tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(reloid));
3829+ tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(reloid));
38313830 else
38323831 tuple = SearchSysCacheLockedCopy1(RELOID, ObjectIdGetDatum(reloid));
38333832 if (!HeapTupleIsValid(tuple))
@@ -3841,6 +3840,10 @@ SetRelationTableSpace(Relation rel,
38413840 if (RelFileNumberIsValid(newRelFilenumber))
38423841 rd_rel->relfilenode = newRelFilenumber;
38433842 CatalogTupleUpdate(pg_class, &otid, tuple);
3843+ /*
3844+ * ENR relations being backend-local are not locked
3845+ * and hence don't need to be unlocked
3846+ */
38443847 if (!is_enr)
38453848 UnlockTuple(pg_class, &otid, InplaceUpdateTupleLock);
38463849
@@ -4344,7 +4347,7 @@ RenameRelationInternal(Oid myrelid, const char *newrelname, bool is_internal, bo
43444347 HeapTuple reltup;
43454348 Form_pg_class relform;
43464349 Oid namespaceId;
4347- bool is_enr = (sql_dialect == SQL_DIALECT_TSQL && get_ENR_withoid(currentQueryEnv, myrelid, ENR_TSQL_TEMP ));
4350+ bool is_enr = (sql_dialect == SQL_DIALECT_TSQL && GetENRTempTableWithOid( myrelid));
43484351
43494352 /*
43504353 * Grab a lock on the target relation, which we will NOT release until end
@@ -4396,6 +4399,10 @@ RenameRelationInternal(Oid myrelid, const char *newrelname, bool is_internal, bo
43964399 namestrcpy(&(relform->relname), newrelname);
43974400
43984401 CatalogTupleUpdate(relrelation, &otid, reltup);
4402+ /*
4403+ * ENR relations being backend-local are not locked
4404+ * and hence don't need to be unlocked
4405+ */
43994406 if (!is_enr)
44004407 UnlockTuple(relrelation, &otid, InplaceUpdateTupleLock);
44014408
@@ -6220,7 +6227,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
62206227 BulkInsertState bistate;
62216228 int ti_options;
62226229 ExprState *partqualstate = NULL;
6223-
6230+
62246231 /*
62256232 * Open the relation(s). We have surely already locked the existing
62266233 * table.
@@ -6231,8 +6238,11 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
62316238
62326239 if (OidIsValid(OIDNewHeap))
62336240 {
6234- Assert(CheckRelationOidLockedByMe(OIDNewHeap, AccessExclusiveLock,
6235- false));
6241+ /*
6242+ * With ENRs, we don't hold locks on relation tuples.
6243+ */
6244+ Assert((sql_dialect == SQL_DIALECT_TSQL && GetENRTempTableWithOid(OIDNewHeap))
6245+ || CheckRelationOidLockedByMe(OIDNewHeap, AccessExclusiveLock,false));
62366246 newrel = table_open(OIDNewHeap, NoLock);
62376247 }
62386248 else
@@ -16770,7 +16780,7 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation,
1677016780
1677116781 /* Fetch heap tuple */
1677216782 relid = RelationGetRelid(rel);
16773- is_enr = (sql_dialect == SQL_DIALECT_TSQL && get_ENR_withoid(currentQueryEnv, relid, ENR_TSQL_TEMP ));
16783+ is_enr = (sql_dialect == SQL_DIALECT_TSQL && GetENRTempTableWithOid( relid));
1677416784 if (is_enr)
1677516785 tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
1677616786 else
@@ -19172,13 +19182,13 @@ AlterRelationNamespaceInternal(Relation classRel, Oid relOid,
1917219182 Form_pg_class classForm;
1917319183 ObjectAddress thisobj;
1917419184 bool already_done = false;
19175- bool is_enr = (sql_dialect == SQL_DIALECT_TSQL && get_ENR_withoid(currentQueryEnv, relOid, ENR_TSQL_TEMP ));
19185+ bool is_enr = (sql_dialect == SQL_DIALECT_TSQL && GetENRTempTableWithOid( relOid));
1917619186
19177- /* no rel lock for relkind=c so use LOCKTAG_TUPLE */
1917819187 if (is_enr)
1917919188 classTup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relOid));
19180- else
19189+ else /* no rel lock for relkind=c so use LOCKTAG_TUPLE */
1918119190 classTup = SearchSysCacheLockedCopy1(RELOID, ObjectIdGetDatum(relOid));
19191+
1918219192 if (!HeapTupleIsValid(classTup))
1918319193 elog(ERROR, "cache lookup failed for relation %u", relOid);
1918419194 classForm = (Form_pg_class) GETSTRUCT(classTup);
@@ -19212,22 +19222,30 @@ AlterRelationNamespaceInternal(Relation classRel, Oid relOid,
1921219222 classForm->relnamespace = newNspOid;
1921319223
1921419224 CatalogTupleUpdate(classRel, &otid, classTup);
19225+ /*
19226+ * ENR relations being backend-local are not locked
19227+ * and hence don't need to be unlocked
19228+ */
1921519229 if (!is_enr)
1921619230 UnlockTuple(classRel, &otid, InplaceUpdateTupleLock);
1921719231
19218-
19219- /* Update dependency on schema if caller said so */
1922019232 if (hasDependEntry &&
1922119233 changeDependencyFor(RelationRelationId,
1922219234 relOid,
1922319235 NamespaceRelationId,
19224- oldNspOid,
1922519236 newNspOid) != 1)
1922619237 elog(ERROR, "could not change schema dependency for relation \"%s\"",
1922719238 NameStr(classForm->relname));
1922819239 }
19229- else if (!is_enr)
19230- UnlockTuple(classRel, &classTup->t_self, InplaceUpdateTupleLock);
19240+ else
19241+ {
19242+ /*
19243+ * ENR relations being backend-local are not locked
19244+ * and hence don't need to be unlocked
19245+ */
19246+ if (!is_enr)
19247+ UnlockTuple(classRel, &classTup->t_self, InplaceUpdateTupleLock);
19248+ }
1923119249 if (!already_done)
1923219250 {
1923319251 add_exact_object_address(&thisobj, objsMoved);
0 commit comments