From e81d25a7be8844e46b256aa69c5207766f0588c9 Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Wed, 2 Jun 2021 13:51:39 +0200 Subject: [PATCH] Refactor RelationIsAKnownShard to remove onlySearchPath argument --- .../worker/worker_shard_visibility.c | 42 ++++++++++--------- .../distributed/worker_shard_visibility.h | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/backend/distributed/worker/worker_shard_visibility.c b/src/backend/distributed/worker/worker_shard_visibility.c index 53132d1db..05b8e0bad 100644 --- a/src/backend/distributed/worker/worker_shard_visibility.c +++ b/src/backend/distributed/worker/worker_shard_visibility.c @@ -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 diff --git a/src/include/distributed/worker_shard_visibility.h b/src/include/distributed/worker_shard_visibility.h index 85c48a758..c5c58d712 100644 --- a/src/include/distributed/worker_shard_visibility.h +++ b/src/include/distributed/worker_shard_visibility.h @@ -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 */