postgresql/src
Tom Lane c401a7c527 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:53 -04:00
..
backend Change FK trigger creation order to better support self-referential FKs. 2011-10-26 13:02:53 -04:00
bin Fix pg_dump to dump casts between auto-generated types. 2011-10-18 17:11:18 -04:00
include Stamp 8.3.16. 2011-09-22 18:06:36 -04:00
interfaces Stamp 8.3.16. 2011-09-22 18:06:36 -04:00
makefiles Fix assorted issues with build and install paths containing spaces. 2011-06-14 16:24:45 -04:00
pl Fix assorted issues with build and install paths containing spaces. 2011-06-14 16:24:45 -04:00
port Stamp 8.3.16. 2011-09-22 18:06:36 -04:00
template Use SYSV semaphores rather than POSIX on Darwin >= 6.0 (i.e., OS X 10.2 2007-09-26 00:32:46 +00:00
test Change FK trigger creation order to better support self-referential FKs. 2011-10-26 13:02:53 -04:00
timezone Fix our mapping of Windows timezones for Central America. 2011-09-23 22:14:06 -04:00
tools Back-patch Fix bat file quoting of %ENV from commit 19b7fac8. 2011-07-04 10:12:27 -04:00
tutorial Update copyrights in source tree to 2008. 2008-01-01 19:46:01 +00:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:12 +02:00
bcc32.mak Remove old-style win32 client-only visual c++ build infrastructure for everything except 2007-03-05 14:18:38 +00:00
DEVELOPERS Testing commit stuff 2006-07-10 15:50:02 +00:00
Makefile Tsearch2 functionality migrates to core. The bulk of this work is by 2007-08-21 01:11:32 +00:00
Makefile.global.in Back-patch creation of tar.bz2 tarball during "make dist". 2011-07-03 16:40:34 -04:00
Makefile.shlib Fix assorted issues with build and install paths containing spaces. 2011-06-14 16:24:45 -04:00
nls-global.mk When merging PO files, take into consideration translations in other PO 2006-04-05 13:40:15 +00:00
win32.mak Update supported standalone VC++ version to 7.1+ only, and fix 2007-08-03 10:47:11 +00:00