postgresql/src
Tom Lane c1b7a6c273 Fix some anomalies with NO SCROLL cursors.
We have long forbidden fetching backwards from a NO SCROLL cursor,
but the prohibition didn't extend to cases in which we rewind the
query altogether and then re-fetch forwards.  I think the reason is
that this logic was mainly meant to protect plan nodes that can't
be run in the reverse direction.  However, re-reading the query output
is problematic if the query is volatile (which includes SELECT FOR
UPDATE, not just queries with volatile functions): the re-read can
produce different results, which confuses the cursor navigation logic
completely.  Another reason for disliking this approach is that some
code paths will either fetch backwards or rewind-and-fetch-forwards
depending on the distance to the target row; so that seemingly
identical use-cases may or may not draw the "cursor can only scan
forward" error.  Hence, let's clean things up by disallowing rewind
as well as fetch-backwards in a NO SCROLL cursor.

Ordinarily we'd only make such a definitional change in HEAD, but
there is a third reason to consider this change now.  Commit ba2c6d6ce
created some new user-visible anomalies for non-scrollable cursors
WITH HOLD, in that navigation in the cursor result got confused if the
cursor had been partially read before committing.  The only good way
to resolve those anomalies is to forbid rewinding such a cursor, which
allows removal of the incorrect cursor state manipulations that
ba2c6d6ce added to PersistHoldablePortal.

To minimize the behavioral change in the back branches (including
v14), refuse to rewind a NO SCROLL cursor only when it has a holdStore,
ie has been held over from a previous transaction due to WITH HOLD.
This should avoid breaking most applications that have been sloppy
about whether to declare cursors as scrollable.  We'll enforce the
prohibition across-the-board beginning in v15.

Back-patch to v11, as ba2c6d6ce was.

Discussion: https://postgr.es/m/3712911.1631207435@sss.pgh.pa.us
2021-09-10 13:18:32 -04:00
..
backend Fix some anomalies with NO SCROLL cursors. 2021-09-10 13:18:32 -04:00
bin Revoke PUBLIC CREATE from public schema, now owned by pg_database_owner. 2021-09-09 23:38:09 -07:00
common Extend collection of Unicode combining characters to beyond the BMP 2021-08-26 13:07:34 -04:00
fe_utils Skip trailing whitespaces when parsing integer options 2021-07-27 10:39:05 +09:00
include Revoke PUBLIC CREATE from public schema, now owned by pg_database_owner. 2021-09-09 23:38:09 -07:00
interfaces Fix incorrect merge in ECPG code with DECLARE 2021-08-25 15:16:31 +09:00
makefiles
pl Revoke PUBLIC CREATE from public schema, now owned by pg_database_owner. 2021-09-09 23:38:09 -07:00
port windows: Only consider us to be running as service if stderr is invalid. 2021-09-07 11:56:13 -07:00
template
test Fix some anomalies with NO SCROLL cursors. 2021-09-10 13:18:32 -04:00
timezone
tools Add PublicationTable and PublicationRelInfo structs 2021-09-06 14:24:50 -03:00
tutorial
.gitignore
DEVELOPERS
Makefile
Makefile.global.in Fix prove_installcheck to use correct paths when used with PGXS 2021-07-01 09:02:46 -04:00
Makefile.shlib AIX: Fix missing libpq symbols by respecting SHLIB_EXPORTS. 2021-09-06 11:27:59 -07:00
nls-global.mk