diff --git a/src/backend/distributed/executor/multi_utility.c b/src/backend/distributed/executor/multi_utility.c index dd6a79033..cd20413cf 100644 --- a/src/backend/distributed/executor/multi_utility.c +++ b/src/backend/distributed/executor/multi_utility.c @@ -73,6 +73,9 @@ static Node * ProcessDropIndexStmt(DropStmt *dropIndexStatement, const char *dropIndexCommand, bool isTopLevel); static Node * ProcessAlterTableStmt(AlterTableStmt *alterTableStatement, const char *alterTableCommand, bool isTopLevel); +static Node * ProcessAlterObjectSchemaStmt(AlterObjectSchemaStmt *alterObjectSchemaStmt, + const char *alterObjectSchemaCommand, + bool isTopLevel); /* Local functions forward declarations for unsupported command checks */ static void ErrorIfUnsupportedIndexStmt(IndexStmt *createIndexStatement); @@ -198,6 +201,30 @@ multi_ProcessUtility(Node *parsetree, ErrorIfDistributedRenameStmt(renameStmt); } } + + /* + * ALTER ... SET SCHEMA statements have their node type as AlterObjectSchemaStmt. + * So, we intercept AlterObjectSchemaStmt to tackle these commands. + */ + if (IsA(parsetree, AlterObjectSchemaStmt)) + { + AlterObjectSchemaStmt *setSchemaStmt = (AlterObjectSchemaStmt *) parsetree; + parsetree = ProcessAlterObjectSchemaStmt(setSchemaStmt, queryString, + isTopLevel); + } + + /* + * ALTER TABLE ALL IN TABLESPACE statements have their node type as + * AlterTableMoveAllStmt. At the moment we do not support this functionality in + * the distributed environment. We warn out here. + */ + if (IsA(parsetree, AlterTableMoveAllStmt) && CitusHasBeenLoaded()) + { + ereport(WARNING, (errmsg("not propagating ALTER TABLE ALL IN TABLESPACE " + "commands to worker nodes"), + errhint("Connect to worker nodes directly to manually " + "move all tables."))); + } } /* @@ -646,6 +673,46 @@ ProcessAlterTableStmt(AlterTableStmt *alterTableStatement, const char *alterTabl } +/* + * ProcessAlterObjectSchemaStmt processes ALTER ... SET SCHEMA statements for distributed + * objects. The function first checks if the statement belongs to a distributed objects + * or not. If it does, then it checks whether given object is a table. If it is, we warn + * out, since we do not support ALTER ... SET SCHEMA + */ +static Node * +ProcessAlterObjectSchemaStmt(AlterObjectSchemaStmt *alterObjectSchemaStmt, + const char *alterObjectSchemaCommand, bool isTopLevel) +{ + + Oid relationId = InvalidOid; + bool noWait = false; + + if (alterObjectSchemaStmt->relation == NULL) + { + return (Node *) alterObjectSchemaStmt; + } + + relationId = RangeVarGetRelidExtended(alterObjectSchemaStmt->relation, + AccessExclusiveLock, + alterObjectSchemaStmt->missing_ok, + noWait, NULL, NULL); + + /* first check whether a distributed relation is affected */ + if (!OidIsValid(relationId) || !IsDistributedTable(relationId)) + { + return (Node *) alterObjectSchemaStmt; + } + + /* warn out if a distributed relation is affected */ + ereport(WARNING, (errmsg("not propagating ALTER ... SET SCHEMA commands to " + "worker nodes"), + errhint("Connect to worker nodes directly to manually " + "change schemas of affected objects."))); + + return (Node *) alterObjectSchemaStmt; +} + + /* * ErrorIfUnsupportedIndexStmt checks if the corresponding index statement is * supported for distributed tables and errors out if it is not. diff --git a/src/test/regress/expected/multi_schema_support.out b/src/test/regress/expected/multi_schema_support.out index fe97e8414..7255deecb 100644 --- a/src/test/regress/expected/multi_schema_support.out +++ b/src/test/regress/expected/multi_schema_support.out @@ -1045,3 +1045,9 @@ WHERE -- set task_executor back to real-time SET citus.task_executor_type TO "real-time"; +-- test ALTER TABLE SET SCHEMA +-- we expect that it will warn out +SET search_path TO public; +ALTER TABLE test_schema_support.nation_hash SET SCHEMA public; +WARNING: not propagating ALTER ... SET SCHEMA commands to worker nodes +HINT: Connect to worker nodes directly to manually change schemas of affected objects. diff --git a/src/test/regress/input/multi_alter_table_statements.source b/src/test/regress/input/multi_alter_table_statements.source index 4584c31fd..c76187425 100644 --- a/src/test/regress/input/multi_alter_table_statements.source +++ b/src/test/regress/input/multi_alter_table_statements.source @@ -249,6 +249,13 @@ SELECT indexname, tablename FROM pg_indexes WHERE tablename = 'lineitem_alter'; SELECT indexname, tablename FROM pg_indexes WHERE tablename like 'lineitem_alter_%'; \c - - - :master_port +-- test ALTER TABLE ALL IN TABLESPACE +-- we expect that it will warn out +CREATE TABLESPACE super_fast_ssd LOCATION '@abs_srcdir@/data'; +ALTER TABLE ALL IN TABLESPACE pg_default SET TABLESPACE super_fast_ssd; +ALTER TABLE ALL IN TABLESPACE super_fast_ssd SET TABLESPACE pg_default; +DROP TABLESPACE super_fast_ssd; + -- Cleanup the table and its shards SET citus.enable_ddl_propagation to true; SELECT master_apply_delete_command('DELETE FROM lineitem_alter'); diff --git a/src/test/regress/output/multi_alter_table_statements.source b/src/test/regress/output/multi_alter_table_statements.source index 5af6ff985..238231e12 100644 --- a/src/test/regress/output/multi_alter_table_statements.source +++ b/src/test/regress/output/multi_alter_table_statements.source @@ -639,6 +639,16 @@ SELECT indexname, tablename FROM pg_indexes WHERE tablename like 'lineitem_alte (0 rows) \c - - - :master_port +-- test ALTER TABLE ALL IN TABLESPACE +-- we expect that it will warn out +CREATE TABLESPACE super_fast_ssd LOCATION '@abs_srcdir@/data'; +ALTER TABLE ALL IN TABLESPACE pg_default SET TABLESPACE super_fast_ssd; +WARNING: not propagating ALTER TABLE ALL IN TABLESPACE commands to worker nodes +HINT: Connect to worker nodes directly to manually move all tables. +ALTER TABLE ALL IN TABLESPACE super_fast_ssd SET TABLESPACE pg_default; +WARNING: not propagating ALTER TABLE ALL IN TABLESPACE commands to worker nodes +HINT: Connect to worker nodes directly to manually move all tables. +DROP TABLESPACE super_fast_ssd; -- Cleanup the table and its shards SET citus.enable_ddl_propagation to true; SELECT master_apply_delete_command('DELETE FROM lineitem_alter'); diff --git a/src/test/regress/sql/multi_schema_support.sql b/src/test/regress/sql/multi_schema_support.sql index 28a59d4fa..2e827dd19 100644 --- a/src/test/regress/sql/multi_schema_support.sql +++ b/src/test/regress/sql/multi_schema_support.sql @@ -728,3 +728,9 @@ WHERE -- set task_executor back to real-time SET citus.task_executor_type TO "real-time"; + + +-- test ALTER TABLE SET SCHEMA +-- we expect that it will warn out +SET search_path TO public; +ALTER TABLE test_schema_support.nation_hash SET SCHEMA public;