]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add test case for same-type reordered FK columns master github/master
authorAmit Langote <amitlan@postgresql.org>
Fri, 10 Apr 2026 08:44:06 +0000 (17:44 +0900)
committerAmit Langote <amitlan@postgresql.org>
Fri, 10 Apr 2026 08:44:06 +0000 (17:44 +0900)
The test added in 980c1a85d819 covered reordered FK columns with
different types, which triggered an "operator not a member of opfamily"
error in the fast-path prior to that commit.  Add a test for the
same-type case, which is also fixed by that commit but where the wrong
scan key ordering instead produced a spurious FK violation without any
internal error.

Reported-by: Fredrik Widlert <fredrik.widlert@digpro.se>
Discussion: https://postgr.es/m/CADfhSr8hYc-4Cz7vfXH_oV-Jq81pyK9W4phLrOGspovsg2W7Kw@mail.gmail.com

src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql

index 9fa2e22329a8a9b96e7ab6180e5c00a55394e5cd..8b3b268de0fb13d3f39d996f3dd8d2e55732564d 100644 (file)
@@ -3672,6 +3672,16 @@ INSERT INTO fp_fk_order VALUES (3, 99, 'none', 9);  -- should fail
 ERROR:  insert or update on table "fp_fk_order" violates foreign key constraint "fp_fk_order_a_c_b_fkey"
 DETAIL:  Key (a, c, b)=(9, 99, none) is not present in table "fp_pk_order".
 DROP TABLE fp_fk_order, fp_pk_order;
+-- Same-type columns in different order:
+CREATE TABLE fp_pk_same (c1 int, c2 int, PRIMARY KEY (c1, c2));
+INSERT INTO fp_pk_same VALUES (1, 2);
+CREATE TABLE fp_fk_same (c1 int, c2 int,
+    FOREIGN KEY (c2, c1) REFERENCES fp_pk_same (c2, c1));
+INSERT INTO fp_fk_same VALUES (1, 2);  -- should succeed
+INSERT INTO fp_fk_same VALUES (9, 9);  -- should fail
+ERROR:  insert or update on table "fp_fk_same" violates foreign key constraint "fp_fk_same_c2_c1_fkey"
+DETAIL:  Key (c2, c1)=(9, 9) is not present in table "fp_pk_same".
+DROP TABLE fp_fk_same, fp_pk_same;
 -- Deferred constraint: batch flushed at COMMIT, not at statement end
 CREATE TABLE fp_pk_commit (a int PRIMARY KEY);
 CREATE TABLE fp_fk_commit (a int REFERENCES fp_pk_commit
index 9afee64d1e01386c9939dc8ae697ec2396753350..7eb86b188f06567a50cdd34504348b0240492419 100644 (file)
@@ -2643,6 +2643,15 @@ INSERT INTO fp_fk_order VALUES (2, 20, 'two', 2);  -- should succeed
 INSERT INTO fp_fk_order VALUES (3, 99, 'none', 9);  -- should fail
 DROP TABLE fp_fk_order, fp_pk_order;
 
+-- Same-type columns in different order:
+CREATE TABLE fp_pk_same (c1 int, c2 int, PRIMARY KEY (c1, c2));
+INSERT INTO fp_pk_same VALUES (1, 2);
+CREATE TABLE fp_fk_same (c1 int, c2 int,
+    FOREIGN KEY (c2, c1) REFERENCES fp_pk_same (c2, c1));
+INSERT INTO fp_fk_same VALUES (1, 2);  -- should succeed
+INSERT INTO fp_fk_same VALUES (9, 9);  -- should fail
+DROP TABLE fp_fk_same, fp_pk_same;
+
 -- Deferred constraint: batch flushed at COMMIT, not at statement end
 CREATE TABLE fp_pk_commit (a int PRIMARY KEY);
 CREATE TABLE fp_fk_commit (a int REFERENCES fp_pk_commit