From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: Melanie Plageman <melanieplageman@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>
Subject: Re: Fix ReadStream handling when heap rescan strategy changes
Date: Wed, 18 Nov 2026 07:47:15 +0000
Message-ID: <av1YA7ceBPlflU7Q@bdtpg> (raw)
In-Reply-To: <CAAKRu_Z-A9EpQ-ommkp0e+Wg7j99Ct7T=sG1D_4zOEyxjcx3Hg@mail.gmail.com>
References: <aumB7BHGWewR4x/S@bdtpg>
<CAAKRu_Z-A9EpQ-ommkp0e+Wg7j99Ct7T=sG1D_4zOEyxjcx3Hg@mail.gmail.com>
Hi,
On Tue, Nov 17, 2026 at 04:54:08PM -0500, Melanie Plageman wrote:
> On Tue, Nov 3, 2026 at 1:40 AM Bertrand Drouvot
> <bertranddrouvot.pg@gmail.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.
Thanks for looking at it!
Yeah, that makes sense to me. Having initscan() own the reset/end, strategy update,
and stream creation makes the ordering clearer (and also avoids the possible double
reset).
I've one Nit, if we want this comment to describe the complete stream lifecycle,
in heapam.h:
"
stream is allocated at the beginning of the scan and reset on rescan or
when the scan direction changes.
"
worth to change it to something like?
"
The read stream is allocated at the beginning of the scan. It is reset when
the scan direction changes. On rescan, it is reset if strategy use remains
unchanged, and recreated otherwise.
"
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: bertranddrouvot.pg@gmail.com, melanieplageman@gmail.com, thomas.munro@gmail.com
Subject: Re: Fix ReadStream handling when heap rescan strategy changes
In-Reply-To: <av1YA7ceBPlflU7Q@bdtpg>
References: <aumB7BHGWewR4x/S@bdtpg> <CAAKRu_Z-A9EpQ-ommkp0e+Wg7j99Ct7T=sG1D_4zOEyxjcx3Hg@mail.gmail.com> <av1YA7ceBPlflU7Q@bdtpg>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox