mirror of https://github.com/citusdata/citus.git
Improve relation accesses association to do less job
parent
8ccb8b679e
commit
7d0f7835e7
|
@ -66,6 +66,7 @@ typedef struct RelationAccessHashEntry
|
||||||
static HTAB *RelationAccessHash;
|
static HTAB *RelationAccessHash;
|
||||||
|
|
||||||
|
|
||||||
|
static void RecordRelationAccess(Oid relationId, ShardPlacementAccessType accessType);
|
||||||
static void RecordPlacementAccessToCache(Oid relationId,
|
static void RecordPlacementAccessToCache(Oid relationId,
|
||||||
ShardPlacementAccessType accessType);
|
ShardPlacementAccessType accessType);
|
||||||
static RelationAccessMode GetRelationAccessMode(Oid relationId,
|
static RelationAccessMode GetRelationAccessMode(Oid relationId,
|
||||||
|
@ -115,8 +116,8 @@ void
|
||||||
AssociatePlacementAccessWithRelation(ShardPlacement *placement,
|
AssociatePlacementAccessWithRelation(ShardPlacement *placement,
|
||||||
ShardPlacementAccessType accessType)
|
ShardPlacementAccessType accessType)
|
||||||
{
|
{
|
||||||
uint64 shardId = INVALID_SHARD_ID;
|
|
||||||
Oid relationId = InvalidOid;
|
Oid relationId = InvalidOid;
|
||||||
|
uint64 shardId = INVALID_SHARD_ID;
|
||||||
|
|
||||||
if (!ShouldRecordRelationAccess())
|
if (!ShouldRecordRelationAccess())
|
||||||
{
|
{
|
||||||
|
@ -126,6 +127,21 @@ AssociatePlacementAccessWithRelation(ShardPlacement *placement,
|
||||||
shardId = placement->shardId;
|
shardId = placement->shardId;
|
||||||
relationId = RelationIdForShard(shardId);
|
relationId = RelationIdForShard(shardId);
|
||||||
|
|
||||||
|
RecordRelationAccess(relationId, accessType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RecordRelationAccess associates the access to the distributed relation. The
|
||||||
|
* function takes partitioned relations into account as well.
|
||||||
|
*
|
||||||
|
* We implemented this function to prevent accessing placement metadata during
|
||||||
|
* recursive calls of the function itself (e.g., avoid
|
||||||
|
* AssociatePlacementAccessWithRelation()).
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
RecordRelationAccess(Oid relationId, ShardPlacementAccessType accessType)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* If a relation is partitioned, record accesses to all of its partitions as well.
|
* If a relation is partitioned, record accesses to all of its partitions as well.
|
||||||
* We prefer to use PartitionedTableNoLock() because at this point the necessary
|
* We prefer to use PartitionedTableNoLock() because at this point the necessary
|
||||||
|
@ -134,16 +150,11 @@ AssociatePlacementAccessWithRelation(ShardPlacement *placement,
|
||||||
if (PartitionedTableNoLock(relationId))
|
if (PartitionedTableNoLock(relationId))
|
||||||
{
|
{
|
||||||
List *partitionList = PartitionList(relationId);
|
List *partitionList = PartitionList(relationId);
|
||||||
ShardInterval *shardInterval = LoadShardInterval(shardId);
|
|
||||||
int shardIndex = shardInterval->shardIndex;
|
|
||||||
ListCell *partitionCell = NULL;
|
ListCell *partitionCell = NULL;
|
||||||
|
|
||||||
foreach(partitionCell, partitionList)
|
foreach(partitionCell, partitionList)
|
||||||
{
|
{
|
||||||
Oid partitionOid = lfirst_oid(partitionCell);
|
Oid partitionOid = lfirst_oid(partitionCell);
|
||||||
uint64 partitionShardId = INVALID_SHARD_ID;
|
|
||||||
List *partitionShardPlacementList = NIL;
|
|
||||||
ShardPlacement *partitionInitialShardPlacement = NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* During create_distributed_table, the partitions may not
|
* During create_distributed_table, the partitions may not
|
||||||
|
@ -156,29 +167,19 @@ AssociatePlacementAccessWithRelation(ShardPlacement *placement,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
partitionShardId =
|
/* recursively call the function to cover multi-level partitioned tables */
|
||||||
ColocatedShardIdInRelation(partitionOid, shardIndex);
|
RecordRelationAccess(partitionOid, accessType);
|
||||||
partitionShardPlacementList = ShardPlacementList(partitionShardId);
|
|
||||||
partitionInitialShardPlacement =
|
|
||||||
(ShardPlacement *) linitial(partitionShardPlacementList);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Recursively record all relation accesses of its partitions. Note that
|
|
||||||
* we prefer to recursively call AssociatePlacementAccessWithRelation()
|
|
||||||
* to support multi-level partitioned tables.
|
|
||||||
*/
|
|
||||||
AssociatePlacementAccessWithRelation(partitionInitialShardPlacement,
|
|
||||||
accessType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (PartitionTableNoLock(relationId))
|
else if (PartitionTableNoLock(relationId))
|
||||||
{
|
{
|
||||||
Oid parentOid = PartitionParentOid(relationId);
|
Oid parentOid = PartitionParentOid(relationId);
|
||||||
|
|
||||||
/* only record the parent */
|
/* record the parent */
|
||||||
RecordPlacementAccessToCache(parentOid, accessType);
|
RecordPlacementAccessToCache(parentOid, accessType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* always record the relation that is being considered */
|
||||||
RecordPlacementAccessToCache(relationId, accessType);
|
RecordPlacementAccessToCache(relationId, accessType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue