From 845185fb05b2e6b167398465ec15a97102efac9c Mon Sep 17 00:00:00 2001 From: Rui Zhao Date: Tue, 11 Aug 2026 17:37:28 +0800 Subject: [PATCH 2/2] Cover the cross-schema ALTER INDEX ... ATTACH PARTITION in the tests v24 made emit_indexes() qualify the child index in ALTER INDEX ... ATTACH PARTITION, but the six expected lines that changed are all same-schema, where the old bare name happened to resolve through search_path. A fix that qualified with the base namespace rather than the child's own namespace would pass them too. The cross-schema partition block already in the file needs one index to exercise the real shape. --- src/test/regress/expected/pg_get_table_ddl.out | 9 ++++++++- src/test/regress/sql/pg_get_table_ddl.sql | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/regress/expected/pg_get_table_ddl.out b/src/test/regress/expected/pg_get_table_ddl.out index 717e2126b8..c7448bc10a 100644 --- a/src/test/regress/expected/pg_get_table_ddl.out +++ b/src/test/regress/expected/pg_get_table_ddl.out @@ -911,6 +911,10 @@ CREATE TABLE pgtbl_ddl_part_s.pt (id int, val int) PARTITION BY RANGE (id); CREATE TABLE pgtbl_ddl_part_other.pt_c PARTITION OF pgtbl_ddl_part_s.pt FOR VALUES FROM (0) TO (100); +-- The ALTER INDEX ... ATTACH PARTITION must name the child index with its +-- own schema, which is not the target table's; a bare name would resolve +-- through search_path on replay, or not at all. +CREATE INDEX pt_val_idx ON pgtbl_ddl_part_s.pt (val); SELECT * FROM pg_get_table_ddl('pgtbl_ddl_part_s.pt'::regclass, owner => false, schema_qualified => false); @@ -918,7 +922,10 @@ SELECT * FROM pg_get_table_ddl('pgtbl_ddl_part_s.pt'::regclass, -------------------------------------------------------------------------------------- CREATE TABLE pt (id integer, val integer) PARTITION BY RANGE (id); CREATE TABLE pgtbl_ddl_part_other.pt_c PARTITION OF pt FOR VALUES FROM (0) TO (100); -(2 rows) + CREATE INDEX pt_c_val_idx ON pgtbl_ddl_part_other.pt_c USING btree (val); + CREATE INDEX pt_val_idx ON ONLY pt USING btree (val); + ALTER INDEX pt_val_idx ATTACH PARTITION pgtbl_ddl_part_other.pt_c_val_idx; +(5 rows) DROP SCHEMA pgtbl_ddl_part_s CASCADE; NOTICE: drop cascades to table pgtbl_ddl_part_s.pt diff --git a/src/test/regress/sql/pg_get_table_ddl.sql b/src/test/regress/sql/pg_get_table_ddl.sql index 170c28d860..bebb3069a6 100644 --- a/src/test/regress/sql/pg_get_table_ddl.sql +++ b/src/test/regress/sql/pg_get_table_ddl.sql @@ -544,6 +544,10 @@ CREATE TABLE pgtbl_ddl_part_s.pt (id int, val int) PARTITION BY RANGE (id); CREATE TABLE pgtbl_ddl_part_other.pt_c PARTITION OF pgtbl_ddl_part_s.pt FOR VALUES FROM (0) TO (100); +-- The ALTER INDEX ... ATTACH PARTITION must name the child index with its +-- own schema, which is not the target table's; a bare name would resolve +-- through search_path on replay, or not at all. +CREATE INDEX pt_val_idx ON pgtbl_ddl_part_s.pt (val); SELECT * FROM pg_get_table_ddl('pgtbl_ddl_part_s.pt'::regclass, owner => false, schema_qualified => false); -- 2.43.7