forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3c43595
committed
Quick-hack fix for foreign key cascade vs triggers with transition tables.
AFTER triggers using transition tables crashed if they were fired dueto a foreign key ON CASCADE update. This is because ExecEndModifyTableflushes the transition tables, on the assumption that any trigger thatcould need them was already fired during ExecutorFinish. Normallythat's true, because we don't allow transition-table-using triggersto be deferred. However, foreign key CASCADE updates force anytriggers on the referencing table to be deferred to the outer querylevel, by means of the EXEC_FLAG_SKIP_TRIGGERS flag. I don't recallall the details of why it's like that and am pretty loath to redesignit right now. Instead, just teach ExecEndModifyTable to skip destroyingthe TransitionCaptureState when that flag is set. This will allow thetransition table data to survive until end of the current subtransaction.This isn't a terribly satisfactory solution, because (1) we might beleaking the transition tables for much longer than really necessary,and (2) as things stand, an AFTER STATEMENT trigger will fire once perRI updating query, ie once per row updated or deleted in the referencedtable. I suspect that is not per SQL spec. But redesigning this is aresearch project that we're certainly not going to get done for v10.So let's go with this hackish answer for now.In passing, tweak AfterTriggerSaveEvent to not save the transition_capturepointer into the event record for a deferrable trigger. This is notnecessary to fix the current bug, but it avoids letting dangling pointersto long-gone transition tables persist in the trigger event queue. That'sat least a safety feature. It might also allow merging shared triggerstates in more cases than before.I added a regression test that demonstrates the crash on unpatched code,and also exposes the behavior of firing the AFTER STATEMENT triggersonce per row update.Per bug #14808 from Philippe Beaudoin. Back-patch to v10.Discussion:https://postgr.es/m/20170909064853.25630.12825@wrigleys.postgresql.org1 parent610bbdd commit3c43595
File tree
4 files changed
+104
-3
lines changed- src
- backend
- commands
- executor
- test/regress
- expected
- sql
4 files changed
+104
-3
lines changedLines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5474 | 5474 |
| |
5475 | 5475 |
| |
5476 | 5476 |
| |
5477 |
| - | |
| 5477 | + | |
| 5478 | + | |
| 5479 | + | |
5478 | 5480 |
| |
5479 | 5481 |
| |
5480 | 5482 |
| |
|
Lines changed: 8 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2318 | 2318 |
| |
2319 | 2319 |
| |
2320 | 2320 |
| |
2321 |
| - | |
2322 |
| - | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
2323 | 2329 |
| |
2324 | 2330 |
| |
2325 | 2331 |
| |
|
Lines changed: 52 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2257 | 2257 |
| |
2258 | 2258 |
| |
2259 | 2259 |
| |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
2260 | 2312 |
| |
2261 | 2313 |
| |
2262 | 2314 |
| |
|
Lines changed: 41 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1771 | 1771 |
| |
1772 | 1772 |
| |
1773 | 1773 |
| |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
1774 | 1815 |
| |
1775 | 1816 |
| |
1776 | 1817 |
| |
|
0 commit comments
Comments
(0)