Skip to content

Commit

Permalink
Remove ability to alter buffer size GUC, correct error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
timchang514 committed Oct 18, 2023
1 parent 06ab0d8 commit 1656469
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 56 deletions.
12 changes: 4 additions & 8 deletions src/backend/access/transam/varsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,13 @@ GetNewTempObjectId(void)
temp_oid_buffer_start = tempOidStart + INT_MIN;
ShmemVariableCache->tempOidStart = tempOidStart;
ShmemVariableCache->tempOidBufferSize = temp_oid_buffer_size;
TempVariableCache = (VariableCache) palloc0(sizeof(*TempVariableCache));

TempVariableCache->nextOid = (Oid) tempOidStart;
nextTempOid = (Oid) tempOidStart;

result = tempOidStart;
}
LWLockRelease(OidGenLock);
}

real_temp_oid_buffer_start = temp_oid_buffer_start + INT_MIN;
real_temp_oid_buffer_start = temp_oid_buffer_start - INT_MIN;

/*
* Check for wraparound of the temp OID buffer.
Expand Down Expand Up @@ -605,10 +601,10 @@ GetNewObjectId(void)

/* If we're in tempOid buffer range, skip ahead. */
if (OidIsValid(temp_oid_buffer_start)
&& ShmemVariableCache->nextOid >= (Oid) (temp_oid_buffer_start + INT_MIN)
&& ShmemVariableCache->nextOid < (Oid) (temp_oid_buffer_start + temp_oid_buffer_size + INT_MIN))
&& ShmemVariableCache->nextOid >= (Oid) (temp_oid_buffer_start - INT_MIN)
&& ShmemVariableCache->nextOid < (Oid) (temp_oid_buffer_start + temp_oid_buffer_size - INT_MIN))
{
ShmemVariableCache->nextOid = (Oid) (temp_oid_buffer_start + temp_oid_buffer_size + INT_MIN);
ShmemVariableCache->nextOid = (Oid) (temp_oid_buffer_start + temp_oid_buffer_size - INT_MIN);
}

/*
Expand Down
61 changes: 14 additions & 47 deletions src/backend/catalog/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,7 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
{
CHECK_FOR_INTERRUPTS();

if (relation->rd_rel->relpersistence == RELPERSISTENCE_TEMP && sql_dialect == SQL_DIALECT_TSQL)
{
/* Temp tables use temp OID logic */
newOid = GetNewTempObjectId();
}
else
{
newOid = GetNewObjectId();
}
newOid = GetNewObjectId();

ScanKeyInit(&key,
oidcolumn,
Expand All @@ -451,14 +443,12 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)

/* see notes above about using SnapshotAny */
scan = systable_beginscan(relation, indexId, true,
SnapshotAny, 1, &key);
SnapshotAny, 1, &key);

collides = HeapTupleIsValid(systable_getnext(scan));

systable_endscan(scan);



/*
* Log that we iterate more than GETNEWOID_LOG_THRESHOLD but have not
* yet found OID unused in the relation. Then repeat logging with
Expand Down Expand Up @@ -515,7 +505,6 @@ GetNewTempOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
ScanKeyData key;
bool collides;
uint64 retries = 0;
uint64 retries_before_log = GETNEWOID_LOG_THRESHOLD;

/* Only system relations are supported */
Assert(IsSystemRelation(relation));
Expand All @@ -538,7 +527,6 @@ GetNewTempOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
CHECK_FOR_INTERRUPTS();

newOid = GetNewTempObjectId();
// elog(WARNING, "GetNewTempOidWithIndex got a newOid of %d for indexId %d", newOid, indexId);

ScanKeyInit(&key,
oidcolumn,
Expand All @@ -547,14 +535,12 @@ GetNewTempOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)

/* see notes above about using SnapshotAny */
scan = systable_beginscan(relation, indexId, true,
SnapshotAny, 1, &key);
SnapshotAny, 1, &key);

collides = HeapTupleIsValid(systable_getnext(scan));

systable_endscan(scan);



/*
* Log that we iterate more than GETNEWOID_LOG_THRESHOLD but have not
* yet found OID unused in the relation. Then repeat logging with
Expand All @@ -564,42 +550,15 @@ GetNewTempOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
* logic is necessary not to fill up the server log with the similar
* messages.
*/
if (retries >= retries_before_log)
if (OidIsValid((Oid) temp_oid_buffer_start) && retries >= temp_oid_buffer_size)
{
ereport(LOG,
(errmsg("still searching for an unused OID in relation \"%s\"",
RelationGetRelationName(relation)),
errdetail_plural("OID candidates have been checked %llu time, but no unused OID has been found yet.",
"OID candidates have been checked %llu times, but no unused OID has been found yet.",
retries,
(unsigned long long) retries)));

/*
* Double the number of retries to do before logging next until it
* reaches GETNEWOID_LOG_MAX_INTERVAL.
*/
if (retries_before_log * 2 <= GETNEWOID_LOG_MAX_INTERVAL)
retries_before_log *= 2;
else
retries_before_log += GETNEWOID_LOG_MAX_INTERVAL;
ereport(ERROR,
(errmsg("Unable to allocate oid for temp table. Drop some temporary tables or start a new session.")));
}

retries++;
} while (collides);

/*
* If at least one log message is emitted, also log the completion of OID
* assignment.
*/
if (retries > GETNEWOID_LOG_THRESHOLD)
{
ereport(LOG,
(errmsg_plural("new OID has been assigned in relation \"%s\" after %llu retry",
"new OID has been assigned in relation \"%s\" after %llu retries",
retries,
RelationGetRelationName(relation), (unsigned long long) retries)));
}

return newOid;
}

Expand All @@ -626,6 +585,7 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
char *rpath;
bool collides;
BackendId backend;
int tries = 0;

/*
* If we ever get here during pg_upgrade, there's something wrong; all
Expand Down Expand Up @@ -711,7 +671,14 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
collides = false;
}

if (OidIsValid((Oid) temp_oid_buffer_start) && tries > temp_oid_buffer_size)
{
ereport(ERROR,
(errmsg("Unable to allocate oid for temp table. Drop some temporary tables or start a new session.")));
}

pfree(rpath);
tries++;
} while (collides);

return rnode.node.relNode;
Expand Down
5 changes: 4 additions & 1 deletion src/backend/catalog/toasting.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
/*
* Create the toast table and its index
*/
if (sql_dialect == SQL_DIALECT_TSQL && (RelationIsBBFTableVariable(rel) || RelationIsBBFTempTable(rel)))
if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTableVariable(rel))
pg_toast_prefix = "@pg_toast";

if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTempTable(rel))
pg_toast_prefix = "#pg_toast";

snprintf(toast_relname, sizeof(toast_relname),
"%s_%u", pg_toast_prefix, relOid);
snprintf(toast_idxname, sizeof(toast_idxname),
Expand Down

0 comments on commit 1656469

Please sign in to comment.