Re: Fix ReadStream handling when heap rescan strategy changes

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Subject: Re: Fix ReadStream handling when heap rescan strategy changes
Date: 2026-11-17 21:54:08
Message-ID: CAAKRu_Z-A9EpQ-ommkp0e+Wg7j99Ct7T=sG1D_4zOEyxjcx3Hg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 3, 2026 at 1:40 AM Bertrand Drouvot
<bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
>
> 0001 takes a different approach (than [2]) and recreates the ReadStream when
> initscan() changes whether a strategy is active. Ordinary rescans continue to
> reset and reuse the existing stream. It uses the existing ReadStream APIs, which
> could also make the backpatches easier.

Now that initscan() has to concern itself with the read stream because
it has to reset or end the stream before changing the strategy, then
change the strategy, and then make the new read stream, I think the
separation between initscan() and making the read stream is no longer
useful. In fact, the ping-ponging has become confusing. I think your
version might actually have read_stream_reset() getting called twice
in some cases since read_stream_end() also calls it. Attached v2 just
moves all the read stream setup into initscan() and adds some flags to
make it more clear when we want to rebuild the stream/strategy.

> 0002 contains a test. I'm not sure it is worth adding to the tree given the amount
> of setup, but it demonstrates the issue.

I agree that zero test coverage of this is not good. I really would
have liked to find somewhere to put the test that wasn't a new TAP
test file that makes yet another new cluster. Alas, neither I nor my
LLM could come up with a good place. I did however, change the test to
use a cursor instead of a query that does a rescan. That takes away
the need for the plpgsql function and makes the test simpler IMO.
pg_stat_get_backend_io() doesn't exist in 17, so we'll have to modify
the test to backpatch there.

- Melanie

Attachment Content-Type Size
v2-0001-Recreate-read-stream-across-rescans.patch text/x-patch 10.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-11-17 22:08:26 Re: [***DKIM violation***] Re: [PATCH] Fix heap-buffer-overflow in PGTYPEStimestamp_defmt_scan()
Previous Message Zsolt Parragi 2026-11-17 21:54:00 Re: FATAL: could not send end-of-streaming message to primary: no COPY in progress