Propagate more ALTER FOREIGN TABLE to workers

pull/2726/head
Philip Dubé 2019-05-23 17:25:00 -07:00
parent dff1a8db08
commit b8871d9ff4
7 changed files with 70 additions and 13 deletions

View File

@ -66,6 +66,7 @@ PlanRenameStmt(RenameStmt *renameStmt, const char *renameCommand)
switch (renameStmt->renameType)
{
case OBJECT_TABLE:
case OBJECT_FOREIGN_TABLE:
case OBJECT_COLUMN:
case OBJECT_TABCONSTRAINT:
case OBJECT_POLICY:

View File

@ -524,12 +524,14 @@ IsAlterTableRenameStmt(RenameStmt *renameStmt)
{
bool isAlterTableRenameStmt = false;
if (renameStmt->renameType == OBJECT_TABLE)
if (renameStmt->renameType == OBJECT_TABLE ||
renameStmt->renameType == OBJECT_FOREIGN_TABLE)
{
isAlterTableRenameStmt = true;
}
else if (renameStmt->renameType == OBJECT_COLUMN &&
renameStmt->relationType == OBJECT_TABLE)
(renameStmt->relationType == OBJECT_TABLE ||
renameStmt->relationType == OBJECT_FOREIGN_TABLE))
{
isAlterTableRenameStmt = true;
}

View File

@ -291,6 +291,7 @@ multi_ProcessUtility(PlannedStmt *pstmt,
{
AlterTableStmt *alterTableStmt = (AlterTableStmt *) parsetree;
if (alterTableStmt->relkind == OBJECT_TABLE ||
alterTableStmt->relkind == OBJECT_FOREIGN_TABLE ||
alterTableStmt->relkind == OBJECT_INDEX)
{
ddlJobs = PlanAlterTableStmt(alterTableStmt, queryString);
@ -366,7 +367,8 @@ multi_ProcessUtility(PlannedStmt *pstmt,
if (IsA(parsetree, AlterTableStmt))
{
AlterTableStmt *alterTableStmt = (AlterTableStmt *) parsetree;
if (alterTableStmt->relkind == OBJECT_TABLE)
if (alterTableStmt->relkind == OBJECT_TABLE ||
alterTableStmt->relkind == OBJECT_FOREIGN_TABLE)
{
ErrorIfAlterDropsPartitionColumn(alterTableStmt);

View File

@ -421,7 +421,8 @@ RelayEventExtendNames(Node *parseTree, char *schemaName, uint64 shardId)
RenameStmt *renameStmt = (RenameStmt *) parseTree;
ObjectType objectType = renameStmt->renameType;
if (objectType == OBJECT_TABLE || objectType == OBJECT_INDEX)
if (objectType == OBJECT_TABLE || objectType == OBJECT_INDEX ||
objectType == OBJECT_FOREIGN_TABLE)
{
char **oldRelationName = &(renameStmt->relation->relname);
char **newRelationName = &(renameStmt->newname);

View File

@ -2,6 +2,6 @@
# Only run few basic tests to set up a testing environment
# ----------
test: multi_cluster_management
test: multi_test_helpers
test: multi_test_helpers multi_create_fdw
test: multi_create_table multi_behavioral_analytics_create_table
test: multi_load_data

View File

@ -145,13 +145,37 @@ CREATE FOREIGN TABLE foreign_table (
id bigint not null,
full_name text not null default ''
) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true');
SELECT master_get_table_ddl_events('foreign_table');
SELECT create_distributed_table('foreign_table', 'id');
NOTICE: foreign-data wrapper "fake_fdw" does not have an extension defined
master_get_table_ddl_events
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
create_distributed_table
--------------------------
(1 row)
ALTER FOREIGN TABLE foreign_table rename to renamed_foreign_table;
ALTER FOREIGN TABLE renamed_foreign_table rename full_name to rename_name;
ALTER FOREIGN TABLE renamed_foreign_table alter rename_name type char(8);
\c - - - :worker_1_port
select table_name, column_name, data_type
from information_schema.columns
where table_schema='public' and table_name like 'renamed_foreign_table_%' and column_name <> 'id'
order by table_name;
table_name | column_name | data_type
------------------------------+-------------+-----------
renamed_foreign_table_610000 | rename_name | character
renamed_foreign_table_610001 | rename_name | character
renamed_foreign_table_610002 | rename_name | character
renamed_foreign_table_610003 | rename_name | character
(4 rows)
\c - - - :master_port
SELECT master_get_table_ddl_events('renamed_foreign_table');
NOTICE: foreign-data wrapper "fake_fdw" does not have an extension defined
master_get_table_ddl_events
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE SERVER fake_fdw_server FOREIGN DATA WRAPPER fake_fdw
CREATE FOREIGN TABLE public.foreign_table (id bigint NOT NULL, full_name text DEFAULT ''::text NOT NULL) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true')
ALTER TABLE public.foreign_table OWNER TO postgres
CREATE FOREIGN TABLE public.renamed_foreign_table (id bigint NOT NULL, rename_name character(8) DEFAULT ''::text NOT NULL) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true')
ALTER TABLE public.renamed_foreign_table OWNER TO postgres
(3 rows)
-- propagating views is not supported
@ -160,7 +184,17 @@ SELECT master_get_table_ddl_events('local_view');
ERROR: local_view is not a regular, foreign or partitioned table
-- clean up
DROP VIEW IF EXISTS local_view;
DROP FOREIGN TABLE IF EXISTS foreign_table;
DROP FOREIGN TABLE IF EXISTS renamed_foreign_table;
\c - - - :worker_1_port
select table_name, column_name, data_type
from information_schema.columns
where table_schema='public' and table_name like 'renamed_foreign_table_%' and column_name <> 'id'
order by table_name;
table_name | column_name | data_type
------------+-------------+-----------
(0 rows)
\c - - - :master_port
DROP TABLE IF EXISTS simple_table, not_null_table, column_constraint_table,
table_constraint_table, default_value_table, pkey_table,
unique_table, clustered_table, fiddly_table;

View File

@ -106,7 +106,18 @@ CREATE FOREIGN TABLE foreign_table (
full_name text not null default ''
) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true');
SELECT master_get_table_ddl_events('foreign_table');
SELECT create_distributed_table('foreign_table', 'id');
ALTER FOREIGN TABLE foreign_table rename to renamed_foreign_table;
ALTER FOREIGN TABLE renamed_foreign_table rename full_name to rename_name;
ALTER FOREIGN TABLE renamed_foreign_table alter rename_name type char(8);
\c - - - :worker_1_port
select table_name, column_name, data_type
from information_schema.columns
where table_schema='public' and table_name like 'renamed_foreign_table_%' and column_name <> 'id'
order by table_name;
\c - - - :master_port
SELECT master_get_table_ddl_events('renamed_foreign_table');
-- propagating views is not supported
CREATE VIEW local_view AS SELECT * FROM simple_table;
@ -115,7 +126,13 @@ SELECT master_get_table_ddl_events('local_view');
-- clean up
DROP VIEW IF EXISTS local_view;
DROP FOREIGN TABLE IF EXISTS foreign_table;
DROP FOREIGN TABLE IF EXISTS renamed_foreign_table;
\c - - - :worker_1_port
select table_name, column_name, data_type
from information_schema.columns
where table_schema='public' and table_name like 'renamed_foreign_table_%' and column_name <> 'id'
order by table_name;
\c - - - :master_port
DROP TABLE IF EXISTS simple_table, not_null_table, column_constraint_table,
table_constraint_table, default_value_table, pkey_table,
unique_table, clustered_table, fiddly_table;