pgsql: Change FK trigger creation order to better support self-referent

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Change FK trigger creation order to better support self-referent
Дата
Msg-id E1RJ6t8-0008Hl-DE@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/58958726ffaec8d1a5d6a63f648443886fde8a21

Modified Files
--------------
src/backend/commands/tablecmds.c          |   28 +++++++++++++++++++------
src/test/regress/expected/foreign_key.out |   32 +++++++++++++++++++++++++++++
src/test/regress/sql/foreign_key.sql      |   22 +++++++++++++++++++
3 files changed, 75 insertions(+), 7 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Change FK trigger creation order to better support self-referent
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Change FK trigger creation order to better support self-referent