add a utility to get shard oid from relation oid and shard id (#3596)

pull/3598/head
SaitTalhaNisanci 2020-03-09 15:50:29 +03:00 committed by GitHub
parent 4509d9a72b
commit 321d0152c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 8 deletions

View File

@ -22,6 +22,7 @@
#include "distributed/metadata_cache.h"
#include "distributed/multi_physical_planner.h"
#include "distributed/multi_router_planner.h"
#include "distributed/shard_utils.h"
#include "distributed/version_compat.h"
#include "lib/stringinfo.h"
#include "nodes/makefuncs.h"
@ -334,15 +335,9 @@ UpdateRelationsToLocalShardTables(Node *node, List *relationShardList)
return true;
}
uint64 shardId = relationShard->shardId;
Oid relationId = relationShard->relationId;
Oid shardOid = GetShardOid(relationShard->relationId, relationShard->shardId);
char *relationName = get_rel_name(relationId);
AppendShardIdToName(&relationName, shardId);
Oid schemaId = get_rel_namespace(relationId);
newRte->relid = get_relname_relid(relationName, schemaId);
newRte->relid = shardOid;
return false;
}

View File

@ -0,0 +1,31 @@
/*-------------------------------------------------------------------------
*
* shard_utils.c
*
* This file contains functions to perform useful operations on shards.
*
* Copyright (c) Citus Data, Inc.
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "utils/lsyscache.h"
#include "distributed/relay_utility.h"
#include "distributed/shard_utils.h"
/*
* GetShardOid returns the oid of the shard from the given distributed relation
* with the shardid.
*/
Oid
GetShardOid(Oid distRelId, uint64 shardId)
{
char *relationName = get_rel_name(distRelId);
AppendShardIdToName(&relationName, shardId);
Oid schemaId = get_rel_namespace(distRelId);
return get_relname_relid(relationName, schemaId);
}

View File

@ -0,0 +1,18 @@
/*-------------------------------------------------------------------------
*
* shard_utils.h
* Utilities related to shards.
*
* Copyright (c) Citus Data, Inc.
*
*-------------------------------------------------------------------------
*/
#ifndef SHARD_UTILS_H
#define SHARD_UTILS_H
#include "postgres.h"
extern Oid GetShardOid(Oid distRelId, uint64 shardId);
#endif /* SHARD_UTILS_H */