Use table_openXXX methods in the codebase

With PG13 heap_* (heap_open, heap_close etc) are replaced with table_*
(table_open, table_close etc).

It is better to use the new table access methods in the codebase and
define the macros for the previous versions as we can easily remove the
macro without having to change the codebase when we drop the support for
the old version.

Commits that introduced this change on Postgres:
f25968c49697db673f6cd2a07b3f7626779f1827
e0c4ec07284db817e1f8d9adfb3fffc952252db0
4b21acf522d751ba5b6679df391d5121b6c4a35f

Command to see relevant commits on Postgres side:
git log --all --grep="heap_open"
pull/3900/head
Sait Talha Nisanci 2020-05-18 12:19:29 +03:00
parent 0819b79631
commit bf831d2e59
30 changed files with 191 additions and 175 deletions

View File

@ -571,7 +571,7 @@ ColocationIdForNewTable(Oid relationId, Var *distributionColumn,
*/ */
Assert(distributionMethod == DISTRIBUTE_BY_HASH); Assert(distributionMethod == DISTRIBUTE_BY_HASH);
Relation pgDistColocation = heap_open(DistColocationRelationId(), ExclusiveLock); Relation pgDistColocation = table_open(DistColocationRelationId(), ExclusiveLock);
Oid distributionColumnType = distributionColumn->vartype; Oid distributionColumnType = distributionColumn->vartype;
Oid distributionColumnCollation = get_typcollation(distributionColumnType); Oid distributionColumnCollation = get_typcollation(distributionColumnType);
@ -618,12 +618,12 @@ ColocationIdForNewTable(Oid relationId, Var *distributionColumn,
if (createdColocationGroup) if (createdColocationGroup)
{ {
/* keep the exclusive lock */ /* keep the exclusive lock */
heap_close(pgDistColocation, NoLock); table_close(pgDistColocation, NoLock);
} }
else else
{ {
/* release the exclusive lock */ /* release the exclusive lock */
heap_close(pgDistColocation, ExclusiveLock); table_close(pgDistColocation, ExclusiveLock);
} }
} }
@ -1266,7 +1266,7 @@ static void
CopyLocalDataIntoShards(Oid distributedRelationId) CopyLocalDataIntoShards(Oid distributedRelationId)
{ {
/* take an ExclusiveLock to block all operations except SELECT */ /* take an ExclusiveLock to block all operations except SELECT */
Relation distributedRelation = heap_open(distributedRelationId, ExclusiveLock); Relation distributedRelation = table_open(distributedRelationId, ExclusiveLock);
/* /*
* Skip copying from partitioned tables, we will copy the data from * Skip copying from partitioned tables, we will copy the data from
@ -1274,7 +1274,7 @@ CopyLocalDataIntoShards(Oid distributedRelationId)
*/ */
if (PartitionedTable(distributedRelationId)) if (PartitionedTable(distributedRelationId))
{ {
heap_close(distributedRelation, NoLock); table_close(distributedRelation, NoLock);
return; return;
} }
@ -1330,7 +1330,7 @@ CopyLocalDataIntoShards(Oid distributedRelationId)
/* free memory and close the relation */ /* free memory and close the relation */
ExecDropSingleTupleTableSlot(slot); ExecDropSingleTupleTableSlot(slot);
FreeExecutorState(estate); FreeExecutorState(estate);
heap_close(distributedRelation, NoLock); table_close(distributedRelation, NoLock);
PopActiveSnapshot(); PopActiveSnapshot();
} }

View File

@ -388,7 +388,7 @@ ColumnAppearsInForeignKeyToReferenceTable(char *columnName, Oid relationId)
int scanKeyCount = 1; int scanKeyCount = 1;
bool foreignKeyToReferenceTableIncludesGivenColumn = false; bool foreignKeyToReferenceTableIncludesGivenColumn = false;
Relation pgConstraint = heap_open(ConstraintRelationId, AccessShareLock); Relation pgConstraint = table_open(ConstraintRelationId, AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_constraint_contype, BTEqualStrategyNumber, ScanKeyInit(&scanKey[0], Anum_pg_constraint_contype, BTEqualStrategyNumber,
F_CHAREQ, CharGetDatum(CONSTRAINT_FOREIGN)); F_CHAREQ, CharGetDatum(CONSTRAINT_FOREIGN));
@ -446,7 +446,7 @@ ColumnAppearsInForeignKeyToReferenceTable(char *columnName, Oid relationId)
/* clean up scan and close system catalog */ /* clean up scan and close system catalog */
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgConstraint, NoLock); table_close(pgConstraint, NoLock);
return foreignKeyToReferenceTableIncludesGivenColumn; return foreignKeyToReferenceTableIncludesGivenColumn;
} }
@ -720,7 +720,7 @@ GetForeignKeyOids(Oid relationId, int flags)
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
int scanKeyCount = 1; int scanKeyCount = 1;
Relation pgConstraint = heap_open(ConstraintRelationId, AccessShareLock); Relation pgConstraint = table_open(ConstraintRelationId, AccessShareLock);
ScanKeyInit(&scanKey[0], pgConstraintTargetAttrNumber, ScanKeyInit(&scanKey[0], pgConstraintTargetAttrNumber,
BTEqualStrategyNumber, F_OIDEQ, relationId); BTEqualStrategyNumber, F_OIDEQ, relationId);
SysScanDesc scanDescriptor = systable_beginscan(pgConstraint, indexOid, useIndex, SysScanDesc scanDescriptor = systable_beginscan(pgConstraint, indexOid, useIndex,
@ -770,7 +770,7 @@ GetForeignKeyOids(Oid relationId, int flags)
* on pg_constraint to make sure that caller will process valid foreign key * on pg_constraint to make sure that caller will process valid foreign key
* constraints through the transaction. * constraints through the transaction.
*/ */
heap_close(pgConstraint, NoLock); table_close(pgConstraint, NoLock);
return foreignKeyOids; return foreignKeyOids;
} }

View File

@ -47,6 +47,7 @@
#include "distributed/multi_executor.h" #include "distributed/multi_executor.h"
#include "distributed/namespace_utils.h" #include "distributed/namespace_utils.h"
#include "distributed/relation_access_tracking.h" #include "distributed/relation_access_tracking.h"
#include "distributed/version_compat.h"
#include "distributed/worker_create_or_replace.h" #include "distributed/worker_create_or_replace.h"
#include "distributed/worker_transaction.h" #include "distributed/worker_transaction.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
@ -352,7 +353,7 @@ GetFunctionColocationId(Oid functionOid, char *colocateWithTableName,
Oid distributionArgumentOid) Oid distributionArgumentOid)
{ {
int colocationId = INVALID_COLOCATION_ID; int colocationId = INVALID_COLOCATION_ID;
Relation pgDistColocation = heap_open(DistColocationRelationId(), ShareLock); Relation pgDistColocation = table_open(DistColocationRelationId(), ShareLock);
if (pg_strncasecmp(colocateWithTableName, "default", NAMEDATALEN) == 0) if (pg_strncasecmp(colocateWithTableName, "default", NAMEDATALEN) == 0)
{ {
@ -400,7 +401,7 @@ GetFunctionColocationId(Oid functionOid, char *colocateWithTableName,
} }
/* keep the lock */ /* keep the lock */
heap_close(pgDistColocation, NoLock); table_close(pgDistColocation, NoLock);
return colocationId; return colocationId;
} }
@ -489,7 +490,7 @@ UpdateFunctionDistributionInfo(const ObjectAddress *distAddress,
bool isnull[Natts_pg_dist_object]; bool isnull[Natts_pg_dist_object];
bool replace[Natts_pg_dist_object]; bool replace[Natts_pg_dist_object];
Relation pgDistObjectRel = heap_open(DistObjectRelationId(), RowExclusiveLock); Relation pgDistObjectRel = table_open(DistObjectRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistObjectRel); TupleDesc tupleDescriptor = RelationGetDescr(pgDistObjectRel);
/* scan pg_dist_object for classid = $1 AND objid = $2 AND objsubid = $3 via index */ /* scan pg_dist_object for classid = $1 AND objid = $2 AND objsubid = $3 via index */
@ -549,7 +550,7 @@ UpdateFunctionDistributionInfo(const ObjectAddress *distAddress,
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistObjectRel, NoLock); table_close(pgDistObjectRel, NoLock);
} }

View File

@ -138,7 +138,7 @@ PreprocessIndexStmt(Node *node, const char *createIndexCommand)
* checked permissions, and will only fail when executing the actual * checked permissions, and will only fail when executing the actual
* index statements. * index statements.
*/ */
Relation relation = heap_openrv(createIndexStatement->relation, lockmode); Relation relation = table_openrv(createIndexStatement->relation, lockmode);
Oid relationId = RelationGetRelid(relation); Oid relationId = RelationGetRelid(relation);
bool isCitusRelation = IsCitusTable(relationId); bool isCitusRelation = IsCitusTable(relationId);
@ -160,7 +160,7 @@ PreprocessIndexStmt(Node *node, const char *createIndexCommand)
relationContext, namespaceName); relationContext, namespaceName);
} }
heap_close(relation, NoLock); table_close(relation, NoLock);
if (isCitusRelation) if (isCitusRelation)
{ {
@ -246,7 +246,7 @@ PreprocessReindexStmt(Node *node, const char *reindexCommand)
RangeVarGetRelidExtended(reindexStatement->relation, lockmode, 0, RangeVarGetRelidExtended(reindexStatement->relation, lockmode, 0,
RangeVarCallbackOwnsTable, NULL); RangeVarCallbackOwnsTable, NULL);
relation = heap_openrv(reindexStatement->relation, NoLock); relation = table_openrv(reindexStatement->relation, NoLock);
relationId = RelationGetRelid(relation); relationId = RelationGetRelid(relation);
} }
@ -275,7 +275,7 @@ PreprocessReindexStmt(Node *node, const char *reindexCommand)
} }
else else
{ {
heap_close(relation, NoLock); table_close(relation, NoLock);
} }
if (isCitusRelation) if (isCitusRelation)
@ -426,13 +426,13 @@ PostprocessIndexStmt(Node *node, const char *queryString)
StartTransactionCommand(); StartTransactionCommand();
/* get the affected relation and index */ /* get the affected relation and index */
Relation relation = heap_openrv(indexStmt->relation, ShareUpdateExclusiveLock); Relation relation = table_openrv(indexStmt->relation, ShareUpdateExclusiveLock);
Oid indexRelationId = get_relname_relid(indexStmt->idxname, Oid indexRelationId = get_relname_relid(indexStmt->idxname,
schemaId); schemaId);
Relation indexRelation = index_open(indexRelationId, RowExclusiveLock); Relation indexRelation = index_open(indexRelationId, RowExclusiveLock);
/* close relations but retain locks */ /* close relations but retain locks */
heap_close(relation, NoLock); table_close(relation, NoLock);
index_close(indexRelation, NoLock); index_close(indexRelation, NoLock);
/* mark index as invalid, in-place (cannot be rolled back) */ /* mark index as invalid, in-place (cannot be rolled back) */
@ -443,7 +443,7 @@ PostprocessIndexStmt(Node *node, const char *queryString)
StartTransactionCommand(); StartTransactionCommand();
/* now, update index's validity in a way that can roll back */ /* now, update index's validity in a way that can roll back */
Relation pg_index = heap_open(IndexRelationId, RowExclusiveLock); Relation pg_index = table_open(IndexRelationId, RowExclusiveLock);
HeapTuple indexTuple = SearchSysCacheCopy1(INDEXRELID, ObjectIdGetDatum( HeapTuple indexTuple = SearchSysCacheCopy1(INDEXRELID, ObjectIdGetDatum(
indexRelationId)); indexRelationId));
@ -457,7 +457,7 @@ PostprocessIndexStmt(Node *node, const char *queryString)
/* clean up; index now marked valid, but ROLLBACK will mark invalid */ /* clean up; index now marked valid, but ROLLBACK will mark invalid */
heap_freetuple(indexTuple); heap_freetuple(indexTuple);
heap_close(pg_index, RowExclusiveLock); table_close(pg_index, RowExclusiveLock);
return NIL; return NIL;
} }

