mirror of https://github.com/citusdata/citus.git
Suggestions on the PR
parent
ca757b5bc5
commit
cb2538a5f0
|
@ -482,6 +482,8 @@ CreateDistributedTable(Oid relationId, Var *distributionColumn, char distributio
|
|||
/* we need to calculate these variables before creating distributed metadata */
|
||||
bool localTableEmpty = TableEmpty(relationId);
|
||||
Oid colocatedTableId = ColocatedTableId(colocationId);
|
||||
|
||||
/* setting to false since this flag is only valid for citus local tables */
|
||||
bool autoConverted = false;
|
||||
|
||||
/* create an entry for distributed table in pg_dist_partition */
|
||||
|
|
|
@ -70,6 +70,8 @@ static void ErrorIfAttachCitusTableToPgLocalTable(Oid parentRelationId,
|
|||
Oid partitionRelationId);
|
||||
static bool AlterTableDefinesFKeyBetweenPostgresAndNonDistTable(
|
||||
AlterTableStmt *alterTableStatement);
|
||||
static bool ShouldMarkConnectedRelationsNotAutoConverted(Oid leftRelationId,
|
||||
Oid rightRelationId);
|
||||
static void MarkConnectedRelationsNotAutoConverted(Oid leftRelationId,
|
||||
Oid rightRelationId);
|
||||
static bool RelationIdListContainsCitusTableType(List *relationIdList,
|
||||
|
@ -494,7 +496,8 @@ PreprocessAttachPartitionToCitusTable(Oid parentRelationId, Oid partitionRelatio
|
|||
* cannot have non-inherited foreign keys.
|
||||
*/
|
||||
bool cascadeViaForeignKeys = false;
|
||||
bool autoConverted = true;
|
||||
CitusTableCacheEntry *entry = GetCitusTableCacheEntry(parentRelationId);
|
||||
bool autoConverted = entry->autoConverted;
|
||||
CreateCitusLocalTable(partitionRelationId, cascadeViaForeignKeys,
|
||||
autoConverted);
|
||||
}
|
||||
|
@ -863,7 +866,12 @@ PreprocessAlterTableStmt(Node *node, const char *alterTableCommand,
|
|||
rightRelationId = RangeVarGetRelid(constraint->pktable, lockmode,
|
||||
alterTableStatement->missing_ok);
|
||||
|
||||
MarkConnectedRelationsNotAutoConverted(leftRelationId, rightRelationId);
|
||||
if (ShouldMarkConnectedRelationsNotAutoConverted(leftRelationId,
|
||||
rightRelationId))
|
||||
{
|
||||
MarkConnectedRelationsNotAutoConverted(leftRelationId,
|
||||
rightRelationId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Foreign constraint validations will be done in workers. If we do not
|
||||
|
@ -1178,36 +1186,42 @@ AlterTableDefinesFKeyBetweenPostgresAndNonDistTable(AlterTableStmt *alterTableSt
|
|||
|
||||
|
||||
/*
|
||||
* MarkConnectedRelationsNotAutoConverted takes two relations. If both of them are Citus Local
|
||||
* Tables, and one of them is auto-converted while the other one is not; then it
|
||||
* marks both of them as not-auto-converted, as well as other connected relations.
|
||||
* ShouldMarkConnectedRelationsNotAutoConverted takes two relations.
|
||||
* If both of them are Citus Local Tables, and one of them is auto-converted while the
|
||||
* other one is not; then it returns true. False otherwise.
|
||||
*/
|
||||
static void
|
||||
MarkConnectedRelationsNotAutoConverted(Oid leftRelationId, Oid rightRelationId)
|
||||
static bool
|
||||
ShouldMarkConnectedRelationsNotAutoConverted(Oid leftRelationId, Oid rightRelationId)
|
||||
{
|
||||
if (!IsCitusTable(leftRelationId) || !IsCitusTable(rightRelationId))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsCitusTableType(leftRelationId, CITUS_LOCAL_TABLE))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsCitusTableType(rightRelationId, CITUS_LOCAL_TABLE))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
CitusTableCacheEntry *entryLeft = GetCitusTableCacheEntry(leftRelationId);
|
||||
CitusTableCacheEntry *entryRight = GetCitusTableCacheEntry(rightRelationId);
|
||||
|
||||
if (entryLeft->autoConverted == entryRight->autoConverted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return entryLeft->autoConverted != entryRight->autoConverted;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MarkConnectedRelationsNotAutoConverted takes two relations.
|
||||
* Marks both of them as not-auto-converted, as well as other connected relations.
|
||||
*/
|
||||
static void
|
||||
MarkConnectedRelationsNotAutoConverted(Oid leftRelationId, Oid rightRelationId)
|
||||
{
|
||||
List *leftConnectedRelIds = GetForeignKeyConnectedRelationIdList(leftRelationId);
|
||||
List *rightConnectedRelIds = GetForeignKeyConnectedRelationIdList(rightRelationId);
|
||||
List *allConnectedRelations = list_concat_unique_oid(leftConnectedRelIds,
|
||||
|
|
|
@ -2074,6 +2074,8 @@ citus_internal_add_partition_metadata(PG_FUNCTION_ARGS)
|
|||
text *distributionColumnText = NULL;
|
||||
char *distributionColumnString = NULL;
|
||||
Var *distributionColumnVar = NULL;
|
||||
|
||||
/* this flag is only valid for citus local tables, so set it to false */
|
||||
bool autoConverted = false;
|
||||
|
||||
/* only owner of the table (or superuser) is allowed to add the Citus metadata */
|
||||
|
|
|
@ -2072,10 +2072,10 @@ UpdatePlacementGroupId(uint64 placementId, int groupId)
|
|||
|
||||
/*
|
||||
* UpdatePartitionAutoConverted sets the autoConverted for the partition identified
|
||||
* by distributedRelationId.
|
||||
* by citusTableId.
|
||||
*/
|
||||
void
|
||||
UpdatePartitionAutoConverted(Oid distributedRelationId, bool autoConverted)
|
||||
UpdatePartitionAutoConverted(Oid citusTableId, bool autoConverted)
|
||||
{
|
||||
ScanKeyData scanKey[1];
|
||||
int scanKeyCount = 1;
|
||||
|
@ -2087,7 +2087,7 @@ UpdatePartitionAutoConverted(Oid distributedRelationId, bool autoConverted)
|
|||
Relation pgDistPartition = table_open(DistPartitionRelationId(), RowExclusiveLock);
|
||||
TupleDesc tupleDescriptor = RelationGetDescr(pgDistPartition);
|
||||
ScanKeyInit(&scanKey[0], Anum_pg_dist_partition_logicalrelid,
|
||||
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(distributedRelationId));
|
||||
BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(citusTableId));
|
||||
|
||||
SysScanDesc scanDescriptor = systable_beginscan(pgDistPartition,
|
||||
DistPartitionLogicalRelidIndexId(),
|
||||
|
@ -2097,8 +2097,8 @@ UpdatePartitionAutoConverted(Oid distributedRelationId, bool autoConverted)
|
|||
HeapTuple heapTuple = systable_getnext(scanDescriptor);
|
||||
if (!HeapTupleIsValid(heapTuple))
|
||||
{
|
||||
ereport(ERROR, (errmsg("could not find valid entry for partition oid: %u",
|
||||
distributedRelationId)));
|
||||
ereport(ERROR, (errmsg("could not find valid entry for citus table with oid: %u",
|
||||
citusTableId)));
|
||||
}
|
||||
|
||||
memset(replace, 0, sizeof(replace));
|
||||
|
@ -2111,7 +2111,7 @@ UpdatePartitionAutoConverted(Oid distributedRelationId, bool autoConverted)
|
|||
|
||||
CatalogTupleUpdate(pgDistPartition, &heapTuple->t_self, heapTuple);
|
||||
|
||||
CitusInvalidateRelcacheByRelid(distributedRelationId);
|
||||
CitusInvalidateRelcacheByRelid(citusTableId);
|
||||
|
||||
CommandCounterIncrement();
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ extern uint64 InsertShardPlacementRow(uint64 shardId, uint64 placementId,
|
|||
extern void InsertIntoPgDistPartition(Oid relationId, char distributionMethod,
|
||||
Var *distributionColumn, uint32 colocationId,
|
||||
char replicationModel, bool autoConverted);
|
||||
extern void UpdatePartitionAutoConverted(Oid distributedRelationId, bool autoConverted);
|
||||
extern void UpdatePartitionAutoConverted(Oid citusTableId, bool autoConverted);
|
||||
extern void DeletePartitionRow(Oid distributedRelationId);
|
||||
extern void DeleteShardRow(uint64 shardId);
|
||||
extern void UpdateShardPlacementState(uint64 placementId, char shardState);
|
||||
|
|
Loading…
Reference in New Issue