mirror of https://github.com/citusdata/citus.git
Refactor RelationIsAKnownShard to remove onlySearchPath argument
parent
089ef35940
commit
e81d25a7be
|
@ -43,9 +43,19 @@ relation_is_a_known_shard(PG_FUNCTION_ARGS)
|
|||
CheckCitusVersion(ERROR);
|
||||
|
||||
Oid relationId = PG_GETARG_OID(0);
|
||||
bool onlySearchPath = true;
|
||||
|
||||
PG_RETURN_BOOL(RelationIsAKnownShard(relationId, onlySearchPath));
|
||||
if (!RelationIsVisible(relationId))
|
||||
{
|
||||
/*
|
||||
* Relation is not on the search path.
|
||||
*
|
||||
* TODO: it might be nicer to add a separate check in the
|
||||
* citus_shards_on_worker views where this UDF is used.
|
||||
*/
|
||||
PG_RETURN_BOOL(false);
|
||||
}
|
||||
|
||||
PG_RETURN_BOOL(RelationIsAKnownShard(relationId));
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,7 +71,6 @@ citus_table_is_visible(PG_FUNCTION_ARGS)
|
|||
|
||||
Oid relationId = PG_GETARG_OID(0);
|
||||
char relKind = '\0';
|
||||
bool onlySearchPath = true;
|
||||
|
||||
/*
|
||||
* We don't want to deal with not valid/existing relations
|
||||
|
@ -72,7 +81,13 @@ citus_table_is_visible(PG_FUNCTION_ARGS)
|
|||
PG_RETURN_NULL();
|
||||
}
|
||||
|
||||
if (RelationIsAKnownShard(relationId, onlySearchPath))
|
||||
if (!RelationIsVisible(relationId))
|
||||
{
|
||||
/* relation is not on the search path */
|
||||
PG_RETURN_BOOL(false);
|
||||
}
|
||||
|
||||
if (RelationIsAKnownShard(relationId))
|
||||
{
|
||||
/*
|
||||
* If the input relation is an index we simply replace the
|
||||
|
@ -106,9 +121,7 @@ citus_table_is_visible(PG_FUNCTION_ARGS)
|
|||
void
|
||||
ErrorIfRelationIsAKnownShard(Oid relationId)
|
||||
{
|
||||
/* search the relation in all schemas */
|
||||
bool onlySearchPath = false;
|
||||
if (!RelationIsAKnownShard(relationId, onlySearchPath))
|
||||
if (!RelationIsAKnownShard(relationId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -133,9 +146,7 @@ ErrorIfIllegallyChangingKnownShard(Oid relationId)
|
|||
return;
|
||||
}
|
||||
|
||||
/* search the relation in all schemas */
|
||||
bool onlySearchPath = true;
|
||||
if (RelationIsAKnownShard(relationId, onlySearchPath))
|
||||
if (RelationIsAKnownShard(relationId))
|
||||
{
|
||||
const char *relationName = get_rel_name(relationId);
|
||||
ereport(ERROR, (errmsg("cannot modify \"%s\" because it is a shard of "
|
||||
|
@ -150,14 +161,13 @@ ErrorIfIllegallyChangingKnownShard(Oid relationId)
|
|||
|
||||
/*
|
||||
* RelationIsAKnownShard gets a relationId, check whether it's a shard of
|
||||
* any distributed table. If onlySearchPath is true, then it searches
|
||||
* the current search path.
|
||||
* any distributed table.
|
||||
*
|
||||
* We can only do that in MX since both the metadata and tables are only
|
||||
* present there.
|
||||
*/
|
||||
bool
|
||||
RelationIsAKnownShard(Oid shardRelationId, bool onlySearchPath)
|
||||
RelationIsAKnownShard(Oid shardRelationId)
|
||||
{
|
||||
bool missingOk = true;
|
||||
char relKind = '\0';
|
||||
|
@ -191,12 +201,6 @@ RelationIsAKnownShard(Oid shardRelationId, bool onlySearchPath)
|
|||
}
|
||||
relation_close(relation, NoLock);
|
||||
|
||||
/* we're not interested in the relations that are not in the search path */
|
||||
if (!RelationIsVisible(shardRelationId) && onlySearchPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the input relation is an index we simply replace the
|
||||
* relationId with the corresponding relation to hide indexes
|
||||
|
|
|
@ -20,7 +20,7 @@ extern bool EnableManualChangesToShards;
|
|||
extern void ReplaceTableVisibleFunction(Node *inputNode);
|
||||
extern void ErrorIfRelationIsAKnownShard(Oid relationId);
|
||||
extern void ErrorIfIllegallyChangingKnownShard(Oid relationId);
|
||||
extern bool RelationIsAKnownShard(Oid shardRelationId, bool onlySearchPath);
|
||||
extern bool RelationIsAKnownShard(Oid shardRelationId);
|
||||
|
||||
|
||||
#endif /* WORKER_SHARD_VISIBILITY_H */
|
||||
|
|
Loading…
Reference in New Issue