forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9321c79
committed
Fix concurrent update issues with MERGE.
If MERGE attempts an UPDATE or DELETE on a table with BEFORE ROWtriggers, or a cross-partition UPDATE (with or without triggers), anda concurrent UPDATE or DELETE happens, the merge code would fail.In some cases this would lead to a crash, while in others it wouldcause the wrong merge action to be executed, or no action at all. Theimmediate cause of the crash was the trigger code callingExecGetUpdateNewTuple() as part of the EPQ mechanism, which failsbecause during a merge ri_projectNew is NULL, since merge has its ownper-action projection information, which ExecGetUpdateNewTuple() knowsnothing about.Fix by arranging for the trigger code to exit early, returning theTM_Result and TM_FailureData information, if a concurrent modificationis detected, allowing the merge code to do the necessary EPQ handlingin its own way. Similarly, prevent the cross-partition update codefrom doing any EPQ processing for a merge, allowing the merge code towork out what it needs to do.This leads to a number of simplifications in nodeModifyTable.c. Mostnotably, the ModifyTableContext->GetUpdateNewTuple() callback is nolonger needed, and mergeGetUpdateNewTuple() can be deleted, sincethere is no longer any requirement for get-update-new-tuple during amerge. Similarly, ModifyTableContext->cpUpdateRetrySlot is no longerneeded. Thus ExecGetUpdateNewTuple() and the retry_slot handling ofExecCrossPartitionUpdate() can be restored to how they were in v14,before the merge code was added, and ExecMergeMatched() no longerneeds any special-case handling for cross-partition updates.While at it, tidy up ExecUpdateEpilogue() a bit, making it handlerecheckIndexes locally, rather than passing it in as a parameter,ensuring that it is freed properly. This dates back to when it wassplit off from ExecUpdate() to support merge.Per bug #17809 from Alexander Lakhin, and follow-up investigation ofbug #17792, also from Alexander Lakhin.Back-patch to v15, where MERGE was introduced, taking care to preservebackwards-compatibility of the trigger API in v15 for any extensionsthat might use it.Discussion:https://postgr.es/m/17809-9e6650bef133f0fe%40postgresql.orghttps://postgr.es/m/17792-0f89452029662c36%40postgresql.org1 parentb2bd9a6 commit9321c79
File tree
8 files changed
+636
-174
lines changed- src
- backend
- commands
- executor
- include/commands
- test/isolation
- expected
- specs
8 files changed
+636
-174
lines changedLines changed: 24 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
87 | 87 |
| |
88 | 88 |
| |
89 | 89 |
| |
| 90 | + | |
90 | 91 |
| |
91 | 92 |
| |
92 | 93 |
| |
| |||
2694 | 2695 |
| |
2695 | 2696 |
| |
2696 | 2697 |
| |
2697 |
| - | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
2698 | 2701 |
| |
2699 | 2702 |
| |
2700 | 2703 |
| |
| |||
2711 | 2714 |
| |
2712 | 2715 |
| |
2713 | 2716 |
| |
2714 |
| - | |
| 2717 | + | |
2715 | 2718 |
| |
2716 | 2719 |
| |
2717 | 2720 |
| |
| |||
2802 | 2805 |
| |
2803 | 2806 |
| |
2804 | 2807 |
| |
| 2808 | + | |
2805 | 2809 |
| |
2806 | 2810 |
| |
2807 | 2811 |
| |
| |||
2943 | 2947 |
| |
2944 | 2948 |
| |
2945 | 2949 |
| |
| 2950 | + | |
2946 | 2951 |
| |
2947 | 2952 |
| |
2948 | 2953 |
| |
| |||
2967 | 2972 |
| |
2968 | 2973 |
| |
2969 | 2974 |
| |
2970 |
| - | |
| 2975 | + | |
2971 | 2976 |
| |
2972 | 2977 |
| |
2973 | 2978 |
| |
| |||
3122 | 3127 |
| |
3123 | 3128 |
| |
3124 | 3129 |
| |
| 3130 | + | |
3125 | 3131 |
| |
3126 | 3132 |
| |
3127 | 3133 |
| |
| |||
3277 | 3283 |
| |
3278 | 3284 |
| |
3279 | 3285 |
| |
| 3286 | + | |
3280 | 3287 |
| |
3281 | 3288 |
| |
3282 | 3289 |
| |
| |||
3304 | 3311 |
| |
3305 | 3312 |
| |
3306 | 3313 |
| |
| 3314 | + | |
| 3315 | + | |
3307 | 3316 |
| |
3308 | 3317 |
| |
3309 | 3318 |
| |
| |||
3331 | 3340 |
| |
3332 | 3341 |
| |
3333 | 3342 |
| |
| 3343 | + | |
| 3344 | + | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
3334 | 3355 |
| |
3335 | 3356 |
| |
3336 | 3357 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
486 | 486 |
| |
487 | 487 |
| |
488 | 488 |
| |
489 |
| - | |
| 489 | + | |
490 | 490 |
| |
491 | 491 |
| |
492 | 492 |
| |
| |||
547 | 547 |
| |
548 | 548 |
| |
549 | 549 |
| |
550 |
| - | |
| 550 | + | |
551 | 551 |
| |
552 | 552 |
| |
553 | 553 |
| |
|
0 commit comments
Comments
(0)