pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Recreate read stream across rescans
4+ messages / 1 participants
[nested] [flat]

* pgsql: Recreate read stream across rescans
@ 2026-11-18 22:34 Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Melanie Plageman @ 2026-11-18 22:34 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Recreate read stream across rescans

Heap scan descriptors persist across rescans, but initscan() can add or
remove the buffer access strategy when the relation size or caller flags
change.

The ReadStream stored the strategy pointer and sized its queue capacity
based on the strategy at ReadStream creation, which was only before the
first scan. This meant that on rescan, enabling a bulk-read strategy
left the existing stream using its NULL strategy and old capacity.
And disabling the strategy left the stream pointing to freed memory.

Reset and reuse the stream when strategy use is unchanged. Otherwise,
end it before changing the strategy and create a correctly sized
replacement.

Reported-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reported-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com> (earlier version)
Reviewed-by: Joao Rito <joaovictor.rito@gmail.com> (earlier version)
Discussion: https://postgr.es/m/aumB7BHGWewR4x%2FS%40bdtpg
Discussion: https://postgr.es/m/CAN55FZ3Lik2m9J%2BEQjzEHSMSBNgAXU5Myt8LFg%3DD2OQ0i_jUMQ%40mail.gmail.com
Backpatch-through: 17

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/556c025db96500168ed865e26dcfcc3a0b68dbb9

Modified Files
--------------
src/backend/access/heap/heapam.c                   | 155 +++++++++++----------
src/backend/storage/aio/read_stream.c              |   4 +-
src/include/access/heapam.h                        |  11 +-
src/test/modules/test_misc/meson.build             |   1 +
.../modules/test_misc/t/016_heap_scan_stream.pl    |  62 +++++++++
5 files changed, 156 insertions(+), 77 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Recreate read stream across rescans
@ 2026-11-18 22:36 Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Melanie Plageman @ 2026-11-18 22:36 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Recreate read stream across rescans

Heap scan descriptors persist across rescans, but initscan() can add or
remove the buffer access strategy when the relation size or caller flags
change.

The ReadStream stored the strategy pointer and sized its queue capacity
based on the strategy at ReadStream creation, which was only before the
first scan. This meant that on rescan, enabling a bulk-read strategy
left the existing stream using its NULL strategy and old capacity.
And disabling the strategy left the stream pointing to freed memory.

Reset and reuse the stream when strategy use is unchanged. Otherwise,
end it before changing the strategy and create a correctly sized
replacement.

Reported-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reported-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com> (earlier version)
Reviewed-by: Joao Rito <joaovictor.rito@gmail.com> (earlier version)
Discussion: https://postgr.es/m/aumB7BHGWewR4x%2FS%40bdtpg
Discussion: https://postgr.es/m/CAN55FZ3Lik2m9J%2BEQjzEHSMSBNgAXU5Myt8LFg%3DD2OQ0i_jUMQ%40mail.gmail.com
Backpatch-through: 17

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e645b48a6921a6293e1b451f2f234cd6aea51be1

Modified Files
--------------
src/backend/access/heap/heapam.c                   | 155 +++++++++++----------
src/backend/storage/aio/read_stream.c              |   4 +-
src/include/access/heapam.h                        |  11 +-
src/test/modules/test_misc/meson.build             |   1 +
.../modules/test_misc/t/016_heap_scan_stream.pl    |  62 +++++++++
5 files changed, 156 insertions(+), 77 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Recreate read stream across rescans
@ 2026-11-18 22:39 Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Melanie Plageman @ 2026-11-18 22:39 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Recreate read stream across rescans

Heap scan descriptors persist across rescans, but initscan() can add or
remove the buffer access strategy when the relation size or caller flags
change.

The ReadStream stored the strategy pointer and sized its queue capacity
based on the strategy at ReadStream creation, which was only before the
first scan. This meant that on rescan, enabling a bulk-read strategy
left the existing stream using its NULL strategy and old capacity.
And disabling the strategy left the stream pointing to freed memory.

Reset and reuse the stream when strategy use is unchanged. Otherwise,
end it before changing the strategy and create a correctly sized
replacement.

Reported-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reported-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com> (earlier version)
Reviewed-by: Joao Rito <joaovictor.rito@gmail.com> (earlier version)
Discussion: https://postgr.es/m/aumB7BHGWewR4x%2FS%40bdtpg
Discussion: https://postgr.es/m/CAN55FZ3Lik2m9J%2BEQjzEHSMSBNgAXU5Myt8LFg%3DD2OQ0i_jUMQ%40mail.gmail.com
Backpatch-through: 17

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9107706245e2368b9e3519629761b70cb93993e7

Modified Files
--------------
src/backend/access/heap/heapam.c                   | 140 +++++++++++----------
src/include/access/heapam.h                        |  11 +-
src/test/modules/test_misc/meson.build             |   1 +
.../modules/test_misc/t/016_heap_scan_stream.pl    |  62 +++++++++
4 files changed, 146 insertions(+), 68 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Recreate read stream across rescans
@ 2026-11-18 22:43 Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Melanie Plageman @ 2026-11-18 22:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Recreate read stream across rescans

Heap scan descriptors persist across rescans, but initscan() can add or
remove the buffer access strategy when the relation size or caller flags
change.

The ReadStream stored the strategy pointer and sized its queue capacity
based on the strategy at ReadStream creation, which was only before the
first scan. This meant that on rescan, enabling a bulk-read strategy
left the existing stream using its NULL strategy and old capacity.
And disabling the strategy left the stream pointing to freed memory.

Reset and reuse the stream when strategy use is unchanged. Otherwise,
end it before changing the strategy and create a correctly sized
replacement.

Reported-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reported-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com> (earlier version)
Reviewed-by: Joao Rito <joaovictor.rito@gmail.com> (earlier version)
Discussion: https://postgr.es/m/aumB7BHGWewR4x%2FS%40bdtpg
Discussion: https://postgr.es/m/CAN55FZ3Lik2m9J%2BEQjzEHSMSBNgAXU5Myt8LFg%3DD2OQ0i_jUMQ%40mail.gmail.com
Backpatch-through: 17

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6c8717359a4bba3011d112c094c643372656319f

Modified Files
--------------
src/backend/access/heap/heapam.c                   | 100 ++++++++++++---------
src/include/access/heapam.h                        |  11 +--
src/test/modules/test_misc/meson.build             |   1 +
.../modules/test_misc/t/016_heap_scan_stream.pl    |  66 ++++++++++++++
4 files changed, 129 insertions(+), 49 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2026-11-18 22:43 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 22:34 pgsql: Recreate read stream across rescans Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 22:36 pgsql: Recreate read stream across rescans Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 22:39 pgsql: Recreate read stream across rescans Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 22:43 pgsql: Recreate read stream across rescans Melanie Plageman <melanieplageman@gmail.com>

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