Revert&Adjust fkey tests

talha_tes1
Ahmet Gedemenli 2021-10-20 18:12:55 +03:00
parent 5611915300
commit e5fe479eb5
3 changed files with 106 additions and 3 deletions

View File

@ -273,8 +273,7 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve
Oid shellRelationId = get_relname_relid(relationName, relationSchemaId);
/* mark the shell relation with autoConverted=false, as it was a user request */
UpdatePartitionAutoConverted(shellRelationId, false);
UpdatePartitionAutoConverted(shellRelationId, autoConverted);
/*
* We converted every foreign key connected table in our subgraph

View File

@ -103,6 +103,25 @@ BEGIN;
ALTER TABLE reference_table_1 ADD CONSTRAINT fkey_9 FOREIGN KEY (col_1) REFERENCES local_table_1(col_1);
ROLLBACK;
ALTER TABLE partitioned_table_1 DROP CONSTRAINT fkey_8;
BEGIN;
-- now that we detached partitioned table from graph, succeeds
ALTER TABLE reference_table_1 ADD CONSTRAINT fkey_10 FOREIGN KEY (col_1) REFERENCES local_table_1(col_1);
-- show that we converted all 4 local tables in this schema to citus local tables
SELECT COUNT(*)=4 FROM citus_local_tables_in_schema;
?column?
---------------------------------------------------------------------
t
(1 row)
-- dropping that column would undistribute those 4 citus local tables
ALTER TABLE local_table_1 DROP COLUMN col_1 CASCADE;
SELECT COUNT(*)=0 FROM citus_local_tables_in_schema;
?column?
---------------------------------------------------------------------
t
(1 row)
ROLLBACK;
-- this actually attempts to convert local tables to citus local tables but errors out
-- as citus doesn't support defining foreign keys via add column commands
ALTER TABLE local_table_1 ADD COLUMN col_3 INT REFERENCES reference_table_1(col_1);
@ -309,7 +328,51 @@ BEGIN;
-- show that we validate foreign key constraints, errors out
INSERT INTO local_table_5 VALUES (300);
ERROR: insert or update on table "local_table_5_1518069" violates foreign key constraint "local_table_5_col_1_fkey1_1518069"
ERROR: insert or update on table "local_table_5_1518073" violates foreign key constraint "local_table_5_col_1_fkey1_1518073"
ROLLBACK;
BEGIN;
CREATE SCHEMA another_schema_fkeys_between_local_ref;
CREATE TABLE another_schema_fkeys_between_local_ref.local_table_6 (col_1 INT PRIMARY KEY);
-- first convert local tables to citus local tables in graph
ALTER TABLE local_table_2 ADD CONSTRAINT fkey_11 FOREIGN KEY (col_1) REFERENCES reference_table_1(col_1) ON DELETE CASCADE;
CREATE TABLE local_table_5 (
col_1 INT UNIQUE REFERENCES another_schema_fkeys_between_local_ref.local_table_6(col_1) CHECK (col_1 > 0),
col_2 INT REFERENCES local_table_3(col_1),
FOREIGN KEY (col_1) REFERENCES local_table_5(col_1));
-- Now show that we converted local_table_5 & 6 to citus local tables
-- as local_table_5 has foreign key to a citus local table too
SELECT logicalrelid::text AS tablename, partmethod, repmodel FROM pg_dist_partition
WHERE logicalrelid::text IN (SELECT tablename FROM pg_tables WHERE schemaname='fkeys_between_local_ref' UNION
SELECT 'another_schema_fkeys_between_local_ref.local_table_6')
ORDER BY tablename;
tablename | partmethod | repmodel
---------------------------------------------------------------------
another_schema_fkeys_between_local_ref.local_table_6 | n | s
distributed_table | h | s
local_table_1 | n | s
local_table_2 | n | s
local_table_3 | n | s
local_table_4 | n | s
local_table_5 | n | s
reference_table_1 | n | t
(8 rows)
DROP TABLE local_table_3 CASCADE;
DROP SCHEMA another_schema_fkeys_between_local_ref CASCADE;
-- now we shouldn't see local_table_5 since now it is not connected to any reference tables/citus local tables
-- and it's converted automatically
SELECT logicalrelid::text AS tablename, partmethod, repmodel, autoconverted FROM pg_dist_partition
WHERE logicalrelid::text IN (SELECT tablename FROM pg_tables WHERE schemaname='fkeys_between_local_ref')
ORDER BY tablename;
tablename | partmethod | repmodel | autoconverted
---------------------------------------------------------------------
distributed_table | h | s | f
local_table_1 | n | s | t
local_table_2 | n | s | t
local_table_4 | n | s | t
reference_table_1 | n | t | f
(5 rows)
ROLLBACK;
BEGIN;
CREATE TABLE local_table_6 (col_1 INT PRIMARY KEY);

View File

@ -87,6 +87,18 @@ ALTER TABLE reference_table_1 ADD CONSTRAINT fkey_9 FOREIGN KEY (col_1) REFERENC
ROLLBACK;
ALTER TABLE partitioned_table_1 DROP CONSTRAINT fkey_8;
BEGIN;
-- now that we detached partitioned table from graph, succeeds
ALTER TABLE reference_table_1 ADD CONSTRAINT fkey_10 FOREIGN KEY (col_1) REFERENCES local_table_1(col_1);
-- show that we converted all 4 local tables in this schema to citus local tables
SELECT COUNT(*)=4 FROM citus_local_tables_in_schema;
-- dropping that column would undistribute those 4 citus local tables
ALTER TABLE local_table_1 DROP COLUMN col_1 CASCADE;
SELECT COUNT(*)=0 FROM citus_local_tables_in_schema;
ROLLBACK;
-- this actually attempts to convert local tables to citus local tables but errors out
-- as citus doesn't support defining foreign keys via add column commands
ALTER TABLE local_table_1 ADD COLUMN col_3 INT REFERENCES reference_table_1(col_1);
@ -233,6 +245,35 @@ BEGIN;
INSERT INTO local_table_5 VALUES (300);
ROLLBACK;
BEGIN;
CREATE SCHEMA another_schema_fkeys_between_local_ref;
CREATE TABLE another_schema_fkeys_between_local_ref.local_table_6 (col_1 INT PRIMARY KEY);
-- first convert local tables to citus local tables in graph
ALTER TABLE local_table_2 ADD CONSTRAINT fkey_11 FOREIGN KEY (col_1) REFERENCES reference_table_1(col_1) ON DELETE CASCADE;
CREATE TABLE local_table_5 (
col_1 INT UNIQUE REFERENCES another_schema_fkeys_between_local_ref.local_table_6(col_1) CHECK (col_1 > 0),
col_2 INT REFERENCES local_table_3(col_1),
FOREIGN KEY (col_1) REFERENCES local_table_5(col_1));
-- Now show that we converted local_table_5 & 6 to citus local tables
-- as local_table_5 has foreign key to a citus local table too
SELECT logicalrelid::text AS tablename, partmethod, repmodel FROM pg_dist_partition
WHERE logicalrelid::text IN (SELECT tablename FROM pg_tables WHERE schemaname='fkeys_between_local_ref' UNION
SELECT 'another_schema_fkeys_between_local_ref.local_table_6')
ORDER BY tablename;
DROP TABLE local_table_3 CASCADE;
DROP SCHEMA another_schema_fkeys_between_local_ref CASCADE;
-- now we shouldn't see local_table_5 since now it is not connected to any reference tables/citus local tables
-- and it's converted automatically
SELECT logicalrelid::text AS tablename, partmethod, repmodel, autoconverted FROM pg_dist_partition
WHERE logicalrelid::text IN (SELECT tablename FROM pg_tables WHERE schemaname='fkeys_between_local_ref')
ORDER BY tablename;
ROLLBACK;
BEGIN;
CREATE TABLE local_table_6 (col_1 INT PRIMARY KEY);
-- first convert local tables to citus local tables in graph