summaryrefslogtreecommitdiff
path: root/src/test/isolation
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2025-04-23 12:03:02 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2025-04-23 12:03:02 -0400
commit3db61db48ef5b8898f7e85f98548fdec79d76524 (patch)
tree7765e7c6d128db5c08ad30ba8263b1f9e79854ed /src/test/isolation
parent994a100b37ad8c2fb8282a9fce91a16b4c832277 (diff)
Change the names generated for child foreign key constraints.
When a foreign key constraint is placed on a partitioned table, we actually make two pg_constraint entries associated with that table. (I have my doubts about the wisdom of that, but it's been like that since v12 and post-feature-freeze is no time to be messing with such entrenched decisions.) The second "child" entry always had a name generated according to the default rule, "table_column(s)_fkey[nnn]", even if the primary entry had an unrelated user-specified name. The trouble with doing that is that the default name could collide with the user-specified name of some other constraint on the same table. While we were willing to adjust the generated name to avoid collisions, that only helps if it's made second; if it's made first then creation of the other constraint would fail, potentially causing dump/reload or pg_upgrade failures. The core of the problem here is that we're infringing on user namespace, so I doubt that there's any 100% solution other than to find a way to not need the "child" entry. In the meantime, it seems like it'd be an improvement to make the child's name be the name of the parent constraint with an underscore and digit(s) appended as necessary to make it unique. This rule can in theory fail in the same way, but it seems much less probable; for one thing, this rule is guaranteed not to match primary entries having auto-generated names. (While an auto-generated primary name isn't user-specified to begin with, it acts like that during dump/reload, so collisions against such names are definitely possible.) An additional bonus, visible in some of the regression test cases that change here, arises from the fact that some error messages cite the child constraint's name not the parent's. In the previous approach the two names could be completely unrelated, leading to user confusion --- the more so since psql's \d command hides child constraints. With this approach it's hopefully much clearer which constraint-the-user-knows-about is failing. However, that does mean that there's user-visible behavior change occurring here, making it seem like not something to back-patch. I feel it's not too late for v18, though. Reported-by: Kirill Reshke <reshkekirill@gmail.com> Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/CALdSSPhGitjpTfzEMJN-Y2x+Q-5QChSxAsmSJ1-E8mQJLkHOqQ@mail.gmail.com
Diffstat (limited to 'src/test/isolation')
-rw-r--r--src/test/isolation/expected/detach-partition-concurrently-2.out2
-rw-r--r--src/test/isolation/expected/detach-partition-concurrently-4.out2
-rw-r--r--src/test/isolation/expected/fk-partitioned-1.out14
-rw-r--r--src/test/isolation/expected/fk-partitioned-2.out4
4 files changed, 11 insertions, 11 deletions
diff --git a/src/test/isolation/expected/detach-partition-concurrently-2.out b/src/test/isolation/expected/detach-partition-concurrently-2.out
index 6f025d81f5e..10cce9044f3 100644
--- a/src/test/isolation/expected/detach-partition-concurrently-2.out
+++ b/src/test/isolation/expected/detach-partition-concurrently-2.out
@@ -41,7 +41,7 @@ a
step s3i1: INSERT INTO d_lp_fk_r VALUES (1);
step s2d: ALTER TABLE d_lp_fk DETACH PARTITION d_lp_fk_1 CONCURRENTLY;
-ERROR: removing partition "d_lp_fk_1" violates foreign key constraint "d_lp_fk_r_a_fkey1"
+ERROR: removing partition "d_lp_fk_1" violates foreign key constraint "d_lp_fk_r_a_fkey_1"
step s1c: COMMIT;
starting permutation: s1b s1s s3i2 s2d s1c
diff --git a/src/test/isolation/expected/detach-partition-concurrently-4.out b/src/test/isolation/expected/detach-partition-concurrently-4.out
index b652522e424..79b29ae4c10 100644
--- a/src/test/isolation/expected/detach-partition-concurrently-4.out
+++ b/src/test/isolation/expected/detach-partition-concurrently-4.out
@@ -298,7 +298,7 @@ step s1updcur: update d4_fk set a = 1 where current of f;
step s2detach: alter table d4_primary detach partition d4_primary1 concurrently; <waiting ...>
step s1c: commit;
step s2detach: <... completed>
-ERROR: removing partition "d4_primary1" violates foreign key constraint "d4_fk_a_fkey1"
+ERROR: removing partition "d4_primary1" violates foreign key constraint "d4_fk_a_fkey_1"
starting permutation: s2snitch s1b s1s s2detach s3insert s1c
step s2snitch: insert into d4_pid select pg_backend_pid();
diff --git a/src/test/isolation/expected/fk-partitioned-1.out b/src/test/isolation/expected/fk-partitioned-1.out
index 45f2f8cba71..686f7184d0b 100644
--- a/src/test/isolation/expected/fk-partitioned-1.out
+++ b/src/test/isolation/expected/fk-partitioned-1.out
@@ -54,7 +54,7 @@ step s2a: alter table pfk attach partition pfk1 for values in (1);
step s1d: delete from ppk1 where a = 1; <waiting ...>
step s2c: commit;
step s1d: <... completed>
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;
starting permutation: s1b s2b s2a s2c s1d s1c
@@ -63,7 +63,7 @@ step s2b: begin;
step s2a: alter table pfk attach partition pfk1 for values in (1);
step s2c: commit;
step s1d: delete from ppk1 where a = 1;
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;
starting permutation: s2b s1b s1d s1c s2a s2c
@@ -92,7 +92,7 @@ step s2a: alter table pfk attach partition pfk1 for values in (1);
step s1d: delete from ppk1 where a = 1; <waiting ...>
step s2c: commit;
step s1d: <... completed>
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;
starting permutation: s2b s1b s2a s2c s1d s1c
@@ -101,7 +101,7 @@ step s1b: begin;
step s2a: alter table pfk attach partition pfk1 for values in (1);
step s2c: commit;
step s1d: delete from ppk1 where a = 1;
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;
starting permutation: s2b s2a s1b s1d s2c s1c
@@ -111,7 +111,7 @@ step s1b: begin;
step s1d: delete from ppk1 where a = 1; <waiting ...>
step s2c: commit;
step s1d: <... completed>
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;
starting permutation: s2b s2a s1b s2c s1d s1c
@@ -120,7 +120,7 @@ step s2a: alter table pfk attach partition pfk1 for values in (1);
step s1b: begin;
step s2c: commit;
step s1d: delete from ppk1 where a = 1;
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;
starting permutation: s2b s2a s2c s1b s1d s1c
@@ -129,5 +129,5 @@ step s2a: alter table pfk attach partition pfk1 for values in (1);
step s2c: commit;
step s1b: begin;
step s1d: delete from ppk1 where a = 1;
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;
diff --git a/src/test/isolation/expected/fk-partitioned-2.out b/src/test/isolation/expected/fk-partitioned-2.out
index 8c6c714d059..db621bee2d6 100644
--- a/src/test/isolation/expected/fk-partitioned-2.out
+++ b/src/test/isolation/expected/fk-partitioned-2.out
@@ -57,7 +57,7 @@ step s2i: insert into pfk values (1);
step s1d: delete from ppk where a = 1; <waiting ...>
step s2c: commit;
step s1d: <... completed>
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;
starting permutation: s1b s2bs s2i s1d s2c s1c
@@ -72,5 +72,5 @@ step s2i: insert into pfk values (1);
step s1d: delete from ppk where a = 1; <waiting ...>
step s2c: commit;
step s1d: <... completed>
-ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
+ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
step s1c: commit;