Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Chang <[email protected]>
  • Loading branch information
timchang514 committed Jan 10, 2024
1 parent b84858e commit 9fb4b0e
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 28 deletions.
3 changes: 0 additions & 3 deletions src/backend/access/transam/varsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#include "postgres.h"

#include <unistd.h>

#include "access/clog.h"
#include "access/commit_ts.h"
#include "access/subtrans.h"
Expand All @@ -26,7 +24,6 @@
#include "postmaster/autovacuum.h"
#include "storage/pmsignal.h"
#include "storage/proc.h"
#include "utils/guc.h"
#include "utils/syscache.h"


Expand Down
16 changes: 6 additions & 10 deletions src/backend/catalog/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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.")));

Expand Down
2 changes: 1 addition & 1 deletion src/backend/catalog/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ heap_create_with_catalog(const char *relname,

if (!OidIsValid(relid))
relid = GetNewRelFileNode(reltablespace, pg_class_desc,
relpersistence);
relpersistence, false);
}

/*
Expand Down
12 changes: 6 additions & 6 deletions src/backend/catalog/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/cache/relcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/include/access/transam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/include/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ 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;

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;

Expand Down

0 comments on commit 9fb4b0e

Please sign in to comment.