diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index aee89801dbf..af2d20f9373 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -1245,9 +1245,9 @@ lazy_scan_heap(LVRelState *vacrel, VacuumParams *params, bool aggressive) if (next_prefetch_block + prefetch_budget > blkno + vacrel->io_concurrency) prefetch_budget = blkno + vacrel->io_concurrency - next_prefetch_block; - /* And only up to the next unskippable block */ - if (next_prefetch_block + prefetch_budget > next_unskippable_block) - prefetch_budget = next_unskippable_block - next_prefetch_block; + /* Do not perform prefetch if we are skipping current range */ + if (skipping_blocks) + prefetch_budget = 0; for (; prefetch_budget-- > 0; next_prefetch_block++) PrefetchBuffer(vacrel->rel, MAIN_FORKNUM, next_prefetch_block);