Add function for dependency check

velioglu/tmpfuncprop
Burak Velioglu 2022-02-09 14:55:22 +03:00
parent c4fddf1406
commit a29748db0e
No known key found for this signature in database
GPG Key ID: F6827E620F6549C6
2 changed files with 31 additions and 15 deletions

View File

@ -1306,8 +1306,35 @@ PostprocessCreateFunctionStmt(Node *node, const char *queryString)
} }
ObjectAddress address = GetObjectAddressFromParseTree((Node *) stmt, false); 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; ObjectAddress *dependency = NULL;
foreach_ptr(dependency, dependencies) foreach_ptr(dependency, dependencies)
{ {
@ -1324,23 +1351,11 @@ PostprocessCreateFunctionStmt(Node *node, const char *queryString)
relKind == RELKIND_FOREIGN_TABLE || relKind == RELKIND_FOREIGN_TABLE ||
relKind == RELKIND_SEQUENCE) relKind == RELKIND_SEQUENCE)
{ {
/* TODO: Consider changing the check and log message */ return true;
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;
} }
} }
EnsureDependenciesExistOnAllNodes(&address); return false;
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);
} }

View File

@ -259,6 +259,7 @@ extern List * PreprocessCreateFunctionStmt(Node *stmt, const char *queryString,
ProcessUtilityContext processUtilityContext); ProcessUtilityContext processUtilityContext);
extern List * PostprocessCreateFunctionStmt(Node *stmt, extern List * PostprocessCreateFunctionStmt(Node *stmt,
const char *queryString); const char *queryString);
extern bool FunctionDependsOnNonDistributedRelation(ObjectAddress *functionAddress);
extern ObjectAddress CreateFunctionStmtObjectAddress(Node *stmt, extern ObjectAddress CreateFunctionStmtObjectAddress(Node *stmt,
bool missing_ok); bool missing_ok);
extern ObjectAddress DefineAggregateStmtObjectAddress(Node *stmt, extern ObjectAddress DefineAggregateStmtObjectAddress(Node *stmt,