Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd5005b

Browse files
committed
Pass correct TupDesc to ri_NullCheck() in Assert
Previous coding was passing the wrong table's tuple descriptor, whichaccidentally fails to fail because no existing test case exercises aforeign key in which the referenced attributes are further to the rightof the referencing attributes.Add a test so that further breakage is visible.This got broken in16828d5.Discussion:https://postgr.es/m/20180403204723.fqte755nukgm42uf@alvherre.pgsql
1 parentdddfc4c commitcd5005b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

‎src/backend/utils/adt/ri_triggers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel,
514514
boolresult;
515515

516516
/* Only called for non-null rows */
517-
Assert(ri_NullCheck(RelationGetDescr(fk_rel),old_row,riinfo, true)==RI_KEYS_NONE_NULL);
517+
Assert(ri_NullCheck(RelationGetDescr(pk_rel),old_row,riinfo, true)==RI_KEYS_NONE_NULL);
518518

519519
if (SPI_connect()!=SPI_OK_CONNECT)
520520
elog(ERROR,"SPI_connect failed");

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,19 @@ explain (costs off) delete from t1 where a = 1;
13811381
(10 rows)
13821382

13831383
delete from t1 where a = 1;
1384+
-- Test a primary key with attributes located in later attnum positions
1385+
-- compared to the fk attributes.
1386+
create table pktable2 (a int, b int, c int, d int, e int, primary key (d, e));
1387+
create table fktable2 (d int, e int, foreign key (d, e) references pktable2);
1388+
insert into pktable2 values (1, 2, 3, 4, 5);
1389+
insert into fktable2 values (4, 5);
1390+
delete from pktable2;
1391+
ERROR: update or delete on table "pktable2" violates foreign key constraint "fktable2_d_fkey" on table "fktable2"
1392+
DETAIL: Key (d, e)=(4, 5) is still referenced from table "fktable2".
1393+
update pktable2 set d = 5;
1394+
ERROR: update or delete on table "pktable2" violates foreign key constraint "fktable2_d_fkey" on table "fktable2"
1395+
DETAIL: Key (d, e)=(4, 5) is still referenced from table "fktable2".
1396+
drop table pktable2, fktable2;
13841397
--
13851398
-- Test deferred FK check on a tuple deleted by a rolled-back subtransaction
13861399
--

‎src/test/regress/sql/foreign_key.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,16 @@ create rule r1 as on delete to t1 do delete from t2 where t2.b = old.a;
10201020
explain (costs off)deletefrom t1where a=1;
10211021
deletefrom t1where a=1;
10221022

1023+
-- Test a primary key with attributes located in later attnum positions
1024+
-- compared to the fk attributes.
1025+
createtablepktable2 (aint, bint, cint, dint, eint,primary key (d, e));
1026+
createtablefktable2 (dint, eint,foreign key (d, e)references pktable2);
1027+
insert into pktable2values (1,2,3,4,5);
1028+
insert into fktable2values (4,5);
1029+
deletefrom pktable2;
1030+
update pktable2set d=5;
1031+
droptable pktable2, fktable2;
1032+
10231033
--
10241034
-- Test deferred FK check on a tuple deleted by a rolled-back subtransaction
10251035
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp