Re: possible issue in postgres_fdw batching - Mailing list pgsql-hackers

From Tom Lane
Subject Re: possible issue in postgres_fdw batching
Date
Msg-id 1229236.1724024459@sss.pgh.pa.us
Whole thread Raw
In response to possible issue in postgres_fdw batching  (Tomas Vondra <tomas@vondra.me>)
Responses Re: possible issue in postgres_fdw batching
List pgsql-hackers
Tomas Vondra <tomas@vondra.me> writes:
> Consider this simplified example:

>   CREATE TABLE t (a INT);
>   CREATE FOREIGN TABLE f (a INT) SERVER loopback
>                                  OPTIONS (table_name 't');
>   CREATE FUNCTION counter() RETURNS int LANGUAGE sql AS
>   $$ SELECT COUNT(*) FROM f $$;

> And now do

>   INSERT INTO f SELECT counter() FROM generate_series(1,100);

> With batch_size=1 this produces a nice sequence, with batching we start
> to get duplicate values - which is not surprising, as the function is
> oblivious to the data still in the buffer.

> The first question is if this is a bug.

I'd say no; this query is unduly chummy with implementation details.
Even with no foreign table in the picture at all, we would be fully
within our rights to execute the SELECT to completion before any
of the insertions became visible.  (Arguably, it's the current
behavior that is surprising, not that one.)

            regards, tom lane



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: possible issue in postgres_fdw batching
Next
From: Thomas Munro
Date:
Subject: Re: Cirrus CI for macOS branches 16 and 15 broken