Re: BUG #17889: Invalid cursor direction for a foreign scan that reached the fetch_size (MOVE BACKWARD ALL IN cX) - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #17889: Invalid cursor direction for a foreign scan that reached the fetch_size (MOVE BACKWARD ALL IN cX)
Date
Msg-id 3195560.1721073662@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #17889: Invalid cursor direction for a foreign scan that reached the fetch_size (MOVE BACKWARD ALL IN cX)  (Etsuro Fujita <etsuro.fujita@gmail.com>)
Responses Re: BUG #17889: Invalid cursor direction for a foreign scan that reached the fetch_size (MOVE BACKWARD ALL IN cX)
Re: BUG #17889: Invalid cursor direction for a foreign scan that reached the fetch_size (MOVE BACKWARD ALL IN cX)
List pgsql-bugs
Etsuro Fujita <etsuro.fujita@gmail.com> writes:
> On Mon, Jul 15, 2024 at 10:55 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Uh ... does this ensure that the data hasn't changed?

> postgres_fdw opens a remote transaction using REPEATABLE READ or
> SERIALIZABLE, so the recreated cursor uses the same snapshot except
> changes made by the remote transaction.

Ah, right.

> This causes eg, a join-UPDATE query where multiple rows join to the
> same foreign target row to repeatedly update the target row, as shown
> below, which would never happen if rewinding the cursor.
> ...
> Note that postgres_fdw already recreates a cursor when doing a rescan
> with parameter changes, so we already have this issue.  IMO I think we
> should avoid writing a query like this.

Hmm.  In principle, since postgres_fdw controls all the SQL sent to
the remote side, we could avoid building problematic queries.  But
I'm not sure how to make that work in practice, or how we'd avoid
somebody carelessly breaking it in future.  It seems like the
property you propose requiring is a second-order effect that would
be hard to ensure.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Etsuro Fujita
Date:
Subject: Re: BUG #17889: Invalid cursor direction for a foreign scan that reached the fetch_size (MOVE BACKWARD ALL IN cX)
Next
From: Michael Paquier
Date:
Subject: Re: BUG #18540: Does PG16 standby database support function pg_replication_origin_advance?