View File

@ -34,6 +34,7 @@
#include "distributed/local_executor.h" #include "distributed/local_executor.h"
#include "distributed/local_multi_copy.h" #include "distributed/local_multi_copy.h"
#include "distributed/shard_utils.h" #include "distributed/shard_utils.h"
#include "distributed/version_compat.h"
static int ReadFromLocalBufferCallback(void *outBuf, int minRead, int maxRead); static int ReadFromLocalBufferCallback(void *outBuf, int minRead, int maxRead);
static void AddSlotToBuffer(TupleTableSlot *slot, CitusCopyDestReceiver *copyDest, static void AddSlotToBuffer(TupleTableSlot *slot, CitusCopyDestReceiver *copyDest,
@ -160,7 +161,7 @@ DoLocalCopy(StringInfo buffer, Oid relationId, int64 shardId, CopyStmt *copyStat
LocalCopyBuffer = buffer; LocalCopyBuffer = buffer;
Oid shardOid = GetTableLocalShardOid(relationId, shardId); Oid shardOid = GetTableLocalShardOid(relationId, shardId);
Relation shard = heap_open(shardOid, RowExclusiveLock); Relation shard = table_open(shardOid, RowExclusiveLock);
ParseState *pState = make_parsestate(NULL); ParseState *pState = make_parsestate(NULL);
/* p_rtable of pState is set so that we can check constraints. */ /* p_rtable of pState is set so that we can check constraints. */
@ -172,7 +173,7 @@ DoLocalCopy(StringInfo buffer, Oid relationId, int64 shardId, CopyStmt *copyStat
CopyFrom(cstate); CopyFrom(cstate);
EndCopyFrom(cstate); EndCopyFrom(cstate);
heap_close(shard, NoLock); table_close(shard, NoLock);
free_parsestate(pState); free_parsestate(pState);
} }

View File

@ -410,7 +410,7 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
ErrorContextCallback errorCallback; ErrorContextCallback errorCallback;
/* allocate column values and nulls arrays */ /* allocate column values and nulls arrays */
Relation distributedRelation = heap_open(tableId, RowExclusiveLock); Relation distributedRelation = table_open(tableId, RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(distributedRelation); TupleDesc tupleDescriptor = RelationGetDescr(distributedRelation);
uint32 columnCount = tupleDescriptor->natts; uint32 columnCount = tupleDescriptor->natts;
Datum *columnValues = palloc0(columnCount * sizeof(Datum)); Datum *columnValues = palloc0(columnCount * sizeof(Datum));
@ -545,7 +545,7 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
ExecDropSingleTupleTableSlot(tupleTableSlot); ExecDropSingleTupleTableSlot(tupleTableSlot);
FreeExecutorState(executorState); FreeExecutorState(executorState);
heap_close(distributedRelation, NoLock); table_close(distributedRelation, NoLock);
/* mark failed placements as inactive */ /* mark failed placements as inactive */
MarkFailedShardPlacements(); MarkFailedShardPlacements();
@ -568,7 +568,7 @@ static void
CopyToNewShards(CopyStmt *copyStatement, char *completionTag, Oid relationId) CopyToNewShards(CopyStmt *copyStatement, char *completionTag, Oid relationId)
{ {
/* allocate column values and nulls arrays */ /* allocate column values and nulls arrays */
Relation distributedRelation = heap_open(relationId, RowExclusiveLock); Relation distributedRelation = table_open(relationId, RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(distributedRelation); TupleDesc tupleDescriptor = RelationGetDescr(distributedRelation);
uint32 columnCount = tupleDescriptor->natts; uint32 columnCount = tupleDescriptor->natts;
Datum *columnValues = palloc0(columnCount * sizeof(Datum)); Datum *columnValues = palloc0(columnCount * sizeof(Datum));
@ -732,7 +732,7 @@ CopyToNewShards(CopyStmt *copyStatement, char *completionTag, Oid relationId)
} }
EndCopyFrom(copyState); EndCopyFrom(copyState);
heap_close(distributedRelation, NoLock); table_close(distributedRelation, NoLock);
/* check for cancellation one last time before returning */ /* check for cancellation one last time before returning */
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
@ -2138,7 +2138,7 @@ CitusCopyDestReceiverStartup(DestReceiver *dest, int operation,
const char *nullPrintCharacter = "\\N"; const char *nullPrintCharacter = "\\N";
/* look up table properties */ /* look up table properties */
Relation distributedRelation = heap_open(tableId, RowExclusiveLock); Relation distributedRelation = table_open(tableId, RowExclusiveLock);
CitusTableCacheEntry *cacheEntry = GetCitusTableCacheEntry(tableId); CitusTableCacheEntry *cacheEntry = GetCitusTableCacheEntry(tableId);
partitionMethod = cacheEntry->partitionMethod; partitionMethod = cacheEntry->partitionMethod;
@ -2626,7 +2626,7 @@ CitusCopyDestReceiverShutdown(DestReceiver *destReceiver)
} }
PG_END_TRY(); PG_END_TRY();
heap_close(distributedRelation, NoLock); table_close(distributedRelation, NoLock);
} }
@ -2801,7 +2801,7 @@ ProcessCopyStmt(CopyStmt *copyStatement, char *completionTag, const char *queryS
bool isFrom = copyStatement->is_from; bool isFrom = copyStatement->is_from;
/* consider using RangeVarGetRelidExtended to check perms before locking */ /* consider using RangeVarGetRelidExtended to check perms before locking */
Relation copiedRelation = heap_openrv(copyStatement->relation, Relation copiedRelation = table_openrv(copyStatement->relation,
isFrom ? RowExclusiveLock : isFrom ? RowExclusiveLock :
AccessShareLock); AccessShareLock);
@ -2816,7 +2816,7 @@ ProcessCopyStmt(CopyStmt *copyStatement, char *completionTag, const char *queryS
schemaName = MemoryContextStrdup(relationContext, schemaName); schemaName = MemoryContextStrdup(relationContext, schemaName);
copyStatement->relation->schemaname = schemaName; copyStatement->relation->schemaname = schemaName;
heap_close(copiedRelation, NoLock); table_close(copiedRelation, NoLock);
if (isCitusRelation) if (isCitusRelation)
{ {
@ -2875,7 +2875,7 @@ CitusCopySelect(CopyStmt *copyStatement)
SelectStmt *selectStmt = makeNode(SelectStmt); SelectStmt *selectStmt = makeNode(SelectStmt);
selectStmt->fromClause = list_make1(copyObject(copyStatement->relation)); selectStmt->fromClause = list_make1(copyObject(copyStatement->relation));
Relation distributedRelation = heap_openrv(copyStatement->relation, AccessShareLock); Relation distributedRelation = table_openrv(copyStatement->relation, AccessShareLock);
TupleDesc tupleDescriptor = RelationGetDescr(distributedRelation); TupleDesc tupleDescriptor = RelationGetDescr(distributedRelation);
List *targetList = NIL; List *targetList = NIL;
@ -2905,7 +2905,7 @@ CitusCopySelect(CopyStmt *copyStatement)
targetList = lappend(targetList, selectTarget); targetList = lappend(targetList, selectTarget);
} }
heap_close(distributedRelation, NoLock); table_close(distributedRelation, NoLock);
selectStmt->targetList = targetList; selectStmt->targetList = targetList;
return selectStmt; return selectStmt;
@ -2922,7 +2922,7 @@ CitusCopyTo(CopyStmt *copyStatement, char *completionTag)
ListCell *shardIntervalCell = NULL; ListCell *shardIntervalCell = NULL;
int64 tuplesSent = 0; int64 tuplesSent = 0;
Relation distributedRelation = heap_openrv(copyStatement->relation, AccessShareLock); Relation distributedRelation = table_openrv(copyStatement->relation, AccessShareLock);
Oid relationId = RelationGetRelid(distributedRelation); Oid relationId = RelationGetRelid(distributedRelation);
TupleDesc tupleDescriptor = RelationGetDescr(distributedRelation); TupleDesc tupleDescriptor = RelationGetDescr(distributedRelation);
@ -3004,7 +3004,7 @@ CitusCopyTo(CopyStmt *copyStatement, char *completionTag)
SendCopyEnd(copyOutState); SendCopyEnd(copyOutState);
heap_close(distributedRelation, AccessShareLock); table_close(distributedRelation, AccessShareLock);
if (completionTag != NULL) if (completionTag != NULL)
{ {
@ -3079,7 +3079,7 @@ CheckCopyPermissions(CopyStmt *copyStatement)
List *attnums; List *attnums;
ListCell *cur; ListCell *cur;
rel = heap_openrv(copyStatement->relation, rel = table_openrv(copyStatement->relation,
is_from ? RowExclusiveLock : AccessShareLock); is_from ? RowExclusiveLock : AccessShareLock);
range_table = CreateRangeTable(rel, required_access); range_table = CreateRangeTable(rel, required_access);
@ -3105,7 +3105,7 @@ CheckCopyPermissions(CopyStmt *copyStatement)
/* TODO: Perform RLS checks once supported */ /* TODO: Perform RLS checks once supported */
heap_close(rel, NoLock); table_close(rel, NoLock);
/* *INDENT-ON* */ /* *INDENT-ON* */
} }

View File

@ -33,6 +33,7 @@
#include "distributed/coordinator_protocol.h" #include "distributed/coordinator_protocol.h"
#include "distributed/metadata/distobject.h" #include "distributed/metadata/distobject.h"
#include "distributed/metadata_sync.h" #include "distributed/metadata_sync.h"
#include "distributed/version_compat.h"
#include "distributed/worker_transaction.h" #include "distributed/worker_transaction.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
@ -315,7 +316,7 @@ CreateCreateOrAlterRoleCommand(const char *roleName,
static const char * static const char *
ExtractEncryptedPassword(Oid roleOid) ExtractEncryptedPassword(Oid roleOid)
{ {
Relation pgAuthId = heap_open(AuthIdRelationId, AccessShareLock); Relation pgAuthId = table_open(AuthIdRelationId, AccessShareLock);
TupleDesc pgAuthIdDescription = RelationGetDescr(pgAuthId); TupleDesc pgAuthIdDescription = RelationGetDescr(pgAuthId);
HeapTuple tuple = SearchSysCache1(AUTHOID, roleOid); HeapTuple tuple = SearchSysCache1(AUTHOID, roleOid);
bool isNull = true; bool isNull = true;
@ -328,7 +329,7 @@ ExtractEncryptedPassword(Oid roleOid)
Datum passwordDatum = heap_getattr(tuple, Anum_pg_authid_rolpassword, Datum passwordDatum = heap_getattr(tuple, Anum_pg_authid_rolpassword,
pgAuthIdDescription, &isNull); pgAuthIdDescription, &isNull);
heap_close(pgAuthId, AccessShareLock); table_close(pgAuthId, AccessShareLock);
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
if (isNull) if (isNull)
@ -527,7 +528,7 @@ GenerateCreateOrAlterRoleCommand(Oid roleOid)
List * List *
GenerateAlterRoleSetCommandForRole(Oid roleid) GenerateAlterRoleSetCommandForRole(Oid roleid)
{ {
Relation DbRoleSetting = heap_open(DbRoleSettingRelationId, AccessShareLock); Relation DbRoleSetting = table_open(DbRoleSettingRelationId, AccessShareLock);
TupleDesc DbRoleSettingDescription = RelationGetDescr(DbRoleSetting); TupleDesc DbRoleSettingDescription = RelationGetDescr(DbRoleSetting);
HeapTuple tuple = NULL; HeapTuple tuple = NULL;
List *commands = NIL; List *commands = NIL;
@ -561,7 +562,7 @@ GenerateAlterRoleSetCommandForRole(Oid roleid)
} }
heap_endscan(scan); heap_endscan(scan);
heap_close(DbRoleSetting, AccessShareLock); table_close(DbRoleSetting, AccessShareLock);
return commands; return commands;
} }

View File

@ -30,6 +30,7 @@
#include "distributed/resource_lock.h" #include "distributed/resource_lock.h"
#include <distributed/remote_commands.h> #include <distributed/remote_commands.h>
#include <distributed/remote_commands.h> #include <distributed/remote_commands.h>
#include "distributed/version_compat.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/fmgroids.h" #include "utils/fmgroids.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
@ -71,7 +72,7 @@ PreprocessDropSchemaStmt(Node *node, const char *queryString)
continue; continue;
} }
pgClass = heap_open(RelationRelationId, AccessShareLock); pgClass = table_open(RelationRelationId, AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_class_relnamespace, BTEqualStrategyNumber, ScanKeyInit(&scanKey[0], Anum_pg_class_relnamespace, BTEqualStrategyNumber,
F_OIDEQ, namespaceOid); F_OIDEQ, namespaceOid);
@ -105,7 +106,7 @@ PreprocessDropSchemaStmt(Node *node, const char *queryString)
MarkInvalidateForeignKeyGraph(); MarkInvalidateForeignKeyGraph();
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgClass, NoLock); table_close(pgClass, NoLock);
return NIL; return NIL;
} }
@ -113,7 +114,7 @@ PreprocessDropSchemaStmt(Node *node, const char *queryString)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgClass, NoLock); table_close(pgClass, NoLock);
} }
return NIL; return NIL;

