- Notifications
You must be signed in to change notification settings - Fork5.2k
Commit27c7c11
committed
Fix concurrent update trigger issues with MERGE in a CTE.
If a MERGE inside a CTE attempts an UPDATE or DELETE on a table withBEFORE ROW triggers, and a concurrent UPDATE or DELETE happens, themerge code would fail (crashing in the case of an UPDATE action, andpotentially executing the wrong action for a DELETE action).This is the same issue that9321c79 attempted to fix, except nowfor a MERGE inside a CTE. As noted in9321c79, what needs to happenis for the trigger code to exit early, returning the TM_Result andTM_FailureData information to the merge code, if a concurrentmodification is detected, rather than attempting to do an EPQrecheck. The merge code will then do its own rechecking, and rescanthe action list, potentially executing a different action in light ofthe concurrent update. In particular, the trigger code must never callExecGetUpdateNewTuple() for MERGE, since that is bound to fail becauseMERGE has its own per-action projection information.Commit9321c79 did this using estate->es_plannedstmt->commandTypein the trigger code to detect that a MERGE was being executed, whichis fine for a plain MERGE command, but does not work for a MERGEinside a CTE. Fix by passing that information to the trigger code asan additional parameter passed to ExecBRUpdateTriggers() andExecBRDeleteTriggers().Back-patch as far as v17 only, since MERGE cannot appear inside a CTEprior to that. Additionally, take care to preserve the trigger ABI inv17 (though not in v18, which is still in beta).Bug: #18986Reported-by: Yaroslav Syrytsia <me@ys.lc>Author: Dean Rasheed <dean.a.rasheed@gmail.com>Reviewed-by: Michael Paquier <michael@paquier.xyz>Discussion:https://postgr.es/m/18986-e7a8aac3d339fa47@postgresql.orgBackpatch-through: 171 parentbfa9b25 commit27c7c11
File tree
6 files changed
+89
-50
lines changed- src
- backend
- commands
- executor
- include/commands
- test/isolation
- expected
- specs
6 files changed
+89
-50
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
2693 | 2694 | | |
2694 | 2695 | | |
2695 | 2696 | | |
2696 | | - | |
| 2697 | + | |
| 2698 | + | |
2697 | 2699 | | |
2698 | 2700 | | |
2699 | 2701 | | |
| |||
2708 | 2710 | | |
2709 | 2711 | | |
2710 | 2712 | | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
2711 | 2721 | | |
2712 | | - | |
2713 | | - | |
| 2722 | + | |
| 2723 | + | |
2714 | 2724 | | |
2715 | 2725 | | |
2716 | 2726 | | |
| |||
2800 | 2810 | | |
2801 | 2811 | | |
2802 | 2812 | | |
| 2813 | + | |
2803 | 2814 | | |
2804 | 2815 | | |
2805 | 2816 | | |
| |||
2944 | 2955 | | |
2945 | 2956 | | |
2946 | 2957 | | |
2947 | | - | |
| 2958 | + | |
| 2959 | + | |
2948 | 2960 | | |
2949 | 2961 | | |
2950 | 2962 | | |
| |||
2965 | 2977 | | |
2966 | 2978 | | |
2967 | 2979 | | |
2968 | | - | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
2969 | 2988 | | |
2970 | | - | |
2971 | | - | |
| 2989 | + | |
| 2990 | + | |
2972 | 2991 | | |
2973 | 2992 | | |
2974 | 2993 | | |
| |||
3142 | 3161 | | |
3143 | 3162 | | |
3144 | 3163 | | |
| 3164 | + | |
3145 | 3165 | | |
3146 | 3166 | | |
3147 | 3167 | | |
| |||
3298 | 3318 | | |
3299 | 3319 | | |
3300 | 3320 | | |
| 3321 | + | |
3301 | 3322 | | |
3302 | 3323 | | |
3303 | 3324 | | |
| |||
3357 | 3378 | | |
3358 | 3379 | | |
3359 | 3380 | | |
3360 | | - | |
3361 | | - | |
3362 | | - | |
| 3381 | + | |
| 3382 | + | |
3363 | 3383 | | |
3364 | | - | |
| 3384 | + | |
3365 | 3385 | | |
3366 | | - | |
3367 | | - | |
3368 | | - | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
| 3391 | + | |
| 3392 | + | |
| 3393 | + | |
| 3394 | + | |
| 3395 | + | |
| 3396 | + | |
| 3397 | + | |
| 3398 | + | |
| 3399 | + | |
3369 | 3400 | | |
3370 | | - | |
3371 | | - | |
3372 | | - | |
3373 | | - | |
3374 | | - | |
3375 | | - | |
3376 | | - | |
3377 | | - | |
3378 | | - | |
3379 | | - | |
3380 | | - | |
| 3401 | + | |
3381 | 3402 | | |
3382 | | - | |
| 3403 | + | |
| 3404 | + | |
3383 | 3405 | | |
3384 | 3406 | | |
3385 | 3407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
670 | 670 | | |
671 | 671 | | |
672 | 672 | | |
673 | | - | |
| 673 | + | |
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
| |||
746 | 746 | | |
747 | 747 | | |
748 | 748 | | |
749 | | - | |
| 749 | + | |
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1474 | 1474 | | |
1475 | 1475 | | |
1476 | 1476 | | |
1477 | | - | |
| 1477 | + | |
| 1478 | + | |
1478 | 1479 | | |
1479 | 1480 | | |
1480 | 1481 | | |
| |||
2117 | 2118 | | |
2118 | 2119 | | |
2119 | 2120 | | |
2120 | | - | |
| 2121 | + | |
| 2122 | + | |
2121 | 2123 | | |
2122 | 2124 | | |
2123 | 2125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
| 217 | + | |
217 | 218 | | |
218 | 219 | | |
219 | 220 | | |
| |||
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
238 | | - | |
| 239 | + | |
| 240 | + | |
239 | 241 | | |
240 | 242 | | |
241 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
253 | 257 | | |
254 | 258 | | |
255 | 259 | | |
256 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
257 | 266 | | |
258 | 267 | | |
259 | 268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
| |||
0 commit comments
Comments
(0)