forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9ee1cf0
committed
Fix TOAST access failure in RETURNING queries.
Discussion of commit3e2f3c2 exposed a problem that is of longerstanding: since we don't detoast data while sticking it into a portal'sholdStore for PORTAL_ONE_RETURNING and PORTAL_UTIL_SELECT queries, and werelease the query's snapshot as soon as we're done loading the holdStore,later readout of the holdStore can do TOAST fetches against data that canno longer be seen by any of the session's live snapshots. This means thata concurrent VACUUM could remove the TOAST data before we can fetch it.Commit3e2f3c2 exposed the problem by showing that sometimes we had *no*live snapshots while fetching TOAST data, but we'd be at risk anyway.I believe this code was all right when written, because our management of asession's exposed xmin was such that the TOAST references were safe untilend of transaction. But that's no longer true now that we can advance orclear our PGXACT.xmin intra-transaction.To fix, copy the query's snapshot during FillPortalStore() and save it inthe Portal; release it only when the portal is dropped. This essentiallyimplements a policy that we must hold a relevant snapshot whenever weaccess potentially-toasted data. We had already come to that conclusionin other places, cf commits08e261c andec543db.I'd have liked to add a regression test case for this, but I didn't seea way to make one that's not unreasonably bloated; it seems to requirereturning a toasted value to the client, and those will be big.In passing, improve PortalRunUtility() so that it positively verifiesthat its ending PopActiveSnapshot() call will pop the expected snapshot,removing a rather shaky assumption about which utility commands mightdo their own PopActiveSnapshot(). There's no known bug here, but nowthat we're actively referencing the snapshot it's almost free to makethis code a bit more bulletproof.We might want to consider back-patching something like this into olderbranches, but it would be prudent to let it prove itself more in HEADbeforehand.Discussion: <87vazemeda.fsf@credativ.de>1 parent07a601e commit9ee1cf0
File tree
4 files changed
+80
-22
lines changed- src
- backend
- commands
- tcop
- utils/mmgr
- include/utils
4 files changed
+80
-22
lines changedLines changed: 4 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
317 | 317 |
| |
318 | 318 |
| |
319 | 319 |
| |
320 |
| - | |
| 320 | + | |
321 | 321 |
| |
322 | 322 |
| |
323 | 323 |
| |
| 324 | + | |
324 | 325 |
| |
325 | 326 |
| |
326 | 327 |
| |
| |||
362 | 363 |
| |
363 | 364 |
| |
364 | 365 |
| |
365 |
| - | |
| 366 | + | |
| 367 | + | |
366 | 368 |
| |
367 | 369 |
| |
368 | 370 |
| |
|
Lines changed: 50 additions & 20 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
43 | 43 |
| |
44 | 44 |
| |
45 | 45 |
| |
46 |
| - | |
| 46 | + | |
| 47 | + | |
47 | 48 |
| |
48 |
| - | |
| 49 | + | |
| 50 | + | |
49 | 51 |
| |
50 | 52 |
| |
51 | 53 |
| |
| |||
810 | 812 |
| |
811 | 813 |
| |
812 | 814 |
| |
813 |
| - | |
| 815 | + | |
814 | 816 |
| |
815 | 817 |
| |
816 | 818 |
| |
| |||
1039 | 1041 |
| |
1040 | 1042 |
| |
1041 | 1043 |
| |
1042 |
| - | |
| 1044 | + | |
| 1045 | + | |
1043 | 1046 |
| |
1044 |
| - | |
| 1047 | + | |
1045 | 1048 |
| |
1046 | 1049 |
| |
1047 | 1050 |
| |
1048 | 1051 |
| |
1049 | 1052 |
| |
1050 |
| - | |
| 1053 | + | |
1051 | 1054 |
| |
1052 | 1055 |
| |
1053 | 1056 |
| |
| |||
1142 | 1145 |
| |
1143 | 1146 |
| |
1144 | 1147 |
| |
1145 |
| - | |
| 1148 | + | |
| 1149 | + | |
1146 | 1150 |
| |
1147 | 1151 |
| |
1148 |
| - | |
| 1152 | + | |
1149 | 1153 |
| |
1150 | 1154 |
| |
1151 | 1155 |
| |
| |||
1172 | 1176 |
| |
1173 | 1177 |
| |
1174 | 1178 |
| |
1175 |
| - | |
1176 |
| - | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
1177 | 1189 |
| |
1178 | 1190 |
| |
1179 |
| - | |
| 1191 | + | |
1180 | 1192 |
| |
1181 | 1193 |
| |
1182 | 1194 |
| |
| |||
1190 | 1202 |
| |
1191 | 1203 |
| |
1192 | 1204 |
| |
1193 |
| - | |
1194 |
| - | |
1195 |
| - | |
1196 |
| - | |
| 1205 | + | |
| 1206 | + | |
1197 | 1207 |
| |
1198 |
| - | |
| 1208 | + | |
| 1209 | + | |
1199 | 1210 |
| |
1200 | 1211 |
| |
1201 | 1212 |
| |
| |||
1205 | 1216 |
| |
1206 | 1217 |
| |
1207 | 1218 |
| |
1208 |
| - | |
| 1219 | + | |
| 1220 | + | |
1209 | 1221 |
| |
1210 | 1222 |
| |
1211 | 1223 |
| |
| |||
1261 | 1273 |
| |
1262 | 1274 |
| |
1263 | 1275 |
| |
1264 |
| - | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
1265 | 1295 |
| |
1266 | 1296 |
| |
1267 | 1297 |
| |
| |||
1309 | 1339 |
| |
1310 | 1340 |
| |
1311 | 1341 |
| |
1312 |
| - | |
| 1342 | + | |
1313 | 1343 |
| |
1314 | 1344 |
| |
1315 | 1345 |
| |
1316 | 1346 |
| |
1317 | 1347 |
| |
1318 | 1348 |
| |
1319 |
| - | |
| 1349 | + | |
1320 | 1350 |
| |
1321 | 1351 |
| |
1322 | 1352 |
| |
|
Lines changed: 16 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
24 | 24 |
| |
25 | 25 |
| |
26 | 26 |
| |
| 27 | + | |
27 | 28 |
| |
28 | 29 |
| |
29 | 30 |
| |
| |||
351 | 352 |
| |
352 | 353 |
| |
353 | 354 |
| |
| 355 | + | |
354 | 356 |
| |
355 | 357 |
| |
356 | 358 |
| |
| |||
526 | 528 |
| |
527 | 529 |
| |
528 | 530 |
| |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
529 | 545 |
| |
530 | 546 |
| |
531 | 547 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
162 | 162 |
| |
163 | 163 |
| |
164 | 164 |
| |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
165 | 175 |
| |
166 | 176 |
| |
167 | 177 |
| |
|
0 commit comments
Comments
(0)