View File

@ -70,7 +70,7 @@ GetExplicitTriggerIdList(Oid relationId)
{ {
List *triggerIdList = NIL; List *triggerIdList = NIL;
Relation pgTrigger = heap_open(TriggerRelationId, AccessShareLock); Relation pgTrigger = table_open(TriggerRelationId, AccessShareLock);
int scanKeyCount = 1; int scanKeyCount = 1;
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
@ -103,7 +103,7 @@ GetExplicitTriggerIdList(Oid relationId)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgTrigger, NoLock); table_close(pgTrigger, NoLock);
return triggerIdList; return triggerIdList;
} }

View File

@ -64,6 +64,7 @@
#include "distributed/remote_commands.h" #include "distributed/remote_commands.h"
#include "distributed/transaction_management.h" #include "distributed/transaction_management.h"
#include "distributed/worker_create_or_replace.h" #include "distributed/worker_create_or_replace.h"
#include "distributed/version_compat.h"
#include "distributed/worker_manager.h" #include "distributed/worker_manager.h"
#include "distributed/worker_transaction.h" #include "distributed/worker_transaction.h"
#include "miscadmin.h" #include "miscadmin.h"
@ -791,7 +792,7 @@ EnumValsList(Oid typeOid)
BTEqualStrategyNumber, F_OIDEQ, BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(typeOid)); ObjectIdGetDatum(typeOid));
Relation enum_rel = heap_open(EnumRelationId, AccessShareLock); Relation enum_rel = table_open(EnumRelationId, AccessShareLock);
SysScanDesc enum_scan = systable_beginscan(enum_rel, SysScanDesc enum_scan = systable_beginscan(enum_rel,
EnumTypIdSortOrderIndexId, EnumTypIdSortOrderIndexId,
true, NULL, true, NULL,
@ -805,7 +806,7 @@ EnumValsList(Oid typeOid)
} }
systable_endscan(enum_scan); systable_endscan(enum_scan);
heap_close(enum_rel, AccessShareLock); table_close(enum_rel, AccessShareLock);
return vals; return vals;
} }

View File

@ -128,7 +128,7 @@ get_extension_schema(Oid ext_oid)
HeapTuple tuple; HeapTuple tuple;
ScanKeyData entry[1]; ScanKeyData entry[1];
rel = heap_open(ExtensionRelationId, AccessShareLock); rel = table_open(ExtensionRelationId, AccessShareLock);
ScanKeyInit(&entry[0], ScanKeyInit(&entry[0],
#if PG_VERSION_NUM >= PG_VERSION_12 #if PG_VERSION_NUM >= PG_VERSION_12
@ -152,7 +152,7 @@ get_extension_schema(Oid ext_oid)
systable_endscan(scandesc); systable_endscan(scandesc);
heap_close(rel, AccessShareLock); table_close(rel, AccessShareLock);
return result; return result;
/* *INDENT-ON* */ /* *INDENT-ON* */
@ -1174,7 +1174,7 @@ pg_get_replica_identity_command(Oid tableRelationId)
{ {
StringInfo buf = makeStringInfo(); StringInfo buf = makeStringInfo();
Relation relation = heap_open(tableRelationId, AccessShareLock); Relation relation = table_open(tableRelationId, AccessShareLock);
char replicaIdentity = relation->rd_rel->relreplident; char replicaIdentity = relation->rd_rel->relreplident;
@ -1202,7 +1202,7 @@ pg_get_replica_identity_command(Oid tableRelationId)
relationName); relationName);
} }
heap_close(relation, AccessShareLock); table_close(relation, AccessShareLock);
return (buf->len > 0) ? buf->data : NULL; return (buf->len > 0) ? buf->data : NULL;
} }

View File

@ -34,6 +34,7 @@
#include "distributed/shardinterval_utils.h" #include "distributed/shardinterval_utils.h"
#include "distributed/subplan_execution.h" #include "distributed/subplan_execution.h"
#include "distributed/transaction_management.h" #include "distributed/transaction_management.h"
#include "distributed/version_compat.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "nodes/execnodes.h" #include "nodes/execnodes.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"

View File

