Fix ReadStream handling when heap rescan strategy changes

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Melanie Plageman <melanieplageman(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Subject: Fix ReadStream handling when heap rescan strategy changes
Date: 2026-11-03 06:40:44
Message-ID: aumB7BHGWewR4x/S@bdtpg
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

While working on [1], I noticed that a heap rescan can change whether a buffer
access strategy is used while retaining the existing ReadStream. If the strategy
is disabled, the stream keeps a dangling pointer after it is freed. If it is
enabled, the stream continues using its NULL strategy and the queue capacity
selected at creation.

The issue was introduced by b7b0f3f27241. Nazir pointed it out and Yuhang
proposed fixing it with a new read_stream_set_strategy() API in [2]. Since the
issue is independent of the streaming SampleScan changes, I wonder if it wouldn't
make sense to fix it separately, as in the attached?

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.

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.

[1]: https://postgr.es/m/auCYYbDyrQEwIsQq%40bdtpg
[2]: https://postgr.es/m/CAN55FZ3Lik2m9J%2BEQjzEHSMSBNgAXU5Myt8LFg%3DD2OQ0i_jUMQ%40mail.gmail.com

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v1-0001-Fix-ReadStream-handling-when-heap-rescan-strategy.patch text/x-diff 6.6 KB
v1-0002-Test-heap-rescan-strategy-changes.patch text/x-diff 3.1 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Chao Li 2026-11-03 06:26:33 Reject empty rounds values in pgcrypto's SHA-crypt salts