From 75847d10b5741fa692c4df2541ee835a7796d904 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Tue, 22 Jun 2021 14:45:59 +0300 Subject: [PATCH] Add regression tests for changing column type with fkey closes https://github.com/citusdata/citus/issues/2337 as it doesn't apply anymore. --- .../expected/multi_mx_add_coordinator.out | 51 +++++++++++++++++++ .../mx_coordinator_shouldhaveshards.out | 8 +-- .../regress/sql/multi_mx_add_coordinator.sql | 49 ++++++++++++++++++ .../sql/mx_coordinator_shouldhaveshards.sql | 2 +- 4 files changed, 102 insertions(+), 8 deletions(-) diff --git a/src/test/regress/expected/multi_mx_add_coordinator.out b/src/test/regress/expected/multi_mx_add_coordinator.out index de3f67f9f..e9a5fcb2b 100644 --- a/src/test/regress/expected/multi_mx_add_coordinator.out +++ b/src/test/regress/expected/multi_mx_add_coordinator.out @@ -244,6 +244,57 @@ SELECT count(*) FROM run_command_on_workers('SELECT recover_prepared_transaction 2 (1 row) +-- make sure that we can change a column type +-- that appears in foreign key to reference table +SET citus.shard_replication_factor TO 1; +CREATE TABLE local_fkey_table(id int PRIMARY KEY); +CREATE TABLE referece_table(id int PRIMARY KEY); +SELECT create_reference_table('referece_table'); + create_reference_table +--------------------------------------------------------------------- + +(1 row) + +CREATE TABLE distributed_table(id int PRIMARY KEY, value_1 int); +SELECT create_distributed_table('distributed_table', 'id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +INSERT INTO local_fkey_table SELECT i FROM generate_Series(0,100)i; +INSERT INTO referece_table SELECT i FROM generate_Series(0,100)i; +INSERT INTO distributed_table SELECT i, i FROM generate_Series(0,100)i; +ALTER TABLE + distributed_table +ADD CONSTRAINT + fkey_delete FOREIGN KEY(value_1) +REFERENCES + referece_table(id) ON DELETE CASCADE; +ALTER TABLE + referece_table +ADD CONSTRAINT + fkey_delete_2 FOREIGN KEY(id) +REFERENCES + local_fkey_table(id); +ALTER TABLE + local_fkey_table +ADD CONSTRAINT + fkey_delete_3 FOREIGN KEY(id) +REFERENCES + referece_table(id); +-- now we've a distributed table which has a foreign key to a reference table +-- note that this only happens in MX +alter table distributed_table ALTER COLUMN value_1 TYPE bigint; +alter table distributed_table ALTER COLUMN value_1 TYPE int; +alter table referece_table ALTER COLUMN id TYPE bigint; +alter table referece_table ALTER COLUMN id TYPE int; +alter table local_fkey_table ALTER COLUMN id TYPE int; +SET citus.force_max_query_parallelization TO ON; +alter table distributed_table ALTER COLUMN value_1 TYPE bigint; +alter table distributed_table ALTER COLUMN value_1 TYPE int; +SET client_min_messages TO error; +DROP TABLE distributed_table, referece_table, local_fkey_table; SELECT master_remove_node('localhost', :master_port); master_remove_node --------------------------------------------------------------------- diff --git a/src/test/regress/expected/mx_coordinator_shouldhaveshards.out b/src/test/regress/expected/mx_coordinator_shouldhaveshards.out index 2582400d6..ddacdbd80 100644 --- a/src/test/regress/expected/mx_coordinator_shouldhaveshards.out +++ b/src/test/regress/expected/mx_coordinator_shouldhaveshards.out @@ -168,14 +168,8 @@ SELECT 1 FROM master_set_node_property('localhost', :master_port, 'shouldhavesha 1 (1 row) +SET client_min_messages TO ERROR; DROP SCHEMA mx_coordinator_shouldhaveshards CASCADE; -NOTICE: drop cascades to 6 other objects -DETAIL: drop cascades to table mx_coordinator_shouldhaveshards.table_1 -drop cascades to table mx_coordinator_shouldhaveshards.table_1_1130052 -drop cascades to table mx_coordinator_shouldhaveshards.table_1_1130055 -drop cascades to table mx_coordinator_shouldhaveshards.table_2 -drop cascades to table mx_coordinator_shouldhaveshards.table_2_1130056 -drop cascades to table mx_coordinator_shouldhaveshards.table_2_1130059 SELECT master_remove_node('localhost', :master_port); master_remove_node --------------------------------------------------------------------- diff --git a/src/test/regress/sql/multi_mx_add_coordinator.sql b/src/test/regress/sql/multi_mx_add_coordinator.sql index 0628aa94b..ef691014f 100644 --- a/src/test/regress/sql/multi_mx_add_coordinator.sql +++ b/src/test/regress/sql/multi_mx_add_coordinator.sql @@ -105,6 +105,55 @@ SELECT * FROM ref ORDER BY a; SELECT recover_prepared_transactions(); SELECT count(*) FROM run_command_on_workers('SELECT recover_prepared_transactions()'); +-- make sure that we can change a column type +-- that appears in foreign key to reference table +SET citus.shard_replication_factor TO 1; +CREATE TABLE local_fkey_table(id int PRIMARY KEY); +CREATE TABLE referece_table(id int PRIMARY KEY); +SELECT create_reference_table('referece_table'); + +CREATE TABLE distributed_table(id int PRIMARY KEY, value_1 int); +SELECT create_distributed_table('distributed_table', 'id'); + +INSERT INTO local_fkey_table SELECT i FROM generate_Series(0,100)i; +INSERT INTO referece_table SELECT i FROM generate_Series(0,100)i; +INSERT INTO distributed_table SELECT i, i FROM generate_Series(0,100)i; + +ALTER TABLE + distributed_table +ADD CONSTRAINT + fkey_delete FOREIGN KEY(value_1) +REFERENCES + referece_table(id) ON DELETE CASCADE; + +ALTER TABLE + referece_table +ADD CONSTRAINT + fkey_delete_2 FOREIGN KEY(id) +REFERENCES + local_fkey_table(id); + +ALTER TABLE + local_fkey_table +ADD CONSTRAINT + fkey_delete_3 FOREIGN KEY(id) +REFERENCES + referece_table(id); + +-- now we've a distributed table which has a foreign key to a reference table +-- note that this only happens in MX +alter table distributed_table ALTER COLUMN value_1 TYPE bigint; +alter table distributed_table ALTER COLUMN value_1 TYPE int; +alter table referece_table ALTER COLUMN id TYPE bigint; +alter table referece_table ALTER COLUMN id TYPE int; +alter table local_fkey_table ALTER COLUMN id TYPE int; + +SET citus.force_max_query_parallelization TO ON; +alter table distributed_table ALTER COLUMN value_1 TYPE bigint; +alter table distributed_table ALTER COLUMN value_1 TYPE int; +SET client_min_messages TO error; + +DROP TABLE distributed_table, referece_table, local_fkey_table; SELECT master_remove_node('localhost', :master_port); -- test that coordinator pg_dist_node entry was removed from the workers diff --git a/src/test/regress/sql/mx_coordinator_shouldhaveshards.sql b/src/test/regress/sql/mx_coordinator_shouldhaveshards.sql index 9c0fb6035..44d1ed48c 100644 --- a/src/test/regress/sql/mx_coordinator_shouldhaveshards.sql +++ b/src/test/regress/sql/mx_coordinator_shouldhaveshards.sql @@ -87,7 +87,7 @@ inserts AS ( \c - - - :master_port SELECT 1 FROM master_set_node_property('localhost', :master_port, 'shouldhaveshards', false); - +SET client_min_messages TO ERROR; DROP SCHEMA mx_coordinator_shouldhaveshards CASCADE; SELECT master_remove_node('localhost', :master_port);