diff --git a/src/backend/distributed/commands/database.c b/src/backend/distributed/commands/database.c index 4900e0413..dcd627919 100644 --- a/src/backend/distributed/commands/database.c +++ b/src/backend/distributed/commands/database.c @@ -191,13 +191,25 @@ PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString, } +/* + * Checks if the provided ALTER DATABASE statement is a SET TABLESPACE statement. + * + * This function takes a Node pointer representing a AlterDatabaseStmt, and checks + * if it is a SET TABLESPACE statement, which is used to move a table to a new + * tablespace. + * + * Parameters: + * stmt: A pointer to a Node representing AlterDatabaseStmt. + * + * Returns: + * true if the statement is a SET TABLESPACE statement, false otherwise. + */ static bool isSetTablespaceStatement(AlterDatabaseStmt *stmt) { - ListCell *lc = NULL; - foreach(lc, stmt->options) + DefElem *def = NULL; + foreach_ptr(def, stmt->options) { - DefElem *def = (DefElem *) lfirst(lc); if (strcmp(def->defname, "tablespace") == 0) { return true; @@ -290,8 +302,7 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString, * all workers. */ List * -PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString, - ProcessUtilityContext processUtilityContext) +PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString) { if (!ShouldPropagate()) { diff --git a/src/backend/distributed/commands/distribute_object_ops.c b/src/backend/distributed/commands/distribute_object_ops.c index 4143c740b..a6485d074 100644 --- a/src/backend/distributed/commands/distribute_object_ops.c +++ b/src/backend/distributed/commands/distribute_object_ops.c @@ -524,8 +524,8 @@ static DistributeObjectOps Database_Set = { static DistributeObjectOps Database_Rename = { .deparse = DeparseAlterDatabaseRenameStmt, .qualify = NULL, - .preprocess = PreprocessAlterDatabaseRenameStmt, - .postprocess = NULL, + .preprocess = NULL, + .postprocess = PostprocessAlterDatabaseRenameStmt, .objectType = OBJECT_DATABASE, .operationType = DIST_OPS_ALTER, .address = NULL, diff --git a/src/backend/distributed/deparser/deparse_database_stmts.c b/src/backend/distributed/deparser/deparse_database_stmts.c index 04a0779ef..0f2df1010 100644 --- a/src/backend/distributed/deparser/deparse_database_stmts.c +++ b/src/backend/distributed/deparser/deparse_database_stmts.c @@ -55,7 +55,7 @@ const DefElemOptionFormat create_database_option_formats[] = { }; -const DefElemOptionFormat alter_database_option_formats[] = { +const DefElemOptionFormat alterDatabaseOptionFormats[] = { { "is_template", " IS_TEMPLATE %s", OPTION_FORMAT_BOOLEAN }, { "allow_connections", " ALLOW_CONNECTIONS %s", OPTION_FORMAT_BOOLEAN }, { "connection_limit", " CONNECTION LIMIT %d", OPTION_FORMAT_INTEGER }, @@ -147,16 +147,16 @@ AppendGrantOnDatabaseStmt(StringInfo buf, GrantStmt *stmt) static bool AppendBasicAlterDatabaseOptions(StringInfo buf, DefElem *def, bool - prefix_appended_for_basic_options, char *dbname) + prefixAppendedForBasicOptions, char *dbname) { - if (!prefix_appended_for_basic_options) + if (!prefixAppendedForBasicOptions) { appendStringInfo(buf, "ALTER DATABASE %s WITH", quote_identifier(dbname)); - prefix_appended_for_basic_options = true; + prefixAppendedForBasicOptions = true; } - DefElemOptionToStatement(buf, def, alter_database_option_formats, lengthof( - alter_database_option_formats)); - return prefix_appended_for_basic_options; + DefElemOptionToStatement(buf, def, alterDatabaseOptionFormats, lengthof( + alterDatabaseOptionFormats)); + return prefixAppendedForBasicOptions; } @@ -175,7 +175,7 @@ AppendAlterDatabaseStmt(StringInfo buf, AlterDatabaseStmt *stmt) if (stmt->options) { ListCell *cell = NULL; - bool prefix_appended_for_basic_options = false; + bool prefixAppendedForBasicOptions = false; foreach(cell, stmt->options) { DefElem *def = castNode(DefElem, lfirst(cell)); @@ -186,11 +186,11 @@ AppendAlterDatabaseStmt(StringInfo buf, AlterDatabaseStmt *stmt) } else { - prefix_appended_for_basic_options = AppendBasicAlterDatabaseOptions(buf, - def, - prefix_appended_for_basic_options, - stmt-> - dbname); + prefixAppendedForBasicOptions = AppendBasicAlterDatabaseOptions(buf, + def, + prefixAppendedForBasicOptions, + stmt-> + dbname); } } } @@ -247,6 +247,21 @@ DeparseAlterDatabaseRefreshCollStmt(Node *node) #endif +/* + * Deparses an ALTER DATABASE RENAME statement. + * + * This function takes a Node pointer representing an ALTER DATABASE RENAME + * statement, and returns a string that is the SQL representation of that + * statement. + * + * Parameters: + * node: A pointer to a Node representing an ALTER DATABASE RENAME statement. + * + * Returns: + * A string representing the SQL command to rename a database. The string is + * in the format "ALTER DATABASE RENAME TO ", where + * and are the old and new database names, respectively. + */ char * DeparseAlterDatabaseRenameStmt(Node *node) { diff --git a/src/backend/distributed/sql/downgrades/citus--12.2-1--12.1-1.sql b/src/backend/distributed/sql/downgrades/citus--12.2-1--12.1-1.sql index d568cb034..d18f7257b 100644 --- a/src/backend/distributed/sql/downgrades/citus--12.2-1--12.1-1.sql +++ b/src/backend/distributed/sql/downgrades/citus--12.2-1--12.1-1.sql @@ -3,4 +3,3 @@ DROP FUNCTION pg_catalog.citus_internal_database_command(text); #include "../udfs/citus_add_rebalance_strategy/10.1-1.sql" - diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 760c92e87..854d49b01 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -246,9 +246,7 @@ extern List * CreateDatabaseStmtObjectAddress(Node *node, bool missingOk, extern List * GenerateGrantDatabaseCommandList(void); -extern List * PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString, - ProcessUtilityContext - processUtilityContext); +extern List * PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString); extern void EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt); extern char * CreateDatabaseDDLCommand(Oid dbId);