Merge pull request #5067 from citusdata/add_tests_mx

Add regression tests for changing column type with fkey
pull/5072/head^2
Önder Kalacı 2021-06-23 09:33:41 +03:00 committed by GitHub
commit 2939f10fd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 8 deletions

View File

@ -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
---------------------------------------------------------------------

View File

@ -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
---------------------------------------------------------------------

View File

@ -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

View File

@ -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);