1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Have read_stream_reset reset pending_read_nblocks.

Otherwise, a read of blocks the stream is about to throw away can be
started and then waited for.  read_stream_reset drains the stream by
calling read_stream_next_buffer, whose look-ahead treats the zeroed
distance as end of stream, leading to it spuriously performing the
pending read.  This caused a pathological regression for a nested loop
antijoin query when run with the upcoming index prefetching patch series
applied.

This bug affects all stable branches with the read stream, which was
added to Postgres 17 by commit b5a9b18cd0.  No backpatch for now,
though, since without index prefetching the added overhead for realistic
query plans is negligible.

Author: Tomas Vondra <tomas@vondra.me>
Discussion: https://postgr.es/m/CAH2-WzkKY8b42sZSPWJceT5Fn_THk3ZgcaM8ch3Hzw+XvhP0zQ@mail.gmail.com
This commit is contained in:
Peter Geoghegan
2026-09-15 14:36:47 -04:00
parent 78142821df
commit 862092932c

View File

@@ -1444,6 +1444,9 @@ read_stream_reset(ReadStream *stream)
stream->readahead_distance = 0;
stream->combine_distance = 0;
/* Forget pending reads. */
stream->pending_read_nblocks = 0;
/* Forget buffered block number and fast path state. */
stream->buffered_blocknum = InvalidBlockNumber;
stream->fast_path = false;