forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf21fada
committed
Avoid detoasting failure after COMMIT inside a plpgsql FOR loop.
exec_for_query() normally tries to prefetch a few rows at a timefrom the query being iterated over, so as to reduce executorentry/exit overhead. Unfortunately this is unsafe if we haveCOMMIT or ROLLBACK within the loop, because there might beTOAST references in the data that we prefetched but haven'tyet examined. Immediately after the COMMIT/ROLLBACK, we haveno snapshots in the session, meaning that VACUUM is at libertyto remove recently-deleted TOAST rows.This was originally reported as a case triggering the "no knownsnapshots" error in init_toast_snapshot(), but even if you misshitting that, you can get "missing toast chunk", as illustratedby the added isolation test case.To fix, just disable prefetching in non-atomic contexts. Maybethere will be performance complaints prompting us to work harderlater, but it's not clear at the moment that this really costsmuch, and I doubt we'd want to back-patch any complicated fix.In passing, adjust that error message in init_toast_snapshot()to be a little clearer about the likely cause of the problem.Patch by me, based on earlier investigation by Konstantin Knizhnik.Per bug #15990 from Andreas Wicht. Back-patch to v11 whereintra-procedure COMMIT was added.Discussion:https://postgr.es/m/15990-eee2ac466b11293d@postgresql.org1 parent4f586fe commitf21fada
File tree
4 files changed
+88
-1
lines changed- src
- backend/access/common
- pl/plpgsql/src
- test/isolation
- expected
- specs
4 files changed
+88
-1
lines changedLines changed: 14 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
638 | 638 |
| |
639 | 639 |
| |
640 | 640 |
| |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
641 | 654 |
| |
642 |
| - | |
| 655 | + | |
643 | 656 |
| |
644 | 657 |
| |
645 | 658 |
|
Lines changed: 11 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5826 | 5826 |
| |
5827 | 5827 |
| |
5828 | 5828 |
| |
| 5829 | + | |
| 5830 | + | |
| 5831 | + | |
| 5832 | + | |
| 5833 | + | |
| 5834 | + | |
| 5835 | + | |
| 5836 | + | |
| 5837 | + | |
| 5838 | + | |
| 5839 | + | |
5829 | 5840 |
| |
5830 | 5841 |
| |
5831 | 5842 |
| |
|
Lines changed: 43 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
192 | 192 |
| |
193 | 193 |
| |
194 | 194 |
| |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + |
Lines changed: 20 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
112 | 112 |
| |
113 | 113 |
| |
114 | 114 |
| |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
115 | 134 |
| |
116 | 135 |
| |
117 | 136 |
| |
| |||
135 | 154 |
| |
136 | 155 |
| |
137 | 156 |
| |
| 157 | + |
0 commit comments
Comments
(0)