From 2ada3e99ade14201bb3740b6c9b2b983311b578b Mon Sep 17 00:00:00 2001 From: Kristian Lejao <1741885+lejaokri@users.noreply.github.com> Date: Mon, 28 Aug 2023 23:56:51 -0700 Subject: [PATCH] Add basic serializable testcase (#198) Task: OSS-ONLY Signed-off-by: Kristian Lejao (cherry picked from commit 8a276b6054ddd861e6368076c6576f3a25103f14) --- src/test/regress/expected/serializable.out | 31 +++++++++++++++++++++ src/test/regress/parallel_schedule | 2 ++ src/test/regress/sql/serializable.sql | 32 ++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/test/regress/expected/serializable.out create mode 100644 src/test/regress/sql/serializable.sql diff --git a/src/test/regress/expected/serializable.out b/src/test/regress/expected/serializable.out new file mode 100644 index 00000000000..909cbf51d68 --- /dev/null +++ b/src/test/regress/expected/serializable.out @@ -0,0 +1,31 @@ +CREATE TABLE serializable_tab1 ( + id bigint NOT NULL +); +CREATE TABLE serializable_tab2 ( + id bigint NOT NULL, + user_id bigint +); +ALTER TABLE ONLY serializable_tab1 + ADD CONSTRAINT user_constraint UNIQUE (id); +ALTER TABLE ONLY serializable_tab2 + ADD CONSTRAINT assignment_constraint UNIQUE (user_id); +ALTER TABLE ONLY serializable_tab2 + ADD CONSTRAINT user_assignments_user_id_fkey FOREIGN KEY (user_id) REFERENCES serializable_tab1(id) ON DELETE CASCADE; +INSERT INTO serializable_tab1 (id) VALUES ('12345'); +INSERT INTO serializable_tab2 (id, user_id) VALUES ('1', '12345'); +BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; +DELETE FROM serializable_tab1 where id = '12345'; +SELECT * FROM serializable_tab1; + id +---- +(0 rows) + +ROLLBACK; +SELECT * FROM serializable_tab1; + id +------- + 12345 +(1 row) + +DROP TABLE serializable_tab2; +DROP TABLE serializable_tab1; diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule index 33c027a3c49..1b711c70ee9 100644 --- a/src/test/regress/parallel_schedule +++ b/src/test/regress/parallel_schedule @@ -135,3 +135,5 @@ test: event_trigger oidjoins # this test also uses event triggers, so likewise run it by itself test: fast_default + +test: serializable diff --git a/src/test/regress/sql/serializable.sql b/src/test/regress/sql/serializable.sql new file mode 100644 index 00000000000..2fdb2df5af2 --- /dev/null +++ b/src/test/regress/sql/serializable.sql @@ -0,0 +1,32 @@ +CREATE TABLE serializable_tab1 ( + id bigint NOT NULL +); + +CREATE TABLE serializable_tab2 ( + id bigint NOT NULL, + user_id bigint +); + +ALTER TABLE ONLY serializable_tab1 + ADD CONSTRAINT user_constraint UNIQUE (id); + +ALTER TABLE ONLY serializable_tab2 + ADD CONSTRAINT assignment_constraint UNIQUE (user_id); + +ALTER TABLE ONLY serializable_tab2 + ADD CONSTRAINT user_assignments_user_id_fkey FOREIGN KEY (user_id) REFERENCES serializable_tab1(id) ON DELETE CASCADE; + + +INSERT INTO serializable_tab1 (id) VALUES ('12345'); +INSERT INTO serializable_tab2 (id, user_id) VALUES ('1', '12345'); + +BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; +DELETE FROM serializable_tab1 where id = '12345'; +SELECT * FROM serializable_tab1; +ROLLBACK; + +SELECT * FROM serializable_tab1; + +DROP TABLE serializable_tab2; +DROP TABLE serializable_tab1; +