@ -25,6 +25,7 @@
#include "distributed/metadata/dependency.h" #include "distributed/metadata/dependency.h"
#include "distributed/metadata/distobject.h" #include "distributed/metadata/distobject.h"
#include "distributed/metadata_cache.h" #include "distributed/metadata_cache.h"
#include "distributed/version_compat.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "utils/fmgroids.h" #include "utils/fmgroids.h"
#include "utils/hsearch.h" #include "utils/hsearch.h"
@ -304,7 +305,7 @@ DependencyDefinitionFromPgDepend(ObjectAddress target)
/* /*
* iterate the actual pg_depend catalog * iterate the actual pg_depend catalog
*/ */
Relation depRel = heap_open(DependRelationId, AccessShareLock); Relation depRel = table_open(DependRelationId, AccessShareLock);
/* scan pg_depend for classid = $1 AND objid = $2 using pg_depend_depender_index */ /* scan pg_depend for classid = $1 AND objid = $2 using pg_depend_depender_index */
ScanKeyInit(&key[0], Anum_pg_depend_classid, BTEqualStrategyNumber, F_OIDEQ, ScanKeyInit(&key[0], Anum_pg_depend_classid, BTEqualStrategyNumber, F_OIDEQ,
@ -346,7 +347,7 @@ DependencyDefinitionFromPgShDepend(ObjectAddress target)
/* /*
* iterate the actual pg_shdepend catalog * iterate the actual pg_shdepend catalog
*/ */
Relation shdepRel = heap_open(SharedDependRelationId, AccessShareLock); Relation shdepRel = table_open(SharedDependRelationId, AccessShareLock);
/* /*
* Scan pg_shdepend for dbid = $1 AND classid = $2 AND objid = $3 using * Scan pg_shdepend for dbid = $1 AND classid = $2 AND objid = $3 using
@ -621,7 +622,7 @@ IsObjectAddressOwnedByExtension(const ObjectAddress *target,
HeapTuple depTup = NULL; HeapTuple depTup = NULL;
bool result = false; bool result = false;
Relation depRel = heap_open(DependRelationId, AccessShareLock); Relation depRel = table_open(DependRelationId, AccessShareLock);
/* scan pg_depend for classid = $1 AND objid = $2 using pg_depend_depender_index */ /* scan pg_depend for classid = $1 AND objid = $2 using pg_depend_depender_index */
ScanKeyInit(&key[0], Anum_pg_depend_classid, BTEqualStrategyNumber, F_OIDEQ, ScanKeyInit(&key[0], Anum_pg_depend_classid, BTEqualStrategyNumber, F_OIDEQ,
@ -647,7 +648,7 @@ IsObjectAddressOwnedByExtension(const ObjectAddress *target,
} }
systable_endscan(depScan); systable_endscan(depScan);
heap_close(depRel, AccessShareLock); table_close(depRel, AccessShareLock);
return result; return result;
} }

View File

@ -31,6 +31,7 @@
#include "distributed/metadata/distobject.h" #include "distributed/metadata/distobject.h"
#include "distributed/metadata/pg_dist_object.h" #include "distributed/metadata/pg_dist_object.h"
#include "distributed/metadata_cache.h" #include "distributed/metadata_cache.h"
#include "distributed/version_compat.h"
#include "executor/spi.h" #include "executor/spi.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
@ -103,7 +104,7 @@ ObjectExists(const ObjectAddress *address)
if (is_objectclass_supported(address->classId)) if (is_objectclass_supported(address->classId))
{ {
HeapTuple objtup; HeapTuple objtup;
Relation catalog = heap_open(address->classId, AccessShareLock); Relation catalog = table_open(address->classId, AccessShareLock);
#if PG_VERSION_NUM >= PG_VERSION_12 #if PG_VERSION_NUM >= PG_VERSION_12
objtup = get_catalog_object_by_oid(catalog, get_object_attnum_oid( objtup = get_catalog_object_by_oid(catalog, get_object_attnum_oid(
@ -111,7 +112,7 @@ ObjectExists(const ObjectAddress *address)
#else #else
objtup = get_catalog_object_by_oid(catalog, address->objectId); objtup = get_catalog_object_by_oid(catalog, address->objectId);
#endif #endif
heap_close(catalog, AccessShareLock); table_close(catalog, AccessShareLock);
if (objtup != NULL) if (objtup != NULL)
{ {
return true; return true;
@ -257,7 +258,7 @@ IsObjectDistributed(const ObjectAddress *address)
ScanKeyData key[3]; ScanKeyData key[3];
bool result = false; bool result = false;
Relation pgDistObjectRel = heap_open(DistObjectRelationId(), AccessShareLock); Relation pgDistObjectRel = table_open(DistObjectRelationId(), AccessShareLock);
/* scan pg_dist_object for classid = $1 AND objid = $2 AND objsubid = $3 via index */ /* scan pg_dist_object for classid = $1 AND objid = $2 AND objsubid = $3 via index */
ScanKeyInit(&key[0], Anum_pg_dist_object_classid, BTEqualStrategyNumber, F_OIDEQ, ScanKeyInit(&key[0], Anum_pg_dist_object_classid, BTEqualStrategyNumber, F_OIDEQ,
@ -295,7 +296,7 @@ ClusterHasDistributedFunctionWithDistArgument(void)
HeapTuple pgDistObjectTup = NULL; HeapTuple pgDistObjectTup = NULL;
Relation pgDistObjectRel = heap_open(DistObjectRelationId(), AccessShareLock); Relation pgDistObjectRel = table_open(DistObjectRelationId(), AccessShareLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistObjectRel); TupleDesc tupleDescriptor = RelationGetDescr(pgDistObjectRel);
@ -340,7 +341,7 @@ GetDistributedObjectAddressList(void)
HeapTuple pgDistObjectTup = NULL; HeapTuple pgDistObjectTup = NULL;
List *objectAddressList = NIL; List *objectAddressList = NIL;
Relation pgDistObjectRel = heap_open(DistObjectRelationId(), AccessShareLock); Relation pgDistObjectRel = table_open(DistObjectRelationId(), AccessShareLock);
SysScanDesc pgDistObjectScan = systable_beginscan(pgDistObjectRel, InvalidOid, false, SysScanDesc pgDistObjectScan = systable_beginscan(pgDistObjectRel, InvalidOid, false,
NULL, 0, NULL, 0,
NULL); NULL);

View File

@ -323,7 +323,7 @@ IsCitusTableViaCatalog(Oid relationId)
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
bool indexOK = true; bool indexOK = true;
Relation pgDistPartition = heap_open(DistPartitionRelationId(), AccessShareLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid, ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relationId)); BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relationId));
@ -334,7 +334,7 @@ IsCitusTableViaCatalog(Oid relationId)
HeapTuple partitionTuple = systable_getnext(scanDescriptor); HeapTuple partitionTuple = systable_getnext(scanDescriptor);
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistPartition, AccessShareLock); table_close(pgDistPartition, AccessShareLock);
return HeapTupleIsValid(partitionTuple); return HeapTupleIsValid(partitionTuple);
} }
@ -1006,7 +1006,7 @@ LookupDistObjectCacheEntry(Oid classid, Oid objid, int32 objsubid)
cacheEntry->key.objid = objid; cacheEntry->key.objid = objid;
cacheEntry->key.objsubid = objsubid; cacheEntry->key.objsubid = objsubid;
Relation pgDistObjectRel = heap_open(DistObjectRelationId(), AccessShareLock); Relation pgDistObjectRel = table_open(DistObjectRelationId(), AccessShareLock);
TupleDesc pgDistObjectTupleDesc = RelationGetDescr(pgDistObjectRel); TupleDesc pgDistObjectTupleDesc = RelationGetDescr(pgDistObjectRel);
ScanKeyInit(&pgDistObjectKey[0], Anum_pg_dist_object_classid, ScanKeyInit(&pgDistObjectKey[0], Anum_pg_dist_object_classid,
@ -1059,14 +1059,14 @@ LookupDistObjectCacheEntry(Oid classid, Oid objid, int32 objsubid)
static CitusTableCacheEntry * static CitusTableCacheEntry *
BuildCitusTableCacheEntry(Oid relationId) BuildCitusTableCacheEntry(Oid relationId)
{ {
Relation pgDistPartition = heap_open(DistPartitionRelationId(), AccessShareLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
HeapTuple distPartitionTuple = HeapTuple distPartitionTuple =
LookupDistPartitionTuple(pgDistPartition, relationId); LookupDistPartitionTuple(pgDistPartition, relationId);
if (distPartitionTuple == NULL) if (distPartitionTuple == NULL)
{ {
/* not a distributed table, done */ /* not a distributed table, done */
heap_close(pgDistPartition, NoLock); table_close(pgDistPartition, NoLock);
return NULL; return NULL;
} }
@ -1166,7 +1166,7 @@ BuildCitusTableCacheEntry(Oid relationId)
MemoryContextSwitchTo(oldContext); MemoryContextSwitchTo(oldContext);
heap_close(pgDistPartition, NoLock); table_close(pgDistPartition, NoLock);
cacheEntry->isValid = true; cacheEntry->isValid = true;
@ -1201,7 +1201,7 @@ BuildCachedShardList(CitusTableCacheEntry *cacheEntry)
int shardIntervalArrayLength = list_length(distShardTupleList); int shardIntervalArrayLength = list_length(distShardTupleList);
if (shardIntervalArrayLength > 0) if (shardIntervalArrayLength > 0)
{ {
Relation distShardRelation = heap_open(DistShardRelationId(), AccessShareLock); Relation distShardRelation = table_open(DistShardRelationId(), AccessShareLock);
TupleDesc distShardTupleDesc = RelationGetDescr(distShardRelation); TupleDesc distShardTupleDesc = RelationGetDescr(distShardRelation);
int arrayIndex = 0; int arrayIndex = 0;
@ -1236,7 +1236,7 @@ BuildCachedShardList(CitusTableCacheEntry *cacheEntry)
arrayIndex++; arrayIndex++;
} }
heap_close(distShardRelation, AccessShareLock); table_close(distShardRelation, AccessShareLock);
} }
/* look up value comparison function */ /* look up value comparison function */
@ -1847,7 +1847,7 @@ InstalledExtensionVersion(void)
InitializeCaches(); InitializeCaches();
Relation relation = heap_open(ExtensionRelationId, AccessShareLock); Relation relation = table_open(ExtensionRelationId, AccessShareLock);
ScanKeyInit(&entry[0], Anum_pg_extension_extname, BTEqualStrategyNumber, F_NAMEEQ, ScanKeyInit(&entry[0], Anum_pg_extension_extname, BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum("citus")); CStringGetDatum("citus"));
@ -1889,7 +1889,7 @@ InstalledExtensionVersion(void)
systable_endscan(scandesc); systable_endscan(scandesc);
heap_close(relation, AccessShareLock); table_close(relation, AccessShareLock);
return installedExtensionVersion; return installedExtensionVersion;
} }
@ -2400,7 +2400,7 @@ CitusExtensionOwner(void)
return MetadataCache.extensionOwner; return MetadataCache.extensionOwner;
} }
Relation relation = heap_open(ExtensionRelationId, AccessShareLock); Relation relation = table_open(ExtensionRelationId, AccessShareLock);
ScanKeyInit(&entry[0], ScanKeyInit(&entry[0],
Anum_pg_extension_extname, Anum_pg_extension_extname,
@ -2440,7 +2440,7 @@ CitusExtensionOwner(void)
systable_endscan(scandesc); systable_endscan(scandesc);
heap_close(relation, AccessShareLock); table_close(relation, AccessShareLock);
return MetadataCache.extensionOwner; return MetadataCache.extensionOwner;
} }
@ -3228,7 +3228,7 @@ GetLocalGroupId(void)
return 0; return 0;
} }
Relation pgDistLocalGroupId = heap_open(localGroupTableOid, AccessShareLock); Relation pgDistLocalGroupId = table_open(localGroupTableOid, AccessShareLock);
SysScanDesc scanDescriptor = systable_beginscan(pgDistLocalGroupId, SysScanDesc scanDescriptor = systable_beginscan(pgDistLocalGroupId,
InvalidOid, false, InvalidOid, false,
@ -3260,7 +3260,7 @@ GetLocalGroupId(void)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistLocalGroupId, AccessShareLock); table_close(pgDistLocalGroupId, AccessShareLock);
return groupId; return groupId;
} }
@ -3671,7 +3671,7 @@ DistTableOidList(void)
int scanKeyCount = 0; int scanKeyCount = 0;
List *distTableOidList = NIL; List *distTableOidList = NIL;
Relation pgDistPartition = heap_open(DistPartitionRelationId(), AccessShareLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition, SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition,
InvalidOid, false, InvalidOid, false,
@ -3693,7 +3693,7 @@ DistTableOidList(void)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistPartition, AccessShareLock); table_close(pgDistPartition, AccessShareLock);
return distTableOidList; return distTableOidList;
} }
@ -3713,7 +3713,7 @@ ReferenceTableOidList()
int scanKeyCount = 0; int scanKeyCount = 0;
List *referenceTableOidList = NIL; List *referenceTableOidList = NIL;
Relation pgDistPartition = heap_open(DistPartitionRelationId(), AccessShareLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition, SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition,
InvalidOid, false, InvalidOid, false,
@ -3742,7 +3742,7 @@ ReferenceTableOidList()
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistPartition, AccessShareLock); table_close(pgDistPartition, AccessShareLock);
return referenceTableOidList; return referenceTableOidList;
} }
@ -3856,7 +3856,7 @@ LookupDistShardTuples(Oid relationId)
List *distShardTupleList = NIL; List *distShardTupleList = NIL;
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
Relation pgDistShard = heap_open(DistShardRelationId(), AccessShareLock); Relation pgDistShard = table_open(DistShardRelationId(), AccessShareLock);
/* copy scankey to local copy, it will be modified during the scan */ /* copy scankey to local copy, it will be modified during the scan */
scanKey[0] = DistShardScanKey[0]; scanKey[0] = DistShardScanKey[0];
@ -3878,7 +3878,7 @@ LookupDistShardTuples(Oid relationId)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistShard, AccessShareLock); table_close(pgDistShard, AccessShareLock);
return distShardTupleList; return distShardTupleList;
} }
@ -3896,7 +3896,7 @@ LookupShardRelationFromCatalog(int64 shardId, bool missingOk)
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
int scanKeyCount = 1; int scanKeyCount = 1;
Form_pg_dist_shard shardForm = NULL; Form_pg_dist_shard shardForm = NULL;
Relation pgDistShard = heap_open(DistShardRelationId(), AccessShareLock); Relation pgDistShard = table_open(DistShardRelationId(), AccessShareLock);
Oid relationId = InvalidOid; Oid relationId = InvalidOid;
ScanKeyInit(&scanKey[0], Anum_pg_dist_shard_shardid, ScanKeyInit(&scanKey[0], Anum_pg_dist_shard_shardid,
@ -3924,7 +3924,7 @@ LookupShardRelationFromCatalog(int64 shardId, bool missingOk)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistShard, NoLock); table_close(pgDistShard, NoLock);
return relationId; return relationId;
} }
@ -4206,7 +4206,7 @@ CitusInvalidateRelcacheByShardId(int64 shardId)
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
int scanKeyCount = 1; int scanKeyCount = 1;
Form_pg_dist_shard shardForm = NULL; Form_pg_dist_shard shardForm = NULL;
Relation pgDistShard = heap_open(DistShardRelationId(), AccessShareLock); Relation pgDistShard = table_open(DistShardRelationId(), AccessShareLock);
/* /*
* Load shard, to find the associated relation id. Can't use * Load shard, to find the associated relation id. Can't use
@ -4249,7 +4249,7 @@ CitusInvalidateRelcacheByShardId(int64 shardId)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistShard, NoLock); table_close(pgDistShard, NoLock);
/* bump command counter, to force invalidation to take effect */ /* bump command counter, to force invalidation to take effect */
CommandCounterIncrement(); CommandCounterIncrement();
@ -4274,7 +4274,7 @@ DistNodeMetadata(void)
ereport(ERROR, (errmsg("pg_dist_node_metadata was not found"))); ereport(ERROR, (errmsg("pg_dist_node_metadata was not found")));
} }
Relation pgDistNodeMetadata = heap_open(metadataTableOid, AccessShareLock); Relation pgDistNodeMetadata = table_open(metadataTableOid, AccessShareLock);
SysScanDesc scanDescriptor = systable_beginscan(pgDistNodeMetadata, SysScanDesc scanDescriptor = systable_beginscan(pgDistNodeMetadata,
InvalidOid, false, InvalidOid, false,
NULL, scanKeyCount, scanKey); NULL, scanKeyCount, scanKey);
@ -4295,7 +4295,7 @@ DistNodeMetadata(void)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistNodeMetadata, AccessShareLock); table_close(pgDistNodeMetadata, AccessShareLock);
return metadata; return metadata;
} }

