forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitba2c6d6
committed
Avoid misbehavior when persisting a non-stable cursor.
PersistHoldablePortal has long assumed that it should store theentire output of the query-to-be-persisted, which requires rewindingand re-reading the output. This is problematic if the query is notstable: we might get different row contents, or even a differentnumber of rows, which'd confuse the cursor state mightily.In the case where the cursor is NO SCROLL, this is very easy tosolve: just store the remaining query output, without any rewinding,and tweak the portal's cursor state to match. Aside from removingthe semantic problem, this could be significantly more efficientthan storing the whole output.If the cursor is scrollable, there's not much we can do, but itwas already the case that scrolling a volatile query's result waspretty unsafe. We can just document more clearly that gettingcorrect results from that is not guaranteed.There are already prohibitions in place on using SCROLL withFOR UPDATE/SHARE, which is one way for a SELECT query to havenon-stable results. We could imagine prohibiting SCROLL whenthe query contains volatile functions, but that would beexpensive to enforce. Moreover, it could break applicationsthat work just fine, if they have functions that are in factstable but the user neglected to mark them so. So settle fordocumenting the hazard.While this problem has existed in some guise for a long time,it got a lot worse in v11, which introduced the possibilityof persisting plpgsql cursors (perhaps implicit ones) evenwhen they violate the rules for what can be marked WITH HOLD.Hence, I've chosen to back-patch to v11 but not further.Per bug #17050 from Алексей Булгаков.Discussion:https://postgr.es/m/17050-f77aa827dc85247c@postgresql.org1 parent444302e commitba2c6d6
File tree
5 files changed
+122
-6
lines changed- doc/src/sgml
- ref
- src
- backend/commands
- pl/plpgsql/src
- expected
- sql
5 files changed
+122
-6
lines changedLines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3142 | 3142 |
| |
3143 | 3143 |
| |
3144 | 3144 |
| |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
3145 | 3154 |
| |
3146 | 3155 |
| |
3147 | 3156 |
| |
|
Lines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
239 | 239 |
| |
240 | 240 |
| |
241 | 241 |
| |
242 |
| - | |
| 242 | + | |
243 | 243 |
| |
244 | 244 |
| |
245 | 245 |
| |
246 |
| - | |
247 |
| - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
248 | 250 |
| |
249 | 251 |
| |
250 | 252 |
| |
|
Lines changed: 16 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
374 | 374 |
| |
375 | 375 |
| |
376 | 376 |
| |
377 |
| - | |
378 |
| - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
379 | 382 |
| |
380 |
| - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
381 | 394 |
| |
382 | 395 |
| |
383 | 396 |
| |
|
Lines changed: 51 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
335 | 335 |
| |
336 | 336 |
| |
337 | 337 |
| |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
338 | 389 |
| |
339 | 390 |
| |
340 | 391 |
| |
|
Lines changed: 41 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
273 | 273 |
| |
274 | 274 |
| |
275 | 275 |
| |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
276 | 317 |
| |
277 | 318 |
| |
278 | 319 |
| |
|
0 commit comments
Comments
(0)