Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTRsk-00GNLr-Bv for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Jul 2024 20:01:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sTRsj-00Czd6-0z for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Jul 2024 20:01:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTRsi-00Czcy-Oo for pgsql-bugs@lists.postgresql.org; Mon, 15 Jul 2024 20:01:08 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTRsf-002I3o-6F for pgsql-bugs@lists.postgresql.org; Mon, 15 Jul 2024 20:01:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 46FK12OD3195561; Mon, 15 Jul 2024 16:01:02 -0400 From: Tom Lane To: Etsuro Fujita cc: eric.cyr@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17889: Invalid cursor direction for a foreign scan that reached the fetch_size (MOVE BACKWARD ALL IN cX) In-reply-to: References: <17889-e8c39a251d258dda@postgresql.org> <1852635.1682808624@sss.pgh.pa.us> <3147482.1721051728@sss.pgh.pa.us> Comments: In-reply-to Etsuro Fujita message dated "Tue, 16 Jul 2024 04:45:48 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3195559.1721073662.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 15 Jul 2024 16:01:02 -0400 Message-ID: <3195560.1721073662@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Etsuro Fujita writes: > On Mon, Jul 15, 2024 at 10:55 PM Tom Lane 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