]> granicus.if.org Git - postgresql/commit
Fix incorrect optimization of foreign-key checks. When an UPDATE on the
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 17 Jul 2007 17:45:28 +0000 (17:45 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 17 Jul 2007 17:45:28 +0000 (17:45 +0000)
commit2c535bfe81ad7cd77d561cd92c441a4787047aa1
tree029339e4c5af7dd386dd6dcf469aa37f8e08b49f
parenta5ca334a2141439b372758869e6ef4adb216f4a5
Fix incorrect optimization of foreign-key checks.  When an UPDATE on the
referencing table does not change the tuple's FK column(s), we don't bother
to check the PK table since the constraint was presumably already valid.
However, the check is still necessary if the tuple was inserted by our own
transaction, since in that case the INSERT trigger will conclude it need not
make the check (since its version of the tuple has been deleted).  We got this
right for simple cases, but not when the insert and update are in different
subtransactions of the current top-level transaction; in such cases the FK
check would never be made at all.  (Hence, problem dates back to 8.0 when
subtransactions were added --- it's actually the subtransaction version of a
bug fixed in 7.3.5.)  Fix, and add regression test cases.  Report and fix by
Affan Salman.
src/backend/commands/trigger.c
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql