forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit84f5c29
committed
Restore the portal-level snapshot after procedure COMMIT/ROLLBACK.
COMMIT/ROLLBACK necessarily destroys all snapshots within the session.The original implementation of intra-procedure transactions justcavalierly did that, ignoring the fact that this left us executing ina rather different environment than normal. In particular, it turnsout that handling of toasted datums depends rather critically on therebeing an outer ActiveSnapshot: otherwise, when SPI or the coreexecutor pop whatever snapshot they used and return, it's unsafe todereference any toasted datums that may appear in the query result.It's possible to demonstrate "no known snapshots" and "missing chunknumber N for toast value" errors as a result of this oversight.Historically this outer snapshot has been held by the Portal code,and that seems like a good plan to preserve. So add infrastructureto pquery.c to allow re-establishing the Portal-owned snapshot if it'snot there anymore, and add enough bookkeeping support that we can tellwhether it is or not.We can't, however, just re-establish the Portal snapshot as part ofCOMMIT/ROLLBACK. As in normal transaction start, acquiring the firstsnapshot should wait until after SET and LOCK commands. Hence, teachspi.c about doing this at the right time. (Note that this patchdoesn't fix the problem for any PLs that try to run intra-proceduretransactions without using SPI to execute SQL commands.)This makes SPI's no_snapshots parameter rather a misnomer, so in HEAD,rename that to allow_nonatomic.replication/logical/worker.c also needs some fixes, because it wasn'tcareful to hold a snapshot open around AFTER trigger execution.That code doesn't use a Portal, which I suspect someday we're gonnahave to fix. But for now, just rearrange the order of operations.This includes back-patching the recent addition of finish_estate()to centralize the cleanup logic there.This also back-patches commit2ecfeda into v13, to improve thetest coverage for worker.c (it was that test that exposed thatworker.c's snapshot management is wrong).Per bug #15990 from Andreas Wicht. Back-patch to v11 whereintra-procedure COMMIT was added.Discussion:https://postgr.es/m/15990-eee2ac466b11293d@postgresql.org1 parent124966c commit84f5c29
File tree
12 files changed
+312
-107
lines changed- doc/src/sgml
- src
- backend
- commands
- executor
- replication/logical
- tcop
- utils/mmgr
- include
- executor
- tcop
- utils
- pl/plpgsql/src
- test/isolation
- expected
- specs
12 files changed
+312
-107
lines changedLines changed: 6 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
730 | 730 |
| |
731 | 731 |
| |
732 | 732 |
| |
733 |
| - | |
| 733 | + | |
734 | 734 |
| |
735 | 735 |
| |
736 |
| - | |
737 |
| - | |
| 736 | + | |
| 737 | + | |
738 | 738 |
| |
739 | 739 |
| |
740 | 740 |
| |
| |||
1860 | 1860 |
| |
1861 | 1861 |
| |
1862 | 1862 |
| |
1863 |
| - | |
| 1863 | + | |
1864 | 1864 |
| |
1865 | 1865 |
| |
1866 |
| - | |
1867 |
| - | |
| 1866 | + | |
| 1867 | + | |
1868 | 1868 |
| |
1869 | 1869 |
| |
1870 | 1870 |
| |
|
Lines changed: 15 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
64 | 64 |
| |
65 | 65 |
| |
66 | 66 |
| |
| 67 | + | |
67 | 68 |
| |
68 | 69 |
| |
69 | 70 |
| |
| |||
2319 | 2320 |
| |
2320 | 2321 |
| |
2321 | 2322 |
| |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
2322 | 2337 |
| |
2323 | 2338 |
| |
2324 | 2339 |
| |
|
Lines changed: 53 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
66 | 66 |
| |
67 | 67 |
| |
68 | 68 |
| |
69 |
| - | |
| 69 | + | |
70 | 70 |
| |
71 | 71 |
| |
72 | 72 |
| |
| |||
260 | 260 |
| |
261 | 261 |
| |
262 | 262 |
| |
263 |
| - | |
264 |
| - | |
265 |
| - | |
266 |
| - | |
267 |
| - | |
268 |
| - | |
| 263 | + | |
| 264 | + | |
269 | 265 |
| |
270 | 266 |
| |
271 | 267 |
| |
| |||
322 | 318 |
| |
323 | 319 |
| |
324 | 320 |
| |
| 321 | + | |
| 322 | + | |
| 323 | + | |
325 | 324 |
| |
326 | 325 |
| |
327 | 326 |
| |
| |||
567 | 566 |
| |
568 | 567 |
| |
569 | 568 |
| |
570 |
| - | |
| 569 | + | |
571 | 570 |
| |
572 | 571 |
| |
573 | 572 |
| |
| |||
627 | 626 |
| |
628 | 627 |
| |
629 | 628 |
| |
630 |
| - | |
| 629 | + | |
631 | 630 |
| |
632 | 631 |
| |
633 | 632 |
| |
| |||
2264 | 2263 |
| |
2265 | 2264 |
| |
2266 | 2265 |
| |
2267 |
| - | |
| 2266 | + | |
2268 | 2267 |
| |
2269 | 2268 |
| |
2270 | 2269 |
| |
| |||
2275 | 2274 |
| |
2276 | 2275 |
| |
2277 | 2276 |
| |
2278 |
| - | |
| 2277 | + | |
2279 | 2278 |
| |
2280 | 2279 |
| |
2281 | 2280 |
| |
| |||
2318 | 2317 |
| |
2319 | 2318 |
| |
2320 | 2319 |
| |
2321 |
| - | |
2322 |
| - | |
| 2320 | + | |
| 2321 | + | |
2323 | 2322 |
| |
2324 |
| - | |
| 2323 | + | |
2325 | 2324 |
| |
| 2325 | + | |
2326 | 2326 |
| |
2327 | 2327 |
| |
2328 | 2328 |
| |
| |||
2408 | 2408 |
| |
2409 | 2409 |
| |
2410 | 2410 |
| |
2411 |
| - | |
2412 |
| - | |
| 2411 | + | |
| 2412 | + | |
2413 | 2413 |
| |
2414 |
| - | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
2415 | 2419 |
| |
2416 |
| - | |
2417 |
| - | |
2418 |
| - | |
2419 |
| - | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
2420 | 2444 |
| |
2421 | 2445 |
| |
2422 | 2446 |
| |
| |||
2434 | 2458 |
| |
2435 | 2459 |
| |
2436 | 2460 |
| |
| 2461 | + | |
2437 | 2462 |
| |
2438 | 2463 |
| |
2439 | 2464 |
| |
| |||
2462 | 2487 |
| |
2463 | 2488 |
| |
2464 | 2489 |
| |
2465 |
| - | |
| 2490 | + | |
| 2491 | + | |
2466 | 2492 |
| |
2467 |
| - | |
| 2493 | + | |
2468 | 2494 |
| |
2469 | 2495 |
| |
2470 | 2496 |
| |
| |||
2507 | 2533 |
| |
2508 | 2534 |
| |
2509 | 2535 |
| |
2510 |
| - | |
2511 |
| - | |
2512 |
| - | |
2513 |
| - | |
2514 |
| - | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
2515 | 2539 |
| |
2516 |
| - | |
| 2540 | + | |
2517 | 2541 |
| |
2518 | 2542 |
| |
2519 | 2543 |
| |
|
Lines changed: 9 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
349 | 349 |
| |
350 | 350 |
| |
351 | 351 |
| |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
352 | 359 |
| |
353 | 360 |
| |
354 | 361 |
| |
| |||
400 | 407 |
| |
401 | 408 |
| |
402 | 409 |
| |
| 410 | + | |
403 | 411 |
| |
404 | 412 |
| |
405 | 413 |
| |
| |||
1212 | 1220 |
| |
1213 | 1221 |
| |
1214 | 1222 |
| |
1215 |
| - | |
1216 |
| - | |
1217 |
| - | |
1218 | 1223 |
| |
1219 | 1224 |
| |
1220 | 1225 |
| |
| |||
1229 | 1234 |
| |
1230 | 1235 |
| |
1231 | 1236 |
| |
1232 |
| - | |
1233 |
| - | |
1234 | 1237 |
| |
1235 | 1238 |
| |
1236 | 1239 |
| |
| |||
1358 | 1361 |
| |
1359 | 1362 |
| |
1360 | 1363 |
| |
1361 |
| - | |
1362 |
| - | |
1363 | 1364 |
| |
1364 | 1365 |
| |
1365 | 1366 |
| |
| |||
1374 | 1375 |
| |
1375 | 1376 |
| |
1376 | 1377 |
| |
1377 |
| - | |
1378 |
| - | |
1379 | 1378 |
| |
1380 | 1379 |
| |
1381 | 1380 |
| |
| |||
1482 | 1481 |
| |
1483 | 1482 |
| |
1484 | 1483 |
| |
1485 |
| - | |
1486 |
| - | |
1487 | 1484 |
| |
1488 | 1485 |
| |
1489 | 1486 |
| |
| |||
1497 | 1494 |
| |
1498 | 1495 |
| |
1499 | 1496 |
| |
1500 |
| - | |
1501 |
| - | |
1502 | 1497 |
| |
1503 | 1498 |
| |
1504 | 1499 |
| |
| |||
1818 | 1813 |
| |
1819 | 1814 |
| |
1820 | 1815 |
| |
1821 |
| - | |
| 1816 | + | |
1822 | 1817 |
| |
1823 | 1818 |
| |
1824 | 1819 |
| |
|
0 commit comments
Comments
(0)