View File

@ -989,7 +989,7 @@ UpdateDistNodeBoolAttr(const char *nodeName, int32 nodePort, int attrNum, bool v
bool isnull[Natts_pg_dist_node]; bool isnull[Natts_pg_dist_node];
bool replace[Natts_pg_dist_node]; bool replace[Natts_pg_dist_node];
Relation pgDistNode = heap_open(DistNodeRelationId(), RowExclusiveLock); Relation pgDistNode = table_open(DistNodeRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode); TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode);
ScanKeyInit(&scanKey[0], Anum_pg_dist_node_nodename, ScanKeyInit(&scanKey[0], Anum_pg_dist_node_nodename,
@ -1022,7 +1022,7 @@ UpdateDistNodeBoolAttr(const char *nodeName, int32 nodePort, int attrNum, bool v
CommandCounterIncrement(); CommandCounterIncrement();
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistNode, NoLock); table_close(pgDistNode, NoLock);
} }

View File

@ -190,7 +190,7 @@ DistributedTableSize(Oid relationId, char *sizeQuery)
totalRelationSize += relationSizeOnNode; totalRelationSize += relationSizeOnNode;
} }
heap_close(relation, AccessShareLock); table_close(relation, AccessShareLock);
return totalRelationSize; return totalRelationSize;
} }
@ -633,7 +633,7 @@ NodeGroupHasShardPlacements(int32 groupId, bool onlyConsiderActivePlacements)
ScanKeyData scanKey[2]; ScanKeyData scanKey[2];
Relation pgPlacement = heap_open(DistPlacementRelationId(), Relation pgPlacement = table_open(DistPlacementRelationId(),
AccessShareLock); AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_groupid, ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_groupid,
@ -654,7 +654,7 @@ NodeGroupHasShardPlacements(int32 groupId, bool onlyConsiderActivePlacements)
bool hasActivePlacements = HeapTupleIsValid(heapTuple); bool hasActivePlacements = HeapTupleIsValid(heapTuple);
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgPlacement, NoLock); table_close(pgPlacement, NoLock);
return hasActivePlacements; return hasActivePlacements;
} }
@ -731,7 +731,7 @@ BuildShardPlacementList(ShardInterval *shardInterval)
int scanKeyCount = 1; int scanKeyCount = 1;
bool indexOK = true; bool indexOK = true;
Relation pgPlacement = heap_open(DistPlacementRelationId(), AccessShareLock); Relation pgPlacement = table_open(DistPlacementRelationId(), AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_shardid, ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_shardid,
BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(shardId)); BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(shardId));
@ -755,7 +755,7 @@ BuildShardPlacementList(ShardInterval *shardInterval)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgPlacement, NoLock); table_close(pgPlacement, NoLock);
return shardPlacementList; return shardPlacementList;
} }
@ -774,7 +774,7 @@ AllShardPlacementsOnNodeGroup(int32 groupId)
int scanKeyCount = 1; int scanKeyCount = 1;
bool indexOK = true; bool indexOK = true;
Relation pgPlacement = heap_open(DistPlacementRelationId(), AccessShareLock); Relation pgPlacement = table_open(DistPlacementRelationId(), AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_groupid, ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_groupid,
BTEqualStrategyNumber, F_INT4EQ, Int32GetDatum(groupId)); BTEqualStrategyNumber, F_INT4EQ, Int32GetDatum(groupId));
@ -798,7 +798,7 @@ AllShardPlacementsOnNodeGroup(int32 groupId)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgPlacement, NoLock); table_close(pgPlacement, NoLock);
return shardPlacementList; return shardPlacementList;
} }
@ -879,7 +879,7 @@ InsertShardRow(Oid relationId, uint64 shardId, char storageType,
} }
/* open shard relation and insert new tuple */ /* open shard relation and insert new tuple */
Relation pgDistShard = heap_open(DistShardRelationId(), RowExclusiveLock); Relation pgDistShard = table_open(DistShardRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistShard); TupleDesc tupleDescriptor = RelationGetDescr(pgDistShard);
HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls); HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls);
@ -890,7 +890,7 @@ InsertShardRow(Oid relationId, uint64 shardId, char storageType,
CitusInvalidateRelcacheByRelid(relationId); CitusInvalidateRelcacheByRelid(relationId);
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(pgDistShard, NoLock); table_close(pgDistShard, NoLock);
} }
@ -923,7 +923,7 @@ InsertShardPlacementRow(uint64 shardId, uint64 placementId,
values[Anum_pg_dist_placement_groupid - 1] = Int32GetDatum(groupId); values[Anum_pg_dist_placement_groupid - 1] = Int32GetDatum(groupId);
/* open shard placement relation and insert new tuple */ /* open shard placement relation and insert new tuple */
Relation pgDistPlacement = heap_open(DistPlacementRelationId(), RowExclusiveLock); Relation pgDistPlacement = table_open(DistPlacementRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPlacement); TupleDesc tupleDescriptor = RelationGetDescr(pgDistPlacement);
HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls); HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls);
@ -933,7 +933,7 @@ InsertShardPlacementRow(uint64 shardId, uint64 placementId,
CitusInvalidateRelcacheByShardId(shardId); CitusInvalidateRelcacheByShardId(shardId);
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(pgDistPlacement, NoLock); table_close(pgDistPlacement, NoLock);
return placementId; return placementId;
} }
@ -953,7 +953,7 @@ InsertIntoPgDistPartition(Oid relationId, char distributionMethod,
bool newNulls[Natts_pg_dist_partition]; bool newNulls[Natts_pg_dist_partition];
/* open system catalog and insert new tuple */ /* open system catalog and insert new tuple */
Relation pgDistPartition = heap_open(DistPartitionRelationId(), RowExclusiveLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
/* form new tuple for pg_dist_partition */ /* form new tuple for pg_dist_partition */
memset(newValues, 0, sizeof(newValues)); memset(newValues, 0, sizeof(newValues));
@ -991,7 +991,7 @@ InsertIntoPgDistPartition(Oid relationId, char distributionMethod,
RecordDistributedRelationDependencies(relationId); RecordDistributedRelationDependencies(relationId);
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(pgDistPartition, NoLock); table_close(pgDistPartition, NoLock);
} }
@ -1038,7 +1038,7 @@ DeletePartitionRow(Oid distributedRelationId)
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
int scanKeyCount = 1; int scanKeyCount = 1;
Relation pgDistPartition = heap_open(DistPartitionRelationId(), RowExclusiveLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid, ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(distributedRelationId)); BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(distributedRelationId));
@ -1064,7 +1064,7 @@ DeletePartitionRow(Oid distributedRelationId)
/* increment the counter so that next command can see the row */ /* increment the counter so that next command can see the row */
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(pgDistPartition, NoLock); table_close(pgDistPartition, NoLock);
} }
@ -1079,7 +1079,7 @@ DeleteShardRow(uint64 shardId)
int scanKeyCount = 1; int scanKeyCount = 1;
bool indexOK = true; bool indexOK = true;
Relation pgDistShard = heap_open(DistShardRelationId(), RowExclusiveLock); Relation pgDistShard = table_open(DistShardRelationId(), RowExclusiveLock);
ScanKeyInit(&scanKey[0], Anum_pg_dist_shard_shardid, ScanKeyInit(&scanKey[0], Anum_pg_dist_shard_shardid,
BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(shardId)); BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(shardId));
@ -1106,7 +1106,7 @@ DeleteShardRow(uint64 shardId)
CitusInvalidateRelcacheByRelid(distributedRelationId); CitusInvalidateRelcacheByRelid(distributedRelationId);
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(pgDistShard, NoLock); table_close(pgDistShard, NoLock);
} }
@ -1122,7 +1122,7 @@ DeleteShardPlacementRow(uint64 placementId)
bool indexOK = true; bool indexOK = true;
bool isNull = false; bool isNull = false;
Relation pgDistPlacement = heap_open(DistPlacementRelationId(), RowExclusiveLock); Relation pgDistPlacement = table_open(DistPlacementRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPlacement); TupleDesc tupleDescriptor = RelationGetDescr(pgDistPlacement);
ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_placementid, ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_placementid,
@ -1154,7 +1154,7 @@ DeleteShardPlacementRow(uint64 placementId)
CitusInvalidateRelcacheByShardId(shardId); CitusInvalidateRelcacheByShardId(shardId);
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(pgDistPlacement, NoLock); table_close(pgDistPlacement, NoLock);
} }
@ -1251,7 +1251,7 @@ UpdateShardPlacementState(uint64 placementId, char shardState)
bool replace[Natts_pg_dist_placement]; bool replace[Natts_pg_dist_placement];
bool colIsNull = false; bool colIsNull = false;
Relation pgDistPlacement = heap_open(DistPlacementRelationId(), RowExclusiveLock); Relation pgDistPlacement = table_open(DistPlacementRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPlacement); TupleDesc tupleDescriptor = RelationGetDescr(pgDistPlacement);
ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_placementid, ScanKeyInit(&scanKey[0], Anum_pg_dist_placement_placementid,
BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(placementId)); BTEqualStrategyNumber, F_INT8EQ, Int64GetDatum(placementId));
@ -1288,7 +1288,7 @@ UpdateShardPlacementState(uint64 placementId, char shardState)
CommandCounterIncrement(); CommandCounterIncrement();
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistPlacement, NoLock); table_close(pgDistPlacement, NoLock);
} }

