On 2/17/26 19:17, Peter Geoghegan wrote: > On Mon, Feb 16, 2026 at 10:44 AM Tomas Vondra <[email protected]> wrote: >> I've described this exact behavior a couple months ago in this very >> thread. The queue of batches has limited size, the prefetch needs to be >> paused - at that point read_stream_pause did not exist, so it was done >> by terminating the stream and then read_stream_reset to "resume" it. >> >> That has the unfortunate effect that it resets distance to 1, and so it >> easily led exactly to the issue you describe. But without the pausing it >> would work perfectly fine, in many cases. > > Just to be clear: it *used* to work that way, back when we weren't > using Thomas Munro's built-in pausing mechanism. Because we'd actually > reset the read stream back then, as a workaround for the lack of any > built-in pausing mechanism. But we don't do that anymore; recent > versions only reset in cases where it's strictly necessary, such as on > a rescan, or when the scan direction changes. > > Recent versions of the patch are just about impossible to make pause. > Because (for better or worse) we'll yield before ever running out of > batch slots/before ever pausing. Andres has shown that this can be > detrimental to our ability to maintain an adequate prefetch distance. > But that's likely only because pausing hurts when it prevents us from > aggressively ramping up prefetch distance at the start of the scan. > > Even without yielding, pausing is rare and likely doesn't hurt us > much. After all, 64 batches is usually plenty. > >> With the resetting, this effect is pretty brutal. > > What resetting? We don't do that anymore? And even back when the patch > did things that way, we made sure to save the old prefetch distance > (which was a kludge upon a kludge)? > > Basically I'm confused about why you're now talking about how the > patch worked months ago, which was always a temporary workaround to > deal with the lack of a built-in pausing mechanism. All of our current > problems are due to yielding (not pausing), and/or issues on the read > stream side. >
Yes, the patch no longer resets the stream like this. I was responding to Andres, explaining that we saw basically the same issue, with the twist that the impact strongly depends on the distance value at the moment we hit the particular hit/miss pattern. We no longer have that issue (with the "read_stream_reset" forcing the distance collapse). We still have the issue with decaying too early in some cases, depending on the exact pattern of hits/misses. Sorry if that wasn't clear. -- Tomas Vondra
