- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit1f897ae
committed
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 CHECKaction in the same event. The ON UPDATE action must execute first, elsethe CHECK will check a non-final state of the row and possibly throw aninappropriate error, as seen in bug #6268 from Roman Lytovchenko.Now, the firing order of multiple triggers for the same event is determinedby the sort order of their pg_trigger.tgnames, and the auto-generated nameswe use for FK triggers are "RI_ConstraintTrigger_NNNN" where NNNN is thetrigger OID. So most of the time the firing order is the same as creationorder, and so rearranging the creation order fixes it.This patch will fail to fix the problem if the OID counter wraps around oradds a decimal digit (eg, from 99999 to 100000) while we are creating thetriggers for an FK constraint. Given the small odds of that, and the lowusage of self-referential FKs, we'll live with that solution in the backbranches. A better fix is to change the auto-generated names for FKtriggers, but it seems unwise to do that in stable branches because theremay be client code that depends on the naming convention. We'll fix itthat way in HEAD in a separate patch.Back-patch to all supported branches, since this bug has existed for a longtime.1 parent9a743ff commit1f897ae
File tree
3 files changed
+75
-7
lines changed- src
- backend/commands
- test/regress
- expected
- sql
3 files changed
+75
-7
lines changedLines changed: 21 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4735 | 4735 |
| |
4736 | 4736 |
| |
4737 | 4737 |
| |
4738 |
| - | |
4739 |
| - | |
4740 |
| - | |
4741 |
| - | |
4742 |
| - | |
4743 |
| - | |
4744 |
| - | |
4745 | 4738 |
| |
4746 | 4739 |
| |
4747 | 4740 |
| |
| |||
4879 | 4872 |
| |
4880 | 4873 |
| |
4881 | 4874 |
| |
| 4875 | + | |
| 4876 | + | |
| 4877 | + | |
| 4878 | + | |
| 4879 | + | |
| 4880 | + | |
| 4881 | + | |
| 4882 | + | |
| 4883 | + | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
4882 | 4896 |
| |
4883 | 4897 |
| |
4884 | 4898 |
| |
|
Lines changed: 32 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1276 | 1276 |
| |
1277 | 1277 |
| |
1278 | 1278 |
| |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + |
Lines changed: 22 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
899 | 899 |
| |
900 | 900 |
| |
901 | 901 |
| |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + |
0 commit comments
Comments
(0)