diff --git a/src/backend/distributed/commands/collation.c b/src/backend/distributed/commands/collation.c index 12bf1404a..8bfde6ad4 100644 --- a/src/backend/distributed/commands/collation.c +++ b/src/backend/distributed/commands/collation.c @@ -300,6 +300,32 @@ PreprocessAlterCollationOwnerStmt(Node *node, const char *queryString, } +/* + * PostprocessAlterCollationOwnerStmt is invoked after the owner has been changed locally. + * Since changing the owner could result in new dependencies being found for this object + * we re-ensure all the dependencies for the collation do exist. + * + * This is solely to propagate the new owner (and all its dependencies) if it was not + * already distributed in the cluster. + */ +List * +PostprocessAlterCollationOwnerStmt(Node *node, const char *queryString) +{ + AlterOwnerStmt *stmt = castNode(AlterOwnerStmt, node); + Assert(stmt->objectType == OBJECT_COLLATION); + + ObjectAddress collationAddress = GetObjectAddressFromParseTree((Node *) stmt, false); + if (!ShouldPropagateObject(&collationAddress)) + { + return NIL; + } + + EnsureDependenciesExistOnAllNodes(&collationAddress); + + return NIL; +} + + /* * PreprocessRenameCollationStmt is called when the user is renaming the collation. The invocation happens * before the statement is applied locally. diff --git a/src/backend/distributed/commands/distribute_object_ops.c b/src/backend/distributed/commands/distribute_object_ops.c index 80a2b6628..8b5fc3b96 100644 --- a/src/backend/distributed/commands/distribute_object_ops.c +++ b/src/backend/distributed/commands/distribute_object_ops.c @@ -37,7 +37,7 @@ static DistributeObjectOps Aggregate_AlterOwner = { .deparse = DeparseAlterFunctionOwnerStmt, .qualify = QualifyAlterFunctionOwnerStmt, .preprocess = PreprocessAlterFunctionOwnerStmt, - .postprocess = NULL, + .postprocess = PostprocessAlterFunctionOwnerStmt, .address = AlterFunctionOwnerObjectAddress, .markDistributed = false, }; @@ -269,7 +269,7 @@ static DistributeObjectOps Collation_AlterOwner = { .deparse = DeparseAlterCollationOwnerStmt, .qualify = QualifyAlterCollationOwnerStmt, .preprocess = PreprocessAlterCollationOwnerStmt, - .postprocess = NULL, + .postprocess = PostprocessAlterCollationOwnerStmt, .address = AlterCollationOwnerObjectAddress, .markDistributed = false, }; @@ -373,7 +373,7 @@ static DistributeObjectOps Function_AlterOwner = { .deparse = DeparseAlterFunctionOwnerStmt, .qualify = QualifyAlterFunctionOwnerStmt, .preprocess = PreprocessAlterFunctionOwnerStmt, - .postprocess = NULL, + .postprocess = PostprocessAlterFunctionOwnerStmt, .address = AlterFunctionOwnerObjectAddress, .markDistributed = false, }; @@ -437,7 +437,7 @@ static DistributeObjectOps Procedure_AlterOwner = { .deparse = DeparseAlterFunctionOwnerStmt, .qualify = QualifyAlterFunctionOwnerStmt, .preprocess = PreprocessAlterFunctionOwnerStmt, - .postprocess = NULL, + .postprocess = PostprocessAlterFunctionOwnerStmt, .address = AlterFunctionOwnerObjectAddress, .markDistributed = false, }; @@ -581,7 +581,7 @@ static DistributeObjectOps Routine_AlterOwner = { .deparse = DeparseAlterFunctionOwnerStmt, .qualify = QualifyAlterFunctionOwnerStmt, .preprocess = PreprocessAlterFunctionOwnerStmt, - .postprocess = NULL, + .postprocess = PostprocessAlterFunctionOwnerStmt, .address = AlterFunctionOwnerObjectAddress, .markDistributed = false, }; @@ -647,7 +647,7 @@ static DistributeObjectOps Statistics_AlterOwner = { .deparse = DeparseAlterStatisticsOwnerStmt, .qualify = QualifyAlterStatisticsOwnerStmt, .preprocess = PreprocessAlterStatisticsOwnerStmt, - .postprocess = NULL, + .postprocess = PostprocessAlterStatisticsOwnerStmt, .address = NULL, .markDistributed = false, }; diff --git a/src/backend/distributed/commands/function.c b/src/backend/distributed/commands/function.c index 2c0dfd6bb..d0a285094 100644 --- a/src/backend/distributed/commands/function.c +++ b/src/backend/distributed/commands/function.c @@ -1584,6 +1584,32 @@ PreprocessAlterFunctionOwnerStmt(Node *node, const char *queryString, } +/* + * PostprocessAlterFunctionOwnerStmt is invoked after the owner has been changed locally. + * Since changing the owner could result in new dependencies being found for this object + * we re-ensure all the dependencies for the function do exist. + * + * This is solely to propagate the new owner (and all its dependencies) if it was not + * already distributed in the cluster. + */ +List * +PostprocessAlterFunctionOwnerStmt(Node *node, const char *queryString) +{ + AlterOwnerStmt *stmt = castNode(AlterOwnerStmt, node); + AssertObjectTypeIsFunctional(stmt->objectType); + + ObjectAddress address = GetObjectAddressFromParseTree((Node *) stmt, false); + if (!ShouldPropagateAlterFunction(&address)) + { + return NIL; + } + + EnsureDependenciesExistOnAllNodes(&address); + + return NIL; +} + + /* * PreprocessDropFunctionStmt gets called during the planning phase of a DROP FUNCTION statement * and returns a list of DDLJob's that will drop any distributed functions from the diff --git a/src/backend/distributed/commands/statistics.c b/src/backend/distributed/commands/statistics.c index 1265887ff..79a758c10 100644 --- a/src/backend/distributed/commands/statistics.c +++ b/src/backend/distributed/commands/statistics.c @@ -427,6 +427,37 @@ PreprocessAlterStatisticsOwnerStmt(Node *node, const char *queryString, } +/* + * PostprocessAlterStatisticsOwnerStmt is invoked after the owner has been changed locally. + * Since changing the owner could result in new dependencies being found for this object + * we re-ensure all the dependencies for the statistics do exist. + * + * This is solely to propagate the new owner (and all its dependencies) if it was not + * already distributed in the cluster. + */ +List * +PostprocessAlterStatisticsOwnerStmt(Node *node, const char *queryString) +{ + AlterOwnerStmt *stmt = castNode(AlterOwnerStmt, node); + Assert(stmt->objectType == OBJECT_STATISTIC_EXT); + + Oid statsOid = get_statistics_object_oid((List *) stmt->object, false); + Oid relationId = GetRelIdByStatsOid(statsOid); + + if (!IsCitusTable(relationId) || !ShouldPropagate()) + { + return NIL; + } + + ObjectAddress statisticsAddress = { 0 }; + ObjectAddressSet(statisticsAddress, StatisticExtRelationId, statsOid); + + EnsureDependenciesExistOnAllNodes(&statisticsAddress); + + return NIL; +} + + /* * GetExplicitStatisticsCommandList returns the list of DDL commands to create * or alter statistics that are explicitly created for the table with relationId. diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 660220324..6d5b13d98 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -146,6 +146,7 @@ extern List * PreprocessDropCollationStmt(Node *stmt, const char *queryString, extern List * PreprocessAlterCollationOwnerStmt(Node *stmt, const char *queryString, ProcessUtilityContext processUtilityContext); +extern List * PostprocessAlterCollationOwnerStmt(Node *node, const char *queryString); extern List * PreprocessAlterCollationSchemaStmt(Node *stmt, const char *queryString, ProcessUtilityContext processUtilityContext); @@ -281,6 +282,7 @@ extern ObjectAddress RenameFunctionStmtObjectAddress(Node *stmt, bool missing_ok); extern List * PreprocessAlterFunctionOwnerStmt(Node *stmt, const char *queryString, ProcessUtilityContext processUtilityContext); +extern List * PostprocessAlterFunctionOwnerStmt(Node *stmt, const char *queryString); extern ObjectAddress AlterFunctionOwnerObjectAddress(Node *stmt, bool missing_ok); extern List * PreprocessAlterFunctionSchemaStmt(Node *stmt, const char *queryString, @@ -432,6 +434,7 @@ extern List * PreprocessAlterStatisticsStmt(Node *node, const char *queryString, extern List * PreprocessAlterStatisticsOwnerStmt(Node *node, const char *queryString, ProcessUtilityContext processUtilityContext); +extern List * PostprocessAlterStatisticsOwnerStmt(Node *node, const char *queryString); extern List * GetExplicitStatisticsCommandList(Oid relationId); extern List * GetExplicitStatisticsSchemaIdList(Oid relationId); extern List * GetAlterIndexStatisticsCommands(Oid indexOid);