postgresql/src/backend/commands
Tom Lane f3bef03e7e Change FK trigger creation order to better support self-referential FKs.
When a foreign-key constraint references another column of the same table,
row updates will queue both the PK's ON UPDATE action and the FK's CHECK
action in the same event.  The ON UPDATE action must execute first, else
the CHECK will check a non-final state of the row and possibly throw an
inappropriate error, as seen in bug #6268 from Roman Lytovchenko.

Now, the firing order of multiple triggers for the same event is determined
by the sort order of their pg_trigger.tgnames, and the auto-generated names
we use for FK triggers are "RI_ConstraintTrigger_NNNN" where NNNN is the
trigger OID.  So most of the time the firing order is the same as creation
order, and so rearranging the creation order fixes it.

This patch will fail to fix the problem if the OID counter wraps around or
adds a decimal digit (eg, from 99999 to 100000) while we are creating the
triggers for an FK constraint.  Given the small odds of that, and the low
usage of self-referential FKs, we'll live with that solution in the back
branches.  A better fix is to change the auto-generated names for FK
triggers, but it seems unwise to do that in stable branches because there
may be client code that depends on the naming convention.  We'll fix it
that way in HEAD in a separate patch.

Back-patch to all supported branches, since this bug has existed for a long
time.
2011-10-26 13:02:46 -04:00
..
aggregatecmds.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
alter.c Update copyright for 2009. 2009-01-01 17:24:05 +00:00
analyze.c Avoid possibly accessing off the end of memory in examine_attribute(). 2011-09-06 14:37:59 -04:00
async.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
cluster.c Make CLUSTER lock the old table's toast table before copying data. 2011-05-01 17:57:46 -04:00
comment.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
conversioncmds.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
copy.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
dbcommands.c Prevent ALTER USER f RESET ALL from removing the settings that were put there 2010-03-25 14:44:51 +00:00
define.c Remove the recently added node types ReloptElem and OptionDefElem in favor 2009-04-04 21:12:31 +00:00
discard.c Update copyright for 2009. 2009-01-01 17:24:05 +00:00
explain.c Fix EXPLAIN to handle gating Result nodes within inner-indexscan subplans. 2011-07-03 01:35:22 -04:00
foreigncmds.c Fix unsafe order of operations in foreign-table DDL commands. 2011-08-14 15:40:41 -04:00
functioncmds.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
indexcmds.c Avoid changing an index's indcheckxmin horizon during REINDEX. 2011-04-19 18:51:08 -04:00
lockcmds.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
Makefile SQL/MED catalog manipulation facilities 2008-12-19 16:25:19 +00:00
opclasscmds.c Allow REASSIGNED OWNED to handle opclasses and opfamilies. 2010-07-03 13:53:26 +00:00
operatorcmds.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
portalcmds.c Fix snapshot management, take two. 2009-10-07 16:27:29 +00:00
prepare.c Previous fix for temporary file management broke returning a set from 2009-12-29 17:41:09 +00:00
proclang.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
schemacmds.c Prevent indirect security attacks via changing session-local state within 2009-12-09 21:58:04 +00:00
sequence.c Clean up after erroneous SELECT FOR UPDATE/SHARE on a sequence. 2011-06-02 15:31:14 -04:00
tablecmds.c Change FK trigger creation order to better support self-referential FKs. 2011-10-26 13:02:46 -04:00
tablespace.c Support column-level privileges, as required by SQL standard. 2009-01-22 20:16:10 +00:00
trigger.c Fix dangling-pointer problem in before-row update trigger processing. 2011-02-21 21:18:19 -05:00
tsearchcmds.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
typecmds.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
user.c Prevent ALTER USER f RESET ALL from removing the settings that were put there 2010-03-25 14:44:51 +00:00
vacuum.c Fix a missed case in code for "moving average" estimate of reltuples. 2011-08-30 14:50:02 -04:00
vacuumlazy.c Fix a missed case in code for "moving average" estimate of reltuples. 2011-08-30 14:50:02 -04:00
variable.c Prevent show_session_authorization from crashing when session_authorization 2010-09-23 16:53:28 -04:00
view.c 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00