mirror of https://github.com/citusdata/citus.git
Add function for dependency check
parent
c4fddf1406
commit
a29748db0e
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue