Update function dep check

velioglu/tmpfuncprop
Burak Velioglu 2022-02-13 17:17:46 +03:00
parent e249aa2d62
commit a58c15268b
No known key found for this signature in database
GPG Key ID: F6827E620F6549C6
2 changed files with 19 additions and 15 deletions

View File

@ -1328,13 +1328,13 @@ PostprocessCreateFunctionStmt(Node *node, const char *queryString)
} }
ObjectAddress address = GetObjectAddressFromParseTree((Node *) stmt, false); ObjectAddress address = GetObjectAddressFromParseTree((Node *) stmt, false);
if (FunctionDependsOnNonDistributedRelation(&address)) if (!DependentRelationsOfFunctionCanBeDistributed(&address))
{ {
ereport(WARNING, (errmsg("Citus can't distribute functions having dependency on" ereport(WARNING, (errmsg("Citus can't distribute functions having dependency on"
" non-distributed relations or sequences"), " non-distributed relations"),
errdetail("Function will be created only locally"), errdetail("Function will be created only locally"),
errhint("To distribute function, distribute dependent relations" errhint("To distribute function, distribute dependent relations"
" and sequences first"))); " first")));
return NIL; return NIL;
} }
@ -1349,11 +1349,11 @@ PostprocessCreateFunctionStmt(Node *node, const char *queryString)
/* /*
* FunctionDependsOnNonDistributedRelation checks whether the given function depends * DependentRelationsOfFunctionCanBeDistributed checks whether Citus can distribute
* on non-distributed relation. * dependent relations of the given function.
*/ */
bool bool
FunctionDependsOnNonDistributedRelation(ObjectAddress *functionAddress) DependentRelationsOfFunctionCanBeDistributed(ObjectAddress *functionAddress)
{ {
Assert(getObjectClass(functionAddress) == OCLASS_PROC); Assert(getObjectClass(functionAddress) == OCLASS_PROC);
@ -1366,21 +1366,25 @@ FunctionDependsOnNonDistributedRelation(ObjectAddress *functionAddress)
continue; continue;
} }
/*
* Since GetDependenciesForObject returns only non-distributed ones, any
* relation comes to that point is must be a non-distributed one.
*
* Citus can only distribute dependent non-distributed sequence and composite
* types.
*/
char relKind = get_rel_relkind(dependency->objectId); char relKind = get_rel_relkind(dependency->objectId);
if (relKind == RELKIND_SEQUENCE || relKind == RELKIND_COMPOSITE_TYPE)
/* only distributed ones are allowed */
if (relKind == RELKIND_RELATION ||
relKind == RELKIND_PARTITIONED_TABLE ||
relKind == RELKIND_FOREIGN_TABLE ||
relKind == RELKIND_SEQUENCE)
{ {
return true; continue;
}
} }
return false; return false;
} }
return true;
}
/* /*
* CreateFunctionStmtObjectAddress returns the ObjectAddress for the subject of the * CreateFunctionStmtObjectAddress returns the ObjectAddress for the subject of the

View File

@ -259,7 +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 bool DependentRelationsOfFunctionCanBeDistributed(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,