Skip to content

Commit

Permalink
Greenplum-compat patch
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Nov 7, 2024
1 parent 379e43f commit 9f54d37
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/backend/access/appendonly/appendonlyam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2972,7 +2972,7 @@ appendonly_insert(AppendOnlyInsertDesc aoInsertDesc,
* object store (objects need to contain pointers to one another).
*/
if (!OidIsValid(tupleOid))
tupleOid = GetNewOid(relation);
tupleOid = GetNewOid(relation, '\0');

MemTupleSetOid(tup, aoInsertDesc->mt_bind, tupleOid);
}
Expand Down
23 changes: 21 additions & 2 deletions src/backend/access/heap/heapam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2426,8 +2426,27 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
heaptup = heap_prepare_insert(relation, tup, xid, cid, options, isFrozen);

/* If it's a virtual tuple it should be inserted in virtual catalog. */
if (fasttab_insert(relation, tup, heaptup, &fasttab_result))
if (fasttab_insert(relation, tup, heaptup, &fasttab_result)) {
/*
* If tuple is cachable, mark it for invalidation from the caches in case
* we abort. Note it is OK to do this after releasing the buffer, because
* the heaptup data structure is all in local memory, not in the shared
* buffer.
*/
if (IsSystemRelation(relation))
{
/*
* Also make note of the OID we used, so that it is dispatched to the
* segments, when this CREATE statement is dispatched.
*/
if (Gp_role == GP_ROLE_DISPATCH && relation->rd_rel->relhasoids)
AddDispatchOidFromTuple(relation, heaptup);

CacheInvalidateHeapTuple(relation, heaptup, NULL);
}

return fasttab_result;
}

/*
* Find buffer to insert this tuple into. If the page is all visible,
Expand Down Expand Up @@ -2651,7 +2670,7 @@ heap_prepare_insert(Relation relation, HeapTuple tup, TransactionId xid,
oid = GetPreassignedOidForTuple(relation, tup);

if (!OidIsValid(oid))
oid = GetNewOid(relation);
oid = GetNewOid(relation, '\0');

HeapTupleSetOid(tup, oid);
}
Expand Down
6 changes: 3 additions & 3 deletions src/backend/catalog/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ IsSharedRelation(Oid relationId)
* there are some exceptions.
*/
static bool
RelationNeedsSynchronizedOIDs(Relation relation)
RelationNeedsSynchronizedOIDs(Relation relation, char targerrelpersistence)
{
if (IsSystemNamespace(RelationGetNamespace(relation)))
{
Expand Down Expand Up @@ -507,7 +507,7 @@ RelationNeedsSynchronizedOIDs(Relation relation)
* OIDs, because SnapshotToast considers dead rows as active indefinitely.)
*/
Oid
GetNewOid(Relation relation)
GetNewOid(Relation relation, char targerrelpersistence)
{
Oid newOid;
Oid oidIndex;
Expand Down Expand Up @@ -550,7 +550,7 @@ GetNewOid(Relation relation)
* GetNewOid() is called in a segment. (There are a few exceptions, see
* RelationNeedsSynchronizedOIDs()).
*/
if (Gp_role == GP_ROLE_EXECUTE && RelationNeedsSynchronizedOIDs(relation))
if (Gp_role == GP_ROLE_EXECUTE && RelationNeedsSynchronizedOIDs(relation, targerrelpersistence))
elog(PANIC, "allocated OID %u for relation \"%s\" in segment",
newOid, RelationGetRelationName(relation));

Expand Down
10 changes: 5 additions & 5 deletions src/backend/catalog/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,15 +1510,15 @@ heap_create_with_catalog(const char *relname,
/*
* Get preassigned OID for GP_ROLE_EXECUTE or binary upgrade
*/
if (!OidIsValid(relid) && relpersistence != RELPERSISTENCE_FAST_TEMP && (Gp_role == GP_ROLE_EXECUTE || IsBinaryUpgrade))
if (!OidIsValid(relid) && (Gp_role == GP_ROLE_EXECUTE || IsBinaryUpgrade))
relid = GetPreassignedOidForRelation(relnamespace, relname);

/*
* GP_ROLE_DISPATCH and GP_ROLE_UTILITY do not have preassigned OIDs.
* Allocate new OIDs here.
*/
if (!OidIsValid(relid) && Gp_role != GP_ROLE_EXECUTE)
relid = GetNewOid(pg_class_desc);
if (!OidIsValid(relid) && (Gp_role != GP_ROLE_EXECUTE || relpersistence == RELPERSISTENCE_FAST_TEMP))
relid = GetNewOid(pg_class_desc, relpersistence);

/*
* Determine the relation's initial permissions.
Expand Down Expand Up @@ -1609,10 +1609,10 @@ heap_create_with_catalog(const char *relname,
true);

if (new_array_oid == InvalidOid && IsBinaryUpgrade)
new_array_oid = GetNewOid(pg_type);
new_array_oid = GetNewOid(pg_type, '\0');
}
else
new_array_oid = GetNewOid(pg_type);
new_array_oid = GetNewOid(pg_type, '\0');
heap_close(pg_type, AccessShareLock);
}

Expand Down
2 changes: 1 addition & 1 deletion src/backend/catalog/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ index_create(Relation heapRelation,
indexRelationId = GetPreassignedOidForRelation(namespaceId, indexRelationName);

if (!OidIsValid(indexRelationId))
indexRelationId = GetNewOid(pg_class);
indexRelationId = GetNewOid(pg_class, '\0');
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/backend/catalog/pg_enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ EnumValuesCreate(Oid enumTypeOid, List *vals)
{
do
{
new_oid = GetNewOid(pg_enum);
new_oid = GetNewOid(pg_enum, '\0');
} while (new_oid & 1);
}
oids[elemno] = new_oid;
Expand Down Expand Up @@ -370,7 +370,7 @@ AddEnumLabel(Oid enumTypeOid,
bool sorts_ok;

/* Get a new OID (different from all existing pg_enum tuples) */
newOid = GetNewOid(pg_enum);
newOid = GetNewOid(pg_enum, '\0');

/*
* Detect whether it sorts correctly relative to existing
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/dbcommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ createdb(const CreatedbStmt *stmt)
{
do
{
dboid = GetNewOid(pg_database_rel);
dboid = GetNewOid(pg_database_rel, '\0');
} while (check_db_file_conflict(dboid));
}

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 @@ -17390,7 +17390,7 @@ ATPExecPartExchange(AlteredTableInfo *tab, Relation rel, AlterPartitionCmd *pc)
if (Gp_role == GP_ROLE_EXECUTE)
array_oid = GetPreassignedOidForType(newnspid, relarrayname, true);
else
array_oid = GetNewOid(typrel);
array_oid = GetNewOid(typrel, '\0');

heap_close(typrel, AccessShareLock);

Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
if (OidIsValid(stmt->trigOid))
trigoid = stmt->trigOid;
else
trigoid = GetNewOid(tgrel);
trigoid = GetNewOid(tgrel, '\0');

/*
* If trigger is internally generated, modify the provided trigger name to
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/typecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ AssignTypeArrayOid(void)
{
Relation pg_type = heap_open(TypeRelationId, AccessShareLock);

type_array_oid = GetNewOid(pg_type);
type_array_oid = GetNewOid(pg_type, '\0');
heap_close(pg_type, AccessShareLock);
}

Expand Down
2 changes: 1 addition & 1 deletion src/include/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extern char* GetReservedPrefix(const char *name);

extern bool IsSharedRelation(Oid relationId);

extern Oid GetNewOid(Relation relation);
extern Oid GetNewOid(Relation relation, char target_persistence);
extern Oid GetNewOidWithIndex(Relation relation, Oid indexId,
AttrNumber oidcolumn);
extern Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class,
Expand Down

0 comments on commit 9f54d37

Please sign in to comment.