View File

@ -41,6 +41,7 @@
#include "distributed/resource_lock.h" #include "distributed/resource_lock.h"
#include "distributed/shardinterval_utils.h" #include "distributed/shardinterval_utils.h"
#include "distributed/shared_connection_stats.h" #include "distributed/shared_connection_stats.h"
#include "distributed/version_compat.h"
#include "distributed/worker_manager.h" #include "distributed/worker_manager.h"
#include "distributed/worker_transaction.h" #include "distributed/worker_transaction.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
@ -798,7 +799,7 @@ UpdateNodeLocation(int32 nodeId, char *newNodeName, int32 newNodePort)
bool isnull[Natts_pg_dist_node]; bool isnull[Natts_pg_dist_node];
bool replace[Natts_pg_dist_node]; bool replace[Natts_pg_dist_node];
Relation pgDistNode = heap_open(DistNodeRelationId(), RowExclusiveLock); Relation pgDistNode = table_open(DistNodeRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode); TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode);
ScanKeyInit(&scanKey[0], Anum_pg_dist_node_nodeid, ScanKeyInit(&scanKey[0], Anum_pg_dist_node_nodeid,
@ -834,7 +835,7 @@ UpdateNodeLocation(int32 nodeId, char *newNodeName, int32 newNodePort)
CommandCounterIncrement(); CommandCounterIncrement();
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistNode, NoLock); table_close(pgDistNode, NoLock);
} }
@ -978,7 +979,7 @@ FindWorkerNodeAnyCluster(const char *nodeName, int32 nodePort)
{ {
WorkerNode *workerNode = NULL; WorkerNode *workerNode = NULL;
Relation pgDistNode = heap_open(DistNodeRelationId(), AccessShareLock); Relation pgDistNode = table_open(DistNodeRelationId(), AccessShareLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode); TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode);
HeapTuple heapTuple = GetNodeTuple(nodeName, nodePort); HeapTuple heapTuple = GetNodeTuple(nodeName, nodePort);
@ -987,7 +988,7 @@ FindWorkerNodeAnyCluster(const char *nodeName, int32 nodePort)
workerNode = TupleToWorkerNode(tupleDescriptor, heapTuple); workerNode = TupleToWorkerNode(tupleDescriptor, heapTuple);
} }
heap_close(pgDistNode, NoLock); table_close(pgDistNode, NoLock);
return workerNode; return workerNode;
} }
@ -1007,7 +1008,7 @@ ReadDistNode(bool includeNodesFromOtherClusters)
int scanKeyCount = 0; int scanKeyCount = 0;
List *workerNodeList = NIL; List *workerNodeList = NIL;
Relation pgDistNode = heap_open(DistNodeRelationId(), AccessShareLock); Relation pgDistNode = table_open(DistNodeRelationId(), AccessShareLock);
SysScanDesc scanDescriptor = systable_beginscan(pgDistNode, SysScanDesc scanDescriptor = systable_beginscan(pgDistNode,
InvalidOid, false, InvalidOid, false,
@ -1031,7 +1032,7 @@ ReadDistNode(bool includeNodesFromOtherClusters)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistNode, NoLock); table_close(pgDistNode, NoLock);
return workerNodeList; return workerNodeList;
} }
@ -1208,7 +1209,7 @@ AddNodeMetadata(char *nodeName, int32 nodePort,
static WorkerNode * static WorkerNode *
SetWorkerColumn(WorkerNode *workerNode, int columnIndex, Datum value) SetWorkerColumn(WorkerNode *workerNode, int columnIndex, Datum value)
{ {
Relation pgDistNode = heap_open(DistNodeRelationId(), RowExclusiveLock); Relation pgDistNode = table_open(DistNodeRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode); TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode);
HeapTuple heapTuple = GetNodeTuple(workerNode->workerName, workerNode->workerPort); HeapTuple heapTuple = GetNodeTuple(workerNode->workerName, workerNode->workerPort);
@ -1261,7 +1262,7 @@ SetWorkerColumn(WorkerNode *workerNode, int columnIndex, Datum value)
WorkerNode *newWorkerNode = TupleToWorkerNode(tupleDescriptor, heapTuple); WorkerNode *newWorkerNode = TupleToWorkerNode(tupleDescriptor, heapTuple);
heap_close(pgDistNode, NoLock); table_close(pgDistNode, NoLock);
/* we also update the column at worker nodes */ /* we also update the column at worker nodes */
SendCommandToWorkersWithMetadata(metadataSyncCommand); SendCommandToWorkersWithMetadata(metadataSyncCommand);
@ -1305,7 +1306,7 @@ SetNodeState(char *nodeName, int nodePort, bool isActive)
static HeapTuple static HeapTuple
GetNodeTuple(const char *nodeName, int32 nodePort) GetNodeTuple(const char *nodeName, int32 nodePort)
{ {
Relation pgDistNode = heap_open(DistNodeRelationId(), AccessShareLock); Relation pgDistNode = table_open(DistNodeRelationId(), AccessShareLock);
const int scanKeyCount = 2; const int scanKeyCount = 2;
const bool indexOK = false; const bool indexOK = false;
@ -1326,7 +1327,7 @@ GetNodeTuple(const char *nodeName, int32 nodePort)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistNode, NoLock); table_close(pgDistNode, NoLock);
return nodeTuple; return nodeTuple;
} }
@ -1448,7 +1449,7 @@ InsertNodeRow(int nodeid, char *nodeName, int32 nodePort, NodeMetadata *nodeMeta
values[Anum_pg_dist_node_shouldhaveshards - 1] = BoolGetDatum( values[Anum_pg_dist_node_shouldhaveshards - 1] = BoolGetDatum(
nodeMetadata->shouldHaveShards); nodeMetadata->shouldHaveShards);
Relation pgDistNode = heap_open(DistNodeRelationId(), RowExclusiveLock); Relation pgDistNode = table_open(DistNodeRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode); TupleDesc tupleDescriptor = RelationGetDescr(pgDistNode);
HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls); HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls);
@ -1461,7 +1462,7 @@ InsertNodeRow(int nodeid, char *nodeName, int32 nodePort, NodeMetadata *nodeMeta
CommandCounterIncrement(); CommandCounterIncrement();
/* close relation */ /* close relation */
heap_close(pgDistNode, NoLock); table_close(pgDistNode, NoLock);
} }
@ -1475,7 +1476,7 @@ DeleteNodeRow(char *nodeName, int32 nodePort)
bool indexOK = false; bool indexOK = false;
ScanKeyData scanKey[2]; ScanKeyData scanKey[2];
Relation pgDistNode = heap_open(DistNodeRelationId(), RowExclusiveLock); Relation pgDistNode = table_open(DistNodeRelationId(), RowExclusiveLock);
/* /*
* simple_heap_delete() expects that the caller has at least an * simple_heap_delete() expects that the caller has at least an
@ -1510,8 +1511,8 @@ DeleteNodeRow(char *nodeName, int32 nodePort)
/* increment the counter so that next command won't see the row */ /* increment the counter so that next command won't see the row */
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(replicaIndex, AccessShareLock); table_close(replicaIndex, AccessShareLock);
heap_close(pgDistNode, NoLock); table_close(pgDistNode, NoLock);
} }
@ -1628,7 +1629,7 @@ UnsetMetadataSyncedForAll(void)
* pg_dist_node in different orders. To protect against deadlock, we * pg_dist_node in different orders. To protect against deadlock, we
* get an exclusive lock here. * get an exclusive lock here.
*/ */
Relation relation = heap_open(DistNodeRelationId(), ExclusiveLock); Relation relation = table_open(DistNodeRelationId(), ExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(relation); TupleDesc tupleDescriptor = RelationGetDescr(relation);
ScanKeyInit(&scanKey[0], Anum_pg_dist_node_hasmetadata, ScanKeyInit(&scanKey[0], Anum_pg_dist_node_hasmetadata,
BTEqualStrategyNumber, F_BOOLEQ, BoolGetDatum(true)); BTEqualStrategyNumber, F_BOOLEQ, BoolGetDatum(true));
@ -1676,7 +1677,7 @@ UnsetMetadataSyncedForAll(void)
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
CatalogCloseIndexes(indstate); CatalogCloseIndexes(indstate);
heap_close(relation, NoLock); table_close(relation, NoLock);
return updatedAtLeastOne; return updatedAtLeastOne;
} }

View File

@ -48,6 +48,7 @@
#include "distributed/metadata_sync.h" #include "distributed/metadata_sync.h"
#include "distributed/namespace_utils.h" #include "distributed/namespace_utils.h"
#include "distributed/pg_dist_shard.h" #include "distributed/pg_dist_shard.h"
#include "distributed/version_compat.h"
#include "distributed/worker_manager.h" #include "distributed/worker_manager.h"
#include "foreign/foreign.h" #include "foreign/foreign.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
@ -648,7 +649,7 @@ GetTableIndexAndConstraintCommands(Oid relationId)
PushOverrideEmptySearchPath(CurrentMemoryContext); PushOverrideEmptySearchPath(CurrentMemoryContext);
/* open system catalog and scan all indexes that belong to this table */ /* open system catalog and scan all indexes that belong to this table */
Relation pgIndex = heap_open(IndexRelationId, AccessShareLock); Relation pgIndex = table_open(IndexRelationId, AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_index_indrelid, ScanKeyInit(&scanKey[0], Anum_pg_index_indrelid,
BTEqualStrategyNumber, F_OIDEQ, relationId); BTEqualStrategyNumber, F_OIDEQ, relationId);
@ -696,7 +697,7 @@ GetTableIndexAndConstraintCommands(Oid relationId)
/* clean up scan and close system catalog */ /* clean up scan and close system catalog */
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgIndex, AccessShareLock); table_close(pgIndex, AccessShareLock);
/* revert back to original search_path */ /* revert back to original search_path */
PopOverrideSearchPath(); PopOverrideSearchPath();

View File

