implement GetOnlyShardOidOfReferenceTable and some refactor in shard_uitls

pull/3701/head
Onur Tirtir 2020-04-03 17:11:14 +03:00
parent 459a4829ae
commit 13a35c6813
4 changed files with 39 additions and 11 deletions

View File

@ -159,7 +159,7 @@ DoLocalCopy(StringInfo buffer, Oid relationId, int64 shardId, CopyStmt *copyStat
*/ */
LocalCopyBuffer = buffer; LocalCopyBuffer = buffer;
Oid shardOid = GetShardLocalTableOid(relationId, shardId); Oid shardOid = GetTableLocalShardOid(relationId, shardId);
Relation shard = heap_open(shardOid, RowExclusiveLock); Relation shard = heap_open(shardOid, RowExclusiveLock);
ParseState *pState = make_parsestate(NULL); ParseState *pState = make_parsestate(NULL);

View File

@ -339,7 +339,7 @@ UpdateRelationsToLocalShardTables(Node *node, List *relationShardList)
return true; return true;
} }
Oid shardOid = GetShardLocalTableOid(relationShard->relationId, Oid shardOid = GetTableLocalShardOid(relationShard->relationId,
relationShard->shardId); relationShard->shardId);
newRte->relid = shardOid; newRte->relid = shardOid;

View File

@ -11,21 +11,48 @@
#include "postgres.h" #include "postgres.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "distributed/metadata_cache.h"
#include "distributed/relay_utility.h" #include "distributed/relay_utility.h"
#include "distributed/shard_utils.h" #include "distributed/shard_utils.h"
/* /*
* GetShardLocalTableOid returns the oid of the shard from the given distributed relation * GetTableLocalShardOid returns the oid of the shard from the given distributed
* with the shardid. * relation with the shardId.
*/ */
Oid Oid
GetShardLocalTableOid(Oid distRelId, uint64 shardId) GetTableLocalShardOid(Oid citusTableOid, uint64 shardId)
{ {
char *relationName = get_rel_name(distRelId); const char *citusTableName = get_rel_name(citusTableOid);
AppendShardIdToName(&relationName, shardId);
Oid schemaId = get_rel_namespace(distRelId); Assert(citusTableName != NULL);
return get_relname_relid(relationName, schemaId); /* construct shard relation name */
char *shardRelationName = pstrdup(citusTableName);
AppendShardIdToName(&shardRelationName, shardId);
Oid citusTableSchemaOid = get_rel_namespace(citusTableOid);
Oid shardRelationOid = get_relname_relid(shardRelationName, citusTableSchemaOid);
return shardRelationOid;
}
/*
* GetReferenceTableLocalShardOid returns OID of the local shard of given
* reference table. Caller of this function must ensure that referenceTableOid
* is owned by a reference table.
*/
Oid
GetReferenceTableLocalShardOid(Oid referenceTableOid)
{
const CitusTableCacheEntry *cacheEntry = GetCitusTableCacheEntry(referenceTableOid);
/* given OID should belong to a valid reference table */
Assert(cacheEntry != NULL && cacheEntry->partitionMethod == DISTRIBUTE_BY_NONE);
const ShardInterval *shardInterval = cacheEntry->sortedShardIntervalArray[0];
uint64 referenceTableShardId = shardInterval->shardId;
return GetTableLocalShardOid(referenceTableOid, referenceTableShardId);
} }

View File

@ -13,6 +13,7 @@
#include "postgres.h" #include "postgres.h"
extern Oid GetShardLocalTableOid(Oid distRelId, uint64 shardId); extern Oid GetTableLocalShardOid(Oid citusTableOid, uint64 shardId);
extern Oid GetReferenceTableLocalShardOid(Oid referenceTableOid);
#endif /* SHARD_UTILS_H */ #endif /* SHARD_UTILS_H */