mirror of https://github.com/citusdata/citus.git
Apply feedback
parent
3a04374a9e
commit
2b0c4accda
|
@ -553,11 +553,7 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
|
||||||
{
|
{
|
||||||
List *placementAccessList = NIL;
|
List *placementAccessList = NIL;
|
||||||
|
|
||||||
/* we only need to calculate this once per shardInterval, not placement */
|
relationShardList = RelationShardListForShardCreate(shardInterval);
|
||||||
if (relationShardList == NIL)
|
|
||||||
{
|
|
||||||
relationShardList = RelationShardListForShardCreate(shardInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
placementAccessList = BuildPlacementDDLList(shardPlacement->groupId,
|
placementAccessList = BuildPlacementDDLList(shardPlacement->groupId,
|
||||||
relationShardList);
|
relationShardList);
|
||||||
|
@ -617,6 +613,7 @@ RelationShardListForShardCreate(ShardInterval *shardInterval)
|
||||||
List *allForeignKeyRelations =
|
List *allForeignKeyRelations =
|
||||||
list_concat_unique_oid(referencedRelationList, referencingRelationList);
|
list_concat_unique_oid(referencedRelationList, referencingRelationList);
|
||||||
int shardIndex = -1;
|
int shardIndex = -1;
|
||||||
|
ListCell *fkeyRelationIdCell = NULL;
|
||||||
|
|
||||||
/* record the placement access of the shard itself */
|
/* record the placement access of the shard itself */
|
||||||
relationShard = CitusMakeNode(RelationShard);
|
relationShard = CitusMakeNode(RelationShard);
|
||||||
|
@ -630,60 +627,60 @@ RelationShardListForShardCreate(ShardInterval *shardInterval)
|
||||||
shardIndex = ShardIndex(shardInterval);
|
shardIndex = ShardIndex(shardInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* all foregin constraint relations */
|
|
||||||
if (allForeignKeyRelations != NIL)
|
/* all foregin key constraint relations */
|
||||||
|
foreach(fkeyRelationIdCell, allForeignKeyRelations)
|
||||||
{
|
{
|
||||||
ListCell *relationIdCell = NULL;
|
Oid fkeyRelationid = lfirst_oid(fkeyRelationIdCell);
|
||||||
|
RelationShard *fkeyRelationShard = NULL;
|
||||||
|
uint64 fkeyShardId = INVALID_SHARD_ID;
|
||||||
|
|
||||||
foreach(relationIdCell, allForeignKeyRelations)
|
if (!IsDistributedTable(fkeyRelationid))
|
||||||
{
|
{
|
||||||
Oid fkeyRelationid = lfirst_oid(relationIdCell);
|
/* we're not interested in local tables */
|
||||||
RelationShard *fkeyRelationShard = NULL;
|
continue;
|
||||||
uint64 fkeyShardId = INVALID_SHARD_ID;
|
|
||||||
|
|
||||||
if (!IsDistributedTable(fkeyRelationid))
|
|
||||||
{
|
|
||||||
/* we're not interested in local tables */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PartitionMethod(fkeyRelationid) == DISTRIBUTE_BY_NONE)
|
|
||||||
{
|
|
||||||
fkeyShardId = GetFirstShardId(fkeyRelationid);
|
|
||||||
}
|
|
||||||
else if (cacheEntry->partitionMethod == DISTRIBUTE_BY_HASH &&
|
|
||||||
PartitionMethod(fkeyRelationid) == DISTRIBUTE_BY_HASH)
|
|
||||||
{
|
|
||||||
/* hash distributed tables should be colocated to have fkey */
|
|
||||||
Assert(TableColocationId(fkeyRelationid) == cacheEntry->colocationId);
|
|
||||||
|
|
||||||
fkeyShardId =
|
|
||||||
ColocatedShardIdInRelation(fkeyRelationid, shardIndex);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* We currently do not support foreign keys from/to local tables or
|
|
||||||
* non-colocated tables when creating shards. Also note that shard
|
|
||||||
* creation via shard moves doesn't happen in a transaction block,
|
|
||||||
* so not relevant here.
|
|
||||||
*/
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
fkeyRelationShard = CitusMakeNode(RelationShard);
|
|
||||||
fkeyRelationShard->relationId = fkeyRelationid;
|
|
||||||
fkeyRelationShard->shardId = fkeyShardId;
|
|
||||||
|
|
||||||
relationShardList = lappend(relationShardList, fkeyRelationShard);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PartitionMethod(fkeyRelationid) == DISTRIBUTE_BY_NONE)
|
||||||
|
{
|
||||||
|
fkeyShardId = GetFirstShardId(fkeyRelationid);
|
||||||
|
}
|
||||||
|
else if (cacheEntry->partitionMethod == DISTRIBUTE_BY_HASH &&
|
||||||
|
PartitionMethod(fkeyRelationid) == DISTRIBUTE_BY_HASH)
|
||||||
|
{
|
||||||
|
/* hash distributed tables should be colocated to have fkey */
|
||||||
|
Assert(TableColocationId(fkeyRelationid) == cacheEntry->colocationId);
|
||||||
|
|
||||||
|
fkeyShardId =
|
||||||
|
ColocatedShardIdInRelation(fkeyRelationid, shardIndex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* We currently do not support foreign keys from/to local tables or
|
||||||
|
* non-colocated tables when creating shards. Also note that shard
|
||||||
|
* creation via shard moves doesn't happen in a transaction block,
|
||||||
|
* so not relevant here.
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fkeyRelationShard = CitusMakeNode(RelationShard);
|
||||||
|
fkeyRelationShard->relationId = fkeyRelationid;
|
||||||
|
fkeyRelationShard->shardId = fkeyShardId;
|
||||||
|
|
||||||
|
relationShardList = lappend(relationShardList, fkeyRelationShard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* if partitioned table, make sure to record the parent table */
|
/* if partitioned table, make sure to record the parent table */
|
||||||
if (PartitionTable(relationId))
|
if (PartitionTable(relationId))
|
||||||
{
|
{
|
||||||
RelationShard *parentRelationShard = CitusMakeNode(RelationShard);
|
RelationShard *parentRelationShard = CitusMakeNode(RelationShard);
|
||||||
|
|
||||||
|
/* partitioned tables are always co-located */
|
||||||
|
Assert(shardIndex != -1);
|
||||||
|
|
||||||
parentRelationShard->relationId = PartitionParentOid(relationId);
|
parentRelationShard->relationId = PartitionParentOid(relationId);
|
||||||
parentRelationShard->shardId =
|
parentRelationShard->shardId =
|
||||||
ColocatedShardIdInRelation(parentRelationShard->relationId, shardIndex);
|
ColocatedShardIdInRelation(parentRelationShard->relationId, shardIndex);
|
||||||
|
@ -697,7 +694,7 @@ RelationShardListForShardCreate(ShardInterval *shardInterval)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WorkerCreateShardCommandList returns a list of DDL commands for the given
|
* WorkerCreateShardCommandList returns a list of DDL commands for the given
|
||||||
* shardId to create the shard on the worker node.
|
* shardId to create the shard on the worker node.
|
||||||
*/
|
*/
|
||||||
List *
|
List *
|
||||||
WorkerCreateShardCommandList(Oid relationId, int shardIndex, uint64 shardId,
|
WorkerCreateShardCommandList(Oid relationId, int shardIndex, uint64 shardId,
|
||||||
|
|
Loading…
Reference in New Issue