From a29748db0eb0f0e6b35192e7a25c650379a64864 Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Wed, 9 Feb 2022 14:55:22 +0300 Subject: [PATCH] Add function for dependency check --- src/backend/distributed/commands/function.c | 45 ++++++++++++++------- src/include/distributed/commands.h | 1 + 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/backend/distributed/commands/function.c b/src/backend/distributed/commands/function.c index 8577957c4..37c040f0f 100644 --- a/src/backend/distributed/commands/function.c +++ b/src/backend/distributed/commands/function.c @@ -1306,8 +1306,35 @@ PostprocessCreateFunctionStmt(Node *node, const char *queryString) } ObjectAddress address = GetObjectAddressFromParseTree((Node *) stmt, false); + if (FunctionDependsOnNonDistributedRelation(&address)) + { + ereport(WARNING, (errmsg("Citus can't distribute functions having dependency on" + " non-distributed relations or sequences"), + errdetail("Function will be created only locally"), + errhint("To distribute function, distribute dependent relations" + " and sequences first"))); + return NIL; + } - List *dependencies = GetDependenciesForObject(&address); + EnsureDependenciesExistOnAllNodes(&address); + + List *commands = list_make1(DISABLE_DDL_PROPAGATION); + commands = list_concat(commands, CreateFunctionDDLCommandsIdempotent(&address)); + commands = list_concat(commands, list_make1(ENABLE_DDL_PROPAGATION)); + + return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); +} + +/* + * FunctionDependsOnNonDistributedRelation checks whether the given function depends + * on non-distributed relation. + */ +bool +FunctionDependsOnNonDistributedRelation(ObjectAddress *functionAddress) +{ + Assert(getObjectClass(functionAddress) == OCLASS_PROC); + + List *dependencies = GetDependenciesForObject(functionAddress); ObjectAddress *dependency = NULL; foreach_ptr(dependency, dependencies) { @@ -1324,23 +1351,11 @@ PostprocessCreateFunctionStmt(Node *node, const char *queryString) relKind == RELKIND_FOREIGN_TABLE || relKind == RELKIND_SEQUENCE) { - /* TODO: Consider changing the check and log message */ - ereport(WARNING, (errmsg( - "Citus can't distribute functions having dependency on non-distributed relations or sequences"), - errdetail("Function will be created only locally"), - errhint( - "To distribute function, distribute dependent relations and sequences first"))); - return NIL; + return true; } } - EnsureDependenciesExistOnAllNodes(&address); - - List *commands = list_make1(DISABLE_DDL_PROPAGATION); - commands = list_concat(commands, CreateFunctionDDLCommandsIdempotent(&address)); - commands = list_concat(commands, list_make1(ENABLE_DDL_PROPAGATION)); - - return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); + return false; } diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 41141ee8a..bb67d34b8 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -259,6 +259,7 @@ extern List * PreprocessCreateFunctionStmt(Node *stmt, const char *queryString, ProcessUtilityContext processUtilityContext); extern List * PostprocessCreateFunctionStmt(Node *stmt, const char *queryString); +extern bool FunctionDependsOnNonDistributedRelation(ObjectAddress *functionAddress); extern ObjectAddress CreateFunctionStmtObjectAddress(Node *stmt, bool missing_ok); extern ObjectAddress DefineAggregateStmtObjectAddress(Node *stmt,