@ -358,7 +358,7 @@ UpdateRelationsToLocalShardTables(Node *node, List *relationShardList)
static void static void
ConvertRteToSubqueryWithEmptyResult(RangeTblEntry *rte) ConvertRteToSubqueryWithEmptyResult(RangeTblEntry *rte)
{ {
Relation relation = heap_open(rte->relid, NoLock); Relation relation = table_open(rte->relid, NoLock);
TupleDesc tupleDescriptor = RelationGetDescr(relation); TupleDesc tupleDescriptor = RelationGetDescr(relation);
int columnCount = tupleDescriptor->natts; int columnCount = tupleDescriptor->natts;
List *targetList = NIL; List *targetList = NIL;
@ -388,7 +388,7 @@ ConvertRteToSubqueryWithEmptyResult(RangeTblEntry *rte)
targetList = lappend(targetList, targetEntry); targetList = lappend(targetList, targetEntry);
} }
heap_close(relation, NoLock); table_close(relation, NoLock);
FromExpr *joinTree = makeNode(FromExpr); FromExpr *joinTree = makeNode(FromExpr);
joinTree->quals = makeBoolConst(false, false); joinTree->quals = makeBoolConst(false, false);

View File

@ -1494,7 +1494,7 @@ AddInsertSelectCasts(List *insertTargetList, List *selectTargetList,
*/ */
Assert(list_length(insertTargetList) <= list_length(selectTargetList)); Assert(list_length(insertTargetList) <= list_length(selectTargetList));
Relation distributedRelation = heap_open(targetRelationId, RowExclusiveLock); Relation distributedRelation = table_open(targetRelationId, RowExclusiveLock);
TupleDesc destTupleDescriptor = RelationGetDescr(distributedRelation); TupleDesc destTupleDescriptor = RelationGetDescr(distributedRelation);
int targetEntryIndex = 0; int targetEntryIndex = 0;
@ -1579,7 +1579,7 @@ AddInsertSelectCasts(List *insertTargetList, List *selectTargetList,
selectTargetEntry->resno = entryResNo++; selectTargetEntry->resno = entryResNo++;
} }
heap_close(distributedRelation, NoLock); table_close(distributedRelation, NoLock);
return selectTargetList; return selectTargetList;
} }

View File

@ -3564,7 +3564,7 @@ AggregateFunctionOid(const char *functionName, Oid inputType)
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
int scanKeyCount = 1; int scanKeyCount = 1;
Relation procRelation = heap_open(ProcedureRelationId, AccessShareLock); Relation procRelation = table_open(ProcedureRelationId, AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_proc_proname, ScanKeyInit(&scanKey[0], Anum_pg_proc_proname,
BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(functionName)); BTEqualStrategyNumber, F_NAMEEQ, CStringGetDatum(functionName));
@ -3605,7 +3605,7 @@ AggregateFunctionOid(const char *functionName, Oid inputType)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(procRelation, AccessShareLock); table_close(procRelation, AccessShareLock);
return functionOid; return functionOid;
} }

View File

@ -32,7 +32,7 @@ TDigestExtensionSchema()
Form_pg_extension extensionForm = NULL; Form_pg_extension extensionForm = NULL;
Oid tdigestExtensionSchema = InvalidOid; Oid tdigestExtensionSchema = InvalidOid;
Relation relation = heap_open(ExtensionRelationId, AccessShareLock); Relation relation = table_open(ExtensionRelationId, AccessShareLock);
ScanKeyInit(&entry[0], ScanKeyInit(&entry[0],
Anum_pg_extension_extname, Anum_pg_extension_extname,
@ -57,7 +57,7 @@ TDigestExtensionSchema()
systable_endscan(scandesc); systable_endscan(scandesc);
heap_close(relation, AccessShareLock); table_close(relation, AccessShareLock);
return tdigestExtensionSchema; return tdigestExtensionSchema;
} }

View File

@ -95,7 +95,7 @@ LogTransactionRecord(int32 groupId, char *transactionName)
values[Anum_pg_dist_transaction_gid - 1] = CStringGetTextDatum(transactionName); values[Anum_pg_dist_transaction_gid - 1] = CStringGetTextDatum(transactionName);
/* open transaction relation and insert new tuple */ /* open transaction relation and insert new tuple */
Relation pgDistTransaction = heap_open(DistTransactionRelationId(), RowExclusiveLock); Relation pgDistTransaction = table_open(DistTransactionRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistTransaction); TupleDesc tupleDescriptor = RelationGetDescr(pgDistTransaction);
HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls); HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls);
@ -105,7 +105,7 @@ LogTransactionRecord(int32 groupId, char *transactionName)
CommandCounterIncrement(); CommandCounterIncrement();
/* close relation and invalidate previous cache entry */ /* close relation and invalidate previous cache entry */
heap_close(pgDistTransaction, NoLock); table_close(pgDistTransaction, NoLock);
} }
@ -171,7 +171,7 @@ RecoverWorkerTransactions(WorkerNode *workerNode)
MemoryContext oldContext = MemoryContextSwitchTo(localContext); MemoryContext oldContext = MemoryContextSwitchTo(localContext);
/* take table lock first to avoid running concurrently */ /* take table lock first to avoid running concurrently */
Relation pgDistTransaction = heap_open(DistTransactionRelationId(), Relation pgDistTransaction = table_open(DistTransactionRelationId(),
ShareUpdateExclusiveLock); ShareUpdateExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistTransaction); TupleDesc tupleDescriptor = RelationGetDescr(pgDistTransaction);
@ -344,7 +344,7 @@ RecoverWorkerTransactions(WorkerNode *workerNode)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistTransaction, NoLock); table_close(pgDistTransaction, NoLock);
if (!recoveryFailed) if (!recoveryFailed)
{ {

View File

@ -29,6 +29,7 @@
#include "distributed/pg_dist_colocation.h" #include "distributed/pg_dist_colocation.h"
#include "distributed/resource_lock.h" #include "distributed/resource_lock.h"
#include "distributed/shardinterval_utils.h" #include "distributed/shardinterval_utils.h"
#include "distributed/version_compat.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "distributed/worker_transaction.h" #include "distributed/worker_transaction.h"
#include "storage/lmgr.h" #include "storage/lmgr.h"
@ -154,7 +155,7 @@ BreakColocation(Oid sourceRelationId)
* can be sure that there will no modifications on the colocation table * can be sure that there will no modifications on the colocation table
* until this transaction is committed. * until this transaction is committed.
*/ */
Relation pgDistColocation = heap_open(DistColocationRelationId(), ExclusiveLock); Relation pgDistColocation = table_open(DistColocationRelationId(), ExclusiveLock);
uint32 newColocationId = GetNextColocationId(); uint32 newColocationId = GetNextColocationId();
UpdateRelationColocationGroup(sourceRelationId, newColocationId); UpdateRelationColocationGroup(sourceRelationId, newColocationId);
@ -162,7 +163,7 @@ BreakColocation(Oid sourceRelationId)
/* if there is not any remaining table in the colocation group, delete it */ /* if there is not any remaining table in the colocation group, delete it */
DeleteColocationGroupIfNoTablesBelong(sourceRelationId); DeleteColocationGroupIfNoTablesBelong(sourceRelationId);
heap_close(pgDistColocation, NoLock); table_close(pgDistColocation, NoLock);
} }
@ -248,7 +249,7 @@ MarkTablesColocated(Oid sourceRelationId, Oid targetRelationId)
* can be sure that there will no modifications on the colocation table * can be sure that there will no modifications on the colocation table
* until this transaction is committed. * until this transaction is committed.
*/ */
Relation pgDistColocation = heap_open(DistColocationRelationId(), ExclusiveLock); Relation pgDistColocation = table_open(DistColocationRelationId(), ExclusiveLock);
/* check if shard placements are colocated */ /* check if shard placements are colocated */
ErrorIfShardPlacementsNotColocated(sourceRelationId, targetRelationId); ErrorIfShardPlacementsNotColocated(sourceRelationId, targetRelationId);
@ -271,7 +272,7 @@ MarkTablesColocated(Oid sourceRelationId, Oid targetRelationId)
/* if there is not any remaining table in the colocation group, delete it */ /* if there is not any remaining table in the colocation group, delete it */
DeleteColocationGroupIfNoTablesBelong(targetColocationId); DeleteColocationGroupIfNoTablesBelong(targetColocationId);
heap_close(pgDistColocation, NoLock); table_close(pgDistColocation, NoLock);
} }
@ -514,7 +515,7 @@ ColocationId(int shardCount, int replicationFactor, Oid distributionColumnType,
ScanKeyData scanKey[4]; ScanKeyData scanKey[4];
bool indexOK = true; bool indexOK = true;
Relation pgDistColocation = heap_open(DistColocationRelationId(), AccessShareLock); Relation pgDistColocation = table_open(DistColocationRelationId(), AccessShareLock);
/* set scan arguments */ /* set scan arguments */
ScanKeyInit(&scanKey[0], Anum_pg_dist_colocation_distributioncolumntype, ScanKeyInit(&scanKey[0], Anum_pg_dist_colocation_distributioncolumntype,
@ -541,7 +542,7 @@ ColocationId(int shardCount, int replicationFactor, Oid distributionColumnType,
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistColocation, AccessShareLock); table_close(pgDistColocation, AccessShareLock);
return colocationId; return colocationId;
} }
@ -574,7 +575,7 @@ CreateColocationGroup(int shardCount, int replicationFactor, Oid distributionCol
ObjectIdGetDatum(distributionColumnCollation); ObjectIdGetDatum(distributionColumnCollation);
/* open colocation relation and insert the new tuple */ /* open colocation relation and insert the new tuple */
Relation pgDistColocation = heap_open(DistColocationRelationId(), RowExclusiveLock); Relation pgDistColocation = table_open(DistColocationRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistColocation); TupleDesc tupleDescriptor = RelationGetDescr(pgDistColocation);
HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls); HeapTuple heapTuple = heap_form_tuple(tupleDescriptor, values, isNulls);
@ -583,7 +584,7 @@ CreateColocationGroup(int shardCount, int replicationFactor, Oid distributionCol
/* increment the counter so that next command can see the row */ /* increment the counter so that next command can see the row */
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(pgDistColocation, RowExclusiveLock); table_close(pgDistColocation, RowExclusiveLock);
return colocationId; return colocationId;
} }
@ -716,7 +717,7 @@ UpdateRelationColocationGroup(Oid distributedRelationId, uint32 colocationId)
bool isNull[Natts_pg_dist_partition]; bool isNull[Natts_pg_dist_partition];
bool replace[Natts_pg_dist_partition]; bool replace[Natts_pg_dist_partition];
Relation pgDistPartition = heap_open(DistPartitionRelationId(), RowExclusiveLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition); TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid, ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
@ -753,7 +754,7 @@ UpdateRelationColocationGroup(Oid distributedRelationId, uint32 colocationId)
CommandCounterIncrement(); CommandCounterIncrement();
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistPartition, NoLock); table_close(pgDistPartition, NoLock);
bool shouldSyncMetadata = ShouldSyncTableMetadata(distributedRelationId); bool shouldSyncMetadata = ShouldSyncTableMetadata(distributedRelationId);
if (shouldSyncMetadata) if (shouldSyncMetadata)
@ -882,7 +883,7 @@ ColocationGroupTableList(Oid colocationId)
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_colocationid, ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_colocationid,
BTEqualStrategyNumber, F_INT4EQ, ObjectIdGetDatum(colocationId)); BTEqualStrategyNumber, F_INT4EQ, ObjectIdGetDatum(colocationId));
Relation pgDistPartition = heap_open(DistPartitionRelationId(), AccessShareLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition); TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition, SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition,
DistPartitionColocationidIndexId(), DistPartitionColocationidIndexId(),
@ -901,7 +902,7 @@ ColocationGroupTableList(Oid colocationId)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistPartition, AccessShareLock); table_close(pgDistPartition, AccessShareLock);
return colocatedTableList; return colocatedTableList;
} }
@ -997,7 +998,7 @@ ColocatedTableId(Oid colocationId)
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_colocationid, ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_colocationid,
BTEqualStrategyNumber, F_INT4EQ, ObjectIdGetDatum(colocationId)); BTEqualStrategyNumber, F_INT4EQ, ObjectIdGetDatum(colocationId));
Relation pgDistPartition = heap_open(DistPartitionRelationId(), AccessShareLock); Relation pgDistPartition = table_open(DistPartitionRelationId(), AccessShareLock);
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition); TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition, SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition,
DistPartitionColocationidIndexId(), DistPartitionColocationidIndexId(),
@ -1034,7 +1035,7 @@ ColocatedTableId(Oid colocationId)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistPartition, AccessShareLock); table_close(pgDistPartition, AccessShareLock);
return colocatedTableId; return colocatedTableId;
} }
@ -1085,7 +1086,7 @@ DeleteColocationGroup(uint32 colocationId)
ScanKeyData scanKey[1]; ScanKeyData scanKey[1];
bool indexOK = false; bool indexOK = false;
Relation pgDistColocation = heap_open(DistColocationRelationId(), RowExclusiveLock); Relation pgDistColocation = table_open(DistColocationRelationId(), RowExclusiveLock);
ScanKeyInit(&scanKey[0], Anum_pg_dist_colocation_colocationid, ScanKeyInit(&scanKey[0], Anum_pg_dist_colocation_colocationid,
BTEqualStrategyNumber, F_INT4EQ, UInt32GetDatum(colocationId)); BTEqualStrategyNumber, F_INT4EQ, UInt32GetDatum(colocationId));
@ -1108,9 +1109,9 @@ DeleteColocationGroup(uint32 colocationId)
CitusInvalidateRelcacheByRelid(DistColocationRelationId()); CitusInvalidateRelcacheByRelid(DistColocationRelationId());
CommandCounterIncrement(); CommandCounterIncrement();
heap_close(replicaIndex, AccessShareLock); table_close(replicaIndex, AccessShareLock);
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgDistColocation, RowExclusiveLock); table_close(pgDistColocation, RowExclusiveLock);
} }

View File

@ -296,7 +296,7 @@ PopulateAdjacencyLists(void)
Oid prevReferencedOid = InvalidOid; Oid prevReferencedOid = InvalidOid;
List *frelEdgeList = NIL; List *frelEdgeList = NIL;
Relation pgConstraint = heap_open(ConstraintRelationId, AccessShareLock); Relation pgConstraint = table_open(ConstraintRelationId, AccessShareLock);
ScanKeyInit(&scanKey[0], Anum_pg_constraint_contype, BTEqualStrategyNumber, F_CHAREQ, ScanKeyInit(&scanKey[0], Anum_pg_constraint_contype, BTEqualStrategyNumber, F_CHAREQ,
CharGetDatum(CONSTRAINT_FOREIGN)); CharGetDatum(CONSTRAINT_FOREIGN));
@ -345,7 +345,7 @@ PopulateAdjacencyLists(void)
} }
systable_endscan(scanDescriptor); systable_endscan(scanDescriptor);
heap_close(pgConstraint, AccessShareLock); table_close(pgConstraint, AccessShareLock);
} }

View File

@ -21,6 +21,7 @@
#include "distributed/coordinator_protocol.h" #include "distributed/coordinator_protocol.h"
#include "distributed/multi_partitioning_utils.h" #include "distributed/multi_partitioning_utils.h"
#include "distributed/shardinterval_utils.h" #include "distributed/shardinterval_utils.h"
#include "distributed/version_compat.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "pgstat.h" #include "pgstat.h"
@ -58,7 +59,7 @@ PartitionedTable(Oid relationId)
} }
/* keep the lock */ /* keep the lock */
heap_close(rel, NoLock); table_close(rel, NoLock);
return partitionedTable; return partitionedTable;
} }
@ -87,7 +88,7 @@ PartitionedTableNoLock(Oid relationId)
} }
/* keep the lock */ /* keep the lock */
heap_close(rel, NoLock); table_close(rel, NoLock);
return partitionedTable; return partitionedTable;
} }
@ -110,7 +111,7 @@ PartitionTable(Oid relationId)
bool partitionTable = rel->rd_rel->relispartition; bool partitionTable = rel->rd_rel->relispartition;
/* keep the lock */ /* keep the lock */
heap_close(rel, NoLock); table_close(rel, NoLock);
return partitionTable; return partitionTable;
} }
@ -135,7 +136,7 @@ PartitionTableNoLock(Oid relationId)
bool partitionTable = rel->rd_rel->relispartition; bool partitionTable = rel->rd_rel->relispartition;
/* keep the lock */ /* keep the lock */
heap_close(rel, NoLock); table_close(rel, NoLock);
return partitionTable; return partitionTable;
} }
@ -185,7 +186,7 @@ IsChildTable(Oid relationId)
HeapTuple inheritsTuple = NULL; HeapTuple inheritsTuple = NULL;
bool tableInherits = false; bool tableInherits = false;
Relation pgInherits = heap_open(InheritsRelationId, AccessShareLock); Relation pgInherits = table_open(InheritsRelationId, AccessShareLock);
ScanKeyInit(&key[0], Anum_pg_inherits_inhrelid, ScanKeyInit(&key[0], Anum_pg_inherits_inhrelid,
BTEqualStrategyNumber, F_OIDEQ, BTEqualStrategyNumber, F_OIDEQ,
@ -207,7 +208,7 @@ IsChildTable(Oid relationId)
} }
systable_endscan(scan); systable_endscan(scan);
heap_close(pgInherits, AccessShareLock); table_close(pgInherits, AccessShareLock);
if (tableInherits && PartitionTable(relationId)) if (tableInherits && PartitionTable(relationId))
{ {
@ -229,7 +230,7 @@ IsParentTable(Oid relationId)
ScanKeyData key[1]; ScanKeyData key[1];
bool tableInherited = false; bool tableInherited = false;
Relation pgInherits = heap_open(InheritsRelationId, AccessShareLock); Relation pgInherits = table_open(InheritsRelationId, AccessShareLock);
ScanKeyInit(&key[0], Anum_pg_inherits_inhparent, ScanKeyInit(&key[0], Anum_pg_inherits_inhparent,
BTEqualStrategyNumber, F_OIDEQ, BTEqualStrategyNumber, F_OIDEQ,
@ -243,7 +244,7 @@ IsParentTable(Oid relationId)
tableInherited = true; tableInherited = true;
} }
systable_endscan(scan); systable_endscan(scan);
heap_close(pgInherits, AccessShareLock); table_close(pgInherits, AccessShareLock);
if (tableInherited && PartitionedTable(relationId)) if (tableInherited && PartitionedTable(relationId))
{ {
@ -277,7 +278,7 @@ PartitionParentOid(Oid partitionOid)
List * List *
PartitionList(Oid parentRelationId) PartitionList(Oid parentRelationId)
{ {
Relation rel = heap_open(parentRelationId, AccessShareLock); Relation rel = table_open(parentRelationId, AccessShareLock);
List *partitionList = NIL; List *partitionList = NIL;
@ -298,7 +299,7 @@ PartitionList(Oid parentRelationId)
} }
/* keep the lock */ /* keep the lock */
heap_close(rel, NoLock); table_close(rel, NoLock);
return partitionList; return partitionList;
} }

View File

@ -197,14 +197,14 @@ DistributedTablesSize(List *distTableOids)
if (PartitionMethod(relationId) == DISTRIBUTE_BY_HASH && if (PartitionMethod(relationId) == DISTRIBUTE_BY_HASH &&
!SingleReplicatedTable(relationId)) !SingleReplicatedTable(relationId))
{ {
heap_close(relation, AccessShareLock); table_close(relation, AccessShareLock);
continue; continue;
} }
Datum tableSizeDatum = DirectFunctionCall1(citus_table_size, Datum tableSizeDatum = DirectFunctionCall1(citus_table_size,
ObjectIdGetDatum(relationId)); ObjectIdGetDatum(relationId));
totalSize += DatumGetInt64(tableSizeDatum); totalSize += DatumGetInt64(tableSizeDatum);
heap_close(relation, AccessShareLock); table_close(relation, AccessShareLock);
} }
return totalSize; return totalSize;

View File

@ -278,7 +278,7 @@ worker_cleanup_job_schema_cache(PG_FUNCTION_ARGS)
CheckCitusVersion(ERROR); CheckCitusVersion(ERROR);
pgNamespace = heap_open(NamespaceRelationId, AccessExclusiveLock); pgNamespace = table_open(NamespaceRelationId, AccessExclusiveLock);
#if PG_VERSION_NUM >= PG_VERSION_12 #if PG_VERSION_NUM >= PG_VERSION_12
scanDescriptor = table_beginscan_catalog(pgNamespace, scanKeyCount, scanKey); scanDescriptor = table_beginscan_catalog(pgNamespace, scanKeyCount, scanKey);
#else #else
@ -304,7 +304,7 @@ worker_cleanup_job_schema_cache(PG_FUNCTION_ARGS)
} }
heap_endscan(scanDescriptor); heap_endscan(scanDescriptor);
heap_close(pgNamespace, AccessExclusiveLock); table_close(pgNamespace, AccessExclusiveLock);
PG_RETURN_VOID(); PG_RETURN_VOID();
} }

View File

@ -94,6 +94,10 @@ FileCompatFromFileStart(File fileDesc)
#else /* pre PG12 */ #else /* pre PG12 */
#define table_open(r, l) heap_open(r, l)
#define table_openrv(r, l) heap_openrv(r, l)
#define table_openrv_extended(r, l, m) heap_openrv_extended(r, l, m)
#define table_close(r, l) heap_close(r, l)
#define QTW_EXAMINE_RTES_BEFORE QTW_EXAMINE_RTES #define QTW_EXAMINE_RTES_BEFORE QTW_EXAMINE_RTES
#define MakeSingleTupleTableSlotCompat(tupleDesc, tts_opts) \ #define MakeSingleTupleTableSlotCompat(tupleDesc, tts_opts) \
MakeSingleTupleTableSlot(tupleDesc) MakeSingleTupleTableSlot(tupleDesc)