mirror of https://github.com/citusdata/citus.git
Merge pull request #662 from citusdata/fix/fix_ALTER_TABLE_SET_SCHEMA
Fix ALTER TABLE SET SCHEMApull/665/head
commit
291aafd11d
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue