Skip to content

Commit

Permalink
Adds alter database rename stmt propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
gurkanindibay committed Oct 11, 2023
1 parent fd521f2 commit 6a333ca
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/backend/distributed/commands/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ PreprocessAlterDatabaseStmt(Node *node, const char *queryString,

if (strstr(sql, "SET TABLESPACE") != NULL)
{
if (IsCoordinatorNode())
if (IsCoordinator())
{
ereport(NOTICE, (errmsg(
"Citus partially supports ALTER DATABASE SET TABLESPACE for "
Expand Down Expand Up @@ -240,9 +240,31 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString,
return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}


#endif


List *
PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext)
{
if (!ShouldPropagate())
{
return NIL;
}

RenameStmt *stmt = castNode(RenameStmt, node);

EnsureCoordinator();

char *sql = DeparseTreeNode((Node *) stmt);

List *commands = list_make3(DISABLE_DDL_PROPAGATION,
(void *) sql,
ENABLE_DDL_PROPAGATION);

return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
}

/*
* CreateDDLTaskList creates a task list for running a single DDL command.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/backend/distributed/commands/distribute_object_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,16 @@ static DistributeObjectOps Database_Set = {
.markDistributed = false,
};

static DistributeObjectOps Database_Rename = {
.deparse = DeparseAlterDatabaseRenameStmt,
.qualify = NULL,
.preprocess = PreprocessAlterDatabaseRenameStmt,
.postprocess = NULL,
.objectType = OBJECT_DATABASE,
.operationType = DIST_OPS_ALTER,
.address = NULL,
.markDistributed = false,
};

static DistributeObjectOps Domain_Alter = {
.deparse = DeparseAlterDomainStmt,
Expand Down Expand Up @@ -2072,6 +2082,11 @@ GetDistributeObjectOps(Node *node)
return &Collation_Rename;
}

case OBJECT_DATABASE:
{
return &Database_Rename;
}

case OBJECT_DOMAIN:
{
return &Domain_Rename;
Expand Down
16 changes: 15 additions & 1 deletion src/backend/distributed/deparser/deparse_database_stmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,23 @@ DeparseAlterDatabaseRefreshCollStmt(Node *node)
return str.data;
}


#endif

char *
DeparseAlterDatabaseRenameStmt(Node *node)
{
RenameStmt *stmt = (RenameStmt *) node;

StringInfoData str;
initStringInfo(&str);

appendStringInfo(&str, "ALTER DATABASE %s RENAME TO %s",
quote_identifier(stmt->subname),
quote_identifier(stmt->newname));

return str.data;
}

static void
AppendAlterDatabaseSetStmt(StringInfo buf, AlterDatabaseSetStmt *stmt)
{
Expand Down
3 changes: 3 additions & 0 deletions src/include/distributed/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ extern List * PostprocessCreateDatabaseStmt(Node *node, const char *queryString)
extern List * PreprocessDropDatabaseStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext);

extern List * PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext);

/* domain.c - forward declarations */
extern List * CreateDomainStmtObjectAddress(Node *node, bool missing_ok, bool
isPostprocess);
Expand Down
1 change: 1 addition & 0 deletions src/include/distributed/deparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ extern char * DeparseAlterDatabaseRefreshCollStmt(Node *node);
extern char * DeparseAlterDatabaseSetStmt(Node *node);
extern char * DeparseCreateDatabaseStmt(Node *node);
extern char * DeparseDropDatabaseStmt(Node *node);
extern char * DeparseAlterDatabaseRenameStmt(Node *node);


/* forward declaration for deparse_publication_stmts.c */
Expand Down

0 comments on commit 6a333ca

Please sign in to comment.