Re: BUG #17050: cursor with for update + commit in loop
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: bulgakovalexey1980@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2021-06-08T20:01:46Z
Lists: pgsql-bugs
Attachments
- fix-unstable-cursor-in-transaction.patch (text/x-diff) patch
I wrote: > The only obvious way to fix this is to always save aside the output > of a cursor query in case we need to persist it later, so that > PersistHoldablePortal doesn't have to assume that rewinding is safe. > That would be pretty catastrophic for performance, though, so I doubt > anybody will be happy with that answer. > For cursors that aren't marked scrollable, we might be able to say > that we only save the *rest* of the query output, and then adjust > the cursor state appropriately for that choice. Seems possibly > nontrivial though, and there's still the question of what to do > for scrollable ones. Actually ... maybe it's not that bad. The nonscrollable case seems to be quite simple to fix, and as for the scrollable case, maybe we can just say it's on the user's head that the query produce stable results. There's already a prohibition on using FOR UPDATE with SCROLL, and the DECLARE CURSOR reference page has some warnings about volatile queries with WITH HOLD, which is basically the same case as we're worried about here. I think the DECLARE CURSOR page needs some modernization to mention that cursors in procedures are basically the same as WITH HOLD. But as far as code changes go, the attached seems sufficient. regards, tom lane
Commits
-
Force NO SCROLL for plpgsql's implicit cursors.
- c5b28184132d 13.4 landed
- be9009890747 14.0 landed
- 5b7bf9f72ab5 11.13 landed
- 182323300620 12.8 landed
-
Avoid misbehavior when persisting a non-stable cursor.
- ba2c6d6cec00 14.0 landed
- c3b5082685dd 12.8 landed
- c1fd756fd23f 13.4 landed
- 2757865fa7fb 11.13 landed