mirror of https://github.com/citusdata/citus.git
Add tests for allowing SET NULL/DEFAULT for subseet of columns (#6319)
PG 15 added support for that (d6f96ed94e73052f99a2e545ed17a8b2fdc1fb8a). We also add support, but we already do not support ON DELETE SET NULL/DEFAULT for distribution column. So, in essence, we add support for reference tables and Citus local tables. Semi-related: We should really consider fixing: https://github.com/citusdata/citus/issues/6318pull/6317/head
commit
c6f108e626
|
@ -56,9 +56,9 @@ SELECT result FROM run_command_on_all_nodes('
|
||||||
');
|
');
|
||||||
result
|
result
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
de-u-co-phonebk
|
de-u-co-phonebk
|
||||||
de-u-co-phonebk
|
de-u-co-phonebk
|
||||||
de-u-co-phonebk
|
de-u-co-phonebk
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
-- with non-icu provider, colliculocale will be null, collcollate and collctype will be set
|
-- with non-icu provider, colliculocale will be null, collcollate and collctype will be set
|
||||||
|
@ -552,7 +552,66 @@ SELECT count(*)=100 FROM copy_test2;
|
||||||
t
|
t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- allow foreign key columns to have SET NULL/DEFAULT on column basis
|
||||||
|
-- currently only reference tables can support that
|
||||||
|
CREATE TABLE PKTABLE (tid int, id int, PRIMARY KEY (tid, id));
|
||||||
|
CREATE TABLE FKTABLE (
|
||||||
|
tid int, id int,
|
||||||
|
fk_id_del_set_null int,
|
||||||
|
fk_id_del_set_default int DEFAULT 0,
|
||||||
|
FOREIGN KEY (tid, fk_id_del_set_null) REFERENCES PKTABLE ON DELETE SET NULL (fk_id_del_set_null),
|
||||||
|
FOREIGN KEY (tid, fk_id_del_set_default) REFERENCES PKTABLE ON DELETE SET DEFAULT (fk_id_del_set_default)
|
||||||
|
);
|
||||||
|
SELECT create_reference_table('PKTABLE');
|
||||||
|
create_reference_table
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
-- ok, Citus could relax this constraint in the future
|
||||||
|
SELECT create_distributed_table('FKTABLE', 'tid');
|
||||||
|
ERROR: cannot create foreign key constraint
|
||||||
|
DETAIL: SET NULL or SET DEFAULT is not supported in ON DELETE operation when distribution key is included in the foreign key constraint
|
||||||
|
-- with reference tables it should all work fine
|
||||||
|
SELECT create_reference_table('FKTABLE');
|
||||||
|
create_reference_table
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
-- show that the definition is expected
|
||||||
|
SELECT pg_get_constraintdef(oid) FROM pg_constraint WHERE conrelid = 'fktable'::regclass::oid ORDER BY oid;
|
||||||
|
pg_get_constraintdef
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
FOREIGN KEY (tid, fk_id_del_set_null) REFERENCES pktable(tid, id) ON DELETE SET NULL (fk_id_del_set_null)
|
||||||
|
FOREIGN KEY (tid, fk_id_del_set_default) REFERENCES pktable(tid, id) ON DELETE SET DEFAULT (fk_id_del_set_default)
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
\c - - - :worker_1_port
|
||||||
|
SET search_path TO pg15;
|
||||||
|
-- show that the definition is expected on the worker as well
|
||||||
|
SELECT pg_get_constraintdef(oid) FROM pg_constraint WHERE conrelid = 'fktable'::regclass::oid ORDER BY oid;
|
||||||
|
pg_get_constraintdef
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
FOREIGN KEY (tid, fk_id_del_set_default) REFERENCES pktable(tid, id) ON DELETE SET DEFAULT (fk_id_del_set_default)
|
||||||
|
FOREIGN KEY (tid, fk_id_del_set_null) REFERENCES pktable(tid, id) ON DELETE SET NULL (fk_id_del_set_null)
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
-- also, make sure that it works as expected
|
||||||
|
INSERT INTO PKTABLE VALUES (1, 0), (1, 1), (1, 2);
|
||||||
|
INSERT INTO FKTABLE VALUES
|
||||||
|
(1, 1, 1, NULL),
|
||||||
|
(1, 2, NULL, 2);
|
||||||
|
DELETE FROM PKTABLE WHERE id = 1 OR id = 2;
|
||||||
|
SELECT * FROM FKTABLE ORDER BY id;
|
||||||
|
tid | id | fk_id_del_set_null | fk_id_del_set_default
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
1 | 1 | |
|
||||||
|
1 | 2 | | 0
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
-- Clean up
|
-- Clean up
|
||||||
|
\c - - - :master_port
|
||||||
\set VERBOSITY terse
|
\set VERBOSITY terse
|
||||||
DROP SCHEMA pg15 CASCADE;
|
DROP SCHEMA pg15 CASCADE;
|
||||||
NOTICE: drop cascades to 13 other objects
|
NOTICE: drop cascades to 15 other objects
|
||||||
|
|
|
@ -298,6 +298,47 @@ ALTER TABLE copy_test2 RENAME COLUMN data_ TO data;
|
||||||
COPY copy_test2 FROM :'temp_dir''copy_test.txt' WITH ( HEADER match, FORMAT text);
|
COPY copy_test2 FROM :'temp_dir''copy_test.txt' WITH ( HEADER match, FORMAT text);
|
||||||
SELECT count(*)=100 FROM copy_test2;
|
SELECT count(*)=100 FROM copy_test2;
|
||||||
|
|
||||||
|
|
||||||
|
-- allow foreign key columns to have SET NULL/DEFAULT on column basis
|
||||||
|
-- currently only reference tables can support that
|
||||||
|
CREATE TABLE PKTABLE (tid int, id int, PRIMARY KEY (tid, id));
|
||||||
|
CREATE TABLE FKTABLE (
|
||||||
|
tid int, id int,
|
||||||
|
fk_id_del_set_null int,
|
||||||
|
fk_id_del_set_default int DEFAULT 0,
|
||||||
|
FOREIGN KEY (tid, fk_id_del_set_null) REFERENCES PKTABLE ON DELETE SET NULL (fk_id_del_set_null),
|
||||||
|
FOREIGN KEY (tid, fk_id_del_set_default) REFERENCES PKTABLE ON DELETE SET DEFAULT (fk_id_del_set_default)
|
||||||
|
);
|
||||||
|
|
||||||
|
SELECT create_reference_table('PKTABLE');
|
||||||
|
|
||||||
|
-- ok, Citus could relax this constraint in the future
|
||||||
|
SELECT create_distributed_table('FKTABLE', 'tid');
|
||||||
|
|
||||||
|
-- with reference tables it should all work fine
|
||||||
|
SELECT create_reference_table('FKTABLE');
|
||||||
|
|
||||||
|
-- show that the definition is expected
|
||||||
|
SELECT pg_get_constraintdef(oid) FROM pg_constraint WHERE conrelid = 'fktable'::regclass::oid ORDER BY oid;
|
||||||
|
|
||||||
|
\c - - - :worker_1_port
|
||||||
|
|
||||||
|
SET search_path TO pg15;
|
||||||
|
|
||||||
|
-- show that the definition is expected on the worker as well
|
||||||
|
SELECT pg_get_constraintdef(oid) FROM pg_constraint WHERE conrelid = 'fktable'::regclass::oid ORDER BY oid;
|
||||||
|
|
||||||
|
-- also, make sure that it works as expected
|
||||||
|
INSERT INTO PKTABLE VALUES (1, 0), (1, 1), (1, 2);
|
||||||
|
INSERT INTO FKTABLE VALUES
|
||||||
|
(1, 1, 1, NULL),
|
||||||
|
(1, 2, NULL, 2);
|
||||||
|
DELETE FROM PKTABLE WHERE id = 1 OR id = 2;
|
||||||
|
SELECT * FROM FKTABLE ORDER BY id;
|
||||||
|
|
||||||
|
|
||||||
-- Clean up
|
-- Clean up
|
||||||
|
\c - - - :master_port
|
||||||
|
|
||||||
\set VERBOSITY terse
|
\set VERBOSITY terse
|
||||||
DROP SCHEMA pg15 CASCADE;
|
DROP SCHEMA pg15 CASCADE;
|
||||||
|
|
Loading…
Reference in New Issue