diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index 2e8ff509dc2..dd3d7498250 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -13,8 +13,6 @@ #include "postgres.h" -#include - #include "access/clog.h" #include "access/commit_ts.h" #include "access/subtrans.h" @@ -26,7 +24,6 @@ #include "postmaster/autovacuum.h" #include "storage/pmsignal.h" #include "storage/proc.h" -#include "utils/guc.h" #include "utils/syscache.h" diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c index e7173f2783e..d5be92fd4f1 100644 --- a/src/backend/catalog/catalog.c +++ b/src/backend/catalog/catalog.c @@ -56,12 +56,6 @@ IsToastClassHookType IsToastClassHook; GetNewTempObjectId_hook_type GetNewTempObjectId_hook; GetNewTempOidWithIndex_hook_type GetNewTempOidWithIndex_hook; -GetNewPermanentRelFileNode_hook_type GetNewPermanentRelFileNode_hook; - -/* - * Temp tables in BBF should use the OID buffer. - */ -#define USE_BBF_OID_BUFFER (relpersistence == RELPERSISTENCE_TEMP && sql_dialect == SQL_DIALECT_TSQL && GetNewTempOidWithIndex_hook && temp_oid_buffer_size > 0) /* * Parameters to determine when to emit a log message in @@ -523,7 +517,7 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn) * created by bootstrap have preassigned OIDs, so there's no need. */ Oid -GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence) +GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence, bool override_temp) { RelFileNodeBackend rnode; char *rpath; @@ -563,6 +557,8 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence) */ rnode.backend = backend; + bool use_bbf_oid_buffer = (relpersistence == RELPERSISTENCE_TEMP && sql_dialect == SQL_DIALECT_TSQL && GetNewTempOidWithIndex_hook && temp_oid_buffer_size > 0 && !override_temp); + do { CHECK_FOR_INTERRUPTS(); @@ -571,7 +567,7 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence) if (pg_class) { /* Temp tables use temp OID logic */ - if (USE_BBF_OID_BUFFER) + if (use_bbf_oid_buffer) rnode.node.relNode = GetNewTempOidWithIndex_hook(pg_class, ClassOidIndexId, Anum_pg_class_oid); else @@ -581,7 +577,7 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence) else { /* Temp tables use temp OID logic */ - if (USE_BBF_OID_BUFFER) + if (use_bbf_oid_buffer) rnode.node.relNode = GetNewTempObjectId_hook(); else rnode.node.relNode = GetNewObjectId(); @@ -607,7 +603,7 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence) collides = false; } - if (USE_BBF_OID_BUFFER && tries > temp_oid_buffer_size) + if (use_bbf_oid_buffer && tries > temp_oid_buffer_size) ereport(ERROR, (errmsg("Unable to allocate oid for temp table. Drop some temporary tables or start a new session."))); diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 2c20cbe0dd5..5b03c59beb8 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -1307,7 +1307,7 @@ heap_create_with_catalog(const char *relname, if (!OidIsValid(relid)) relid = GetNewRelFileNode(reltablespace, pg_class_desc, - relpersistence); + relpersistence, false); } /* diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 10a5f6d0c08..7f6e101516f 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -950,12 +950,12 @@ index_create(Relation heapRelation, } else { - /* Index OIDs must be kept in normal OID range. */ - if (is_enr && GetNewPermanentRelFileNode_hook) - indexRelationId = GetNewPermanentRelFileNode_hook(tableSpaceId, pg_class, relpersistence); - else - indexRelationId = - GetNewRelFileNode(tableSpaceId, pg_class, relpersistence); + /* + * Index OIDs must be kept in normal OID range due to deletion issues. + * Since deletion is sorted by OID, adding indexes to temp OID range + * causes deletion order issues. + */ + indexRelationId = GetNewRelFileNode(tableSpaceId, pg_class, relpersistence, is_enr); } } diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index b4a7d978257..88818af9874 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -14582,7 +14582,7 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode) * to allocate a new one in the new tablespace. */ newrelfilenode = GetNewRelFileNode(newTableSpace, NULL, - rel->rd_rel->relpersistence); + rel->rd_rel->relpersistence, false); /* Open old and new relation */ newrnode = rel->rd_node; diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 41d71abc0e6..b0126dfd5e1 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -3735,7 +3735,7 @@ RelationSetNewRelfilenode(Relation relation, char persistence) { /* Allocate a new relfilenode */ newrelfilenode = GetNewRelFileNode(relation->rd_rel->reltablespace, - NULL, persistence); + NULL, persistence, false); } else if (relation->rd_rel->relkind == RELKIND_INDEX) { diff --git a/src/include/access/transam.h b/src/include/access/transam.h index c3e70d31094..45bc724ce88 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -253,12 +253,11 @@ typedef struct VariableCacheData TransactionId oldestClogXid; /* oldest it's safe to look up in clog */ /* - * These fields are also protected by OidGenLock. For tempOidStart, Shmem will + * This field is also protected by OidGenLock. For tempOidStart, Shmem will * be the source of truth, as another process may have gotten there first and * updated the start. */ Oid tempOidStart; - uint32 tempOidBufferSize; } VariableCacheData; typedef VariableCacheData *VariableCache; diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index 536f64b85d7..5652f931f9f 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -39,7 +39,7 @@ extern bool IsPinnedObject(Oid classId, Oid objectId); extern Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn); extern Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class, - char relpersistence); + char relpersistence, bool override_temp); typedef Oid (*GetNewTempObjectId_hook_type) (void); extern GetNewTempObjectId_hook_type GetNewTempObjectId_hook; @@ -47,9 +47,6 @@ extern GetNewTempObjectId_hook_type GetNewTempObjectId_hook; typedef Oid (*GetNewTempOidWithIndex_hook_type) (Relation relation, Oid indexId, AttrNumber oidcolumn); extern GetNewTempOidWithIndex_hook_type GetNewTempOidWithIndex_hook; -typedef Oid (*GetNewPermanentRelFileNode_hook_type) (Oid reltablespace, Relation pg_class, char relpersistence); -extern GetNewPermanentRelFileNode_hook_type GetNewPermanentRelFileNode_hook; - typedef bool (*IsExtendedCatalogHookType) (Oid relationId); extern IsExtendedCatalogHookType IsExtendedCatalogHook;