diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index e30ead3dfa8..2375bc2e3c4 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -521,25 +521,26 @@ GetNewTempObjectId(void) { Oid result; Oid tempOidStart; + Oid real_temp_oid_buffer_start; static Oid nextTempOid = InvalidOid; /* safety check, we should never get this far in a HS standby */ if (RecoveryInProgress()) elog(ERROR, "cannot assign OIDs during recovery"); - if (!OidIsValid((Oid) temp_oid_buffer_start)) /* If this is the first time initializing */ + if (!OidIsValid((Oid) temp_oid_buffer_start)) /* InvalidOid means it needs assigning */ { /* First check to see if another connection has already picked a start, then update. */ LWLockAcquire(OidGenLock, LW_EXCLUSIVE); if (OidIsValid(ShmemVariableCache->tempOidStart) && (ShmemVariableCache->tempOidBufferSize == temp_oid_buffer_size)) { /* If ShmemVariableCache->tempOidStart is valid, it could also mean the buffer size GUC has been altered, and we need to pick a new start. */ - temp_oid_buffer_start = ShmemVariableCache->tempOidStart; + temp_oid_buffer_start = ShmemVariableCache->tempOidStart + INT_MIN; nextTempOid = ShmemVariableCache->tempOidStart; } else { - /* The first time this is called, we need to pick a start for the buffer range. */ + /* We need to pick a new start for the buffer range. */ tempOidStart = ShmemVariableCache->nextOid; if (ShmemVariableCache->oidCount < temp_oid_buffer_size) ShmemVariableCache->oidCount = 0; @@ -551,7 +552,7 @@ GetNewTempObjectId(void) { tempOidStart = FirstNormalObjectId; } - temp_oid_buffer_start = tempOidStart; + temp_oid_buffer_start = tempOidStart + INT_MIN; ShmemVariableCache->tempOidStart = tempOidStart; ShmemVariableCache->tempOidBufferSize = temp_oid_buffer_size; TempVariableCache = (VariableCache) palloc0(sizeof(*TempVariableCache)); @@ -564,12 +565,14 @@ GetNewTempObjectId(void) LWLockRelease(OidGenLock); } + real_temp_oid_buffer_start = temp_oid_buffer_start + INT_MIN; + /* * Check for wraparound of the temp OID buffer. */ - if (nextTempOid >= (Oid) (temp_oid_buffer_start + temp_oid_buffer_size) || nextTempOid < (Oid) temp_oid_buffer_start) + if (nextTempOid >= (Oid) (real_temp_oid_buffer_start + temp_oid_buffer_size) || nextTempOid < (Oid) real_temp_oid_buffer_start) { - nextTempOid = (Oid) temp_oid_buffer_start; + nextTempOid = (Oid) real_temp_oid_buffer_start; } result = nextTempOid; @@ -593,6 +596,7 @@ Oid GetNewObjectId(void) { Oid result; + Oid real_temp_oid_buffer_start; /* safety check, we should never get this far in a HS standby */ if (RecoveryInProgress()) @@ -602,10 +606,10 @@ GetNewObjectId(void) /* If we're in tempOid buffer range, skip ahead. */ if (OidIsValid(temp_oid_buffer_start) - && ShmemVariableCache->nextOid >= temp_oid_buffer_start - && ShmemVariableCache->nextOid < (temp_oid_buffer_start + temp_oid_buffer_size)) + && ShmemVariableCache->nextOid >= (Oid) (temp_oid_buffer_start + INT_MIN) + && ShmemVariableCache->nextOid < (Oid) (temp_oid_buffer_start + temp_oid_buffer_size + INT_MIN)) { - ShmemVariableCache->nextOid = temp_oid_buffer_start + temp_oid_buffer_size; + ShmemVariableCache->nextOid = (Oid) (temp_oid_buffer_start + temp_oid_buffer_size + INT_MIN); } /* diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 1992b8b03bb..b18a3928302 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -695,7 +695,7 @@ int huge_pages; int huge_page_size; /* - * OIDs are stored as uint32, so we have to store it in a double. + * OIDs are stored as uint32, so we will add INT_MIN to match the range. */ int temp_oid_buffer_start; int temp_oid_buffer_size;