pgsql: Fix incorrect optimization of foreign-key checks. - Mailing list pgsql-committers

From tgl@postgresql.org (Tom Lane)
Subject pgsql: Fix incorrect optimization of foreign-key checks.
Date
Msg-id 20070717174557.1BD8B9FBAF7@postgresql.org
Whole thread Raw
List pgsql-committers
Log Message:
-----------
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.

Tags:
----
REL8_0_STABLE

Modified Files:
--------------
    pgsql/src/backend/utils/adt:
        ri_triggers.c (r1.76 -> r1.76.4.1)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/ri_triggers.c.diff?r1=1.76&r2=1.76.4.1)
    pgsql/src/test/regress/expected:
        foreign_key.out (r1.38 -> r1.38.4.1)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/foreign_key.out.diff?r1=1.38&r2=1.38.4.1)
    pgsql/src/test/regress/sql:
        foreign_key.sql (r1.15 -> r1.15.4.1)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/foreign_key.sql.diff?r1=1.15&r2=1.15.4.1)

pgsql-committers by date:

Previous
From: tgl@postgresql.org (Tom Lane)
Date:
Subject: pgsql: Fix incorrect optimization of foreign-key checks.
Next
From: momjian@postgresql.org (Bruce Momjian)
Date:
Subject: pgsql: Add: > > o Allow GLOBAL temporary tables to exist as empty by