From e5c21255bf7cba3be70de2aae2bdc4997e310d8d Mon Sep 17 00:00:00 2001 From: reshke Date: Fri, 4 Dec 2026 17:08:34 +0500 Subject: [PATCH 2/2] Test RI collation namespace drop with injection point Pause RI validation after the collation tuple lookup, then move the collation and drop its old schema from another session. This avoids locking pg_namespace in the test. --- src/test/modules/injection_points/Makefile | 1 + .../expected/ri_collation_schema_drop.out | 36 ++++++++ .../specs/ri_collation_schema_drop.spec | 84 +++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 src/test/modules/injection_points/expected/ri_collation_schema_drop.out create mode 100644 src/test/modules/injection_points/specs/ri_collation_schema_drop.spec diff --git a/src/test/modules/injection_points/Makefile b/src/test/modules/injection_points/Makefile index a7a16d5016a..0e7191e3213 100644 --- a/src/test/modules/injection_points/Makefile +++ b/src/test/modules/injection_points/Makefile @@ -31,6 +31,7 @@ ISOLATION = basic \ repack_temporal \ repack_temporal_multirange \ repack_toast \ + ri_collation_schema_drop \ ri_fastpath_reindex \ ri_fastpath_snapshot \ syscache-update-pruned \ diff --git a/src/test/modules/injection_points/expected/ri_collation_schema_drop.out b/src/test/modules/injection_points/expected/ri_collation_schema_drop.out new file mode 100644 index 00000000000..b1078a2655f --- /dev/null +++ b/src/test/modules/injection_points/expected/ri_collation_schema_drop.out @@ -0,0 +1,36 @@ +Parsed test spec with 2 sessions + +starting permutation: validate_fk move_and_drop_schema wake checked +step validate_fk: + DO $test$ + DECLARE + failure_state text; + BEGIN + BEGIN + EXECUTE 'ALTER TABLE public.ri_coll_child VALIDATE CONSTRAINT ri_coll_fk'; + EXCEPTION WHEN OTHERS THEN + failure_state := SQLSTATE; + END; + + IF failure_state IS NULL THEN + RAISE NOTICE 'validation completed'; + ELSE + RAISE NOTICE 'validation failed with SQLSTATE %', failure_state; + END IF; + END; + $test$; + +step move_and_drop_schema: + ALTER COLLATION ri_coll_s1.pk SET SCHEMA ri_coll_s3; + DROP SCHEMA ri_coll_s1; + CREATE SCHEMA ri_coll_s1; + +step wake: + DO $$BEGIN + PERFORM injection_points_detach('ri-generate-qual-collation'); + PERFORM injection_points_wakeup('ri-generate-qual-collation'); + END$$; + +s1: NOTICE: validation failed with SQLSTATE XX000 +step validate_fk: <... completed> +step checked: diff --git a/src/test/modules/injection_points/specs/ri_collation_schema_drop.spec b/src/test/modules/injection_points/specs/ri_collation_schema_drop.spec new file mode 100644 index 00000000000..384c1933cdc --- /dev/null +++ b/src/test/modules/injection_points/specs/ri_collation_schema_drop.spec @@ -0,0 +1,84 @@ +# Validate a foreign key while its referenced collation schema is dropped. +# +# The injection point pauses RI validation after it has fetched the collation +# tuple and before it looks up the collation's namespace name. The other +# session moves the collation and drops the old schema before waking validation. + +setup +{ + CREATE EXTENSION injection_points; + CREATE SCHEMA ri_coll_s1; + CREATE SCHEMA ri_coll_s2; + CREATE SCHEMA ri_coll_s3; + + CREATE COLLATION ri_coll_s1.pk (provider = libc, locale = 'C'); + CREATE COLLATION ri_coll_s2.fk (provider = libc, locale = 'C'); + + CREATE TABLE public.ri_coll_parent + ( + k text COLLATE ri_coll_s1.pk PRIMARY KEY + ); + CREATE TABLE public.ri_coll_child + ( + k text COLLATE ri_coll_s2.fk + ); + INSERT INTO public.ri_coll_parent VALUES ('key'); + INSERT INTO public.ri_coll_child VALUES ('key'); + ALTER TABLE public.ri_coll_child + ADD CONSTRAINT ri_coll_fk FOREIGN KEY (k) + REFERENCES public.ri_coll_parent (k) NOT VALID; +} + +teardown +{ + DROP TABLE public.ri_coll_child, public.ri_coll_parent; + DROP SCHEMA ri_coll_s1, ri_coll_s2, ri_coll_s3 CASCADE; + DROP EXTENSION injection_points; +} + +session s1 +setup +{ + DO $$BEGIN + PERFORM injection_points_set_local(); + PERFORM injection_points_attach('ri-generate-qual-collation', 'wait'); + END$$; +} +step validate_fk +{ + DO $test$ + DECLARE + failure_state text; + BEGIN + BEGIN + EXECUTE 'ALTER TABLE public.ri_coll_child VALIDATE CONSTRAINT ri_coll_fk'; + EXCEPTION WHEN OTHERS THEN + failure_state := SQLSTATE; + END; + + IF failure_state IS NULL THEN + RAISE NOTICE 'validation completed'; + ELSE + RAISE NOTICE 'validation failed with SQLSTATE %', failure_state; + END IF; + END; + $test$; +} +step checked { } + +session s2 +step move_and_drop_schema +{ + ALTER COLLATION ri_coll_s1.pk SET SCHEMA ri_coll_s3; + DROP SCHEMA ri_coll_s1; + CREATE SCHEMA ri_coll_s1; +} +step wake +{ + DO $$BEGIN + PERFORM injection_points_detach('ri-generate-qual-collation'); + PERFORM injection_points_wakeup('ri-generate-qual-collation'); + END$$; +} + +permutation validate_fk move_and_drop_schema wake checked