Skip to content

Commit e8d74ad

Browse files
committed
Report syncscan position at end of scan.
The comment in heapgettup_advance_block() says that it reports the scan position before checking for end of scan, but that didn't match the code. The code was refactored in commit 7ae0ab0, which inadvertently changed the order of the check and reporting. Change it back. This caused a few regression test failures with a small shared_buffers setting like 10 MB. The 'portals' and 'cluster' tests perform seqscans that are large enough that sync seqscans kick in. When the sync scan position is not updated at end of scan, the next seq scan doesn't start at the beginning of the table, and the test queries are sensitive to that. Reviewed-by: Melanie Plageman, David Rowley Discussion: https://www.postgresql.org/message-id/6f991389-ae22-d844-a9d8-9aceb7c01a9a@iki.fi Backpatch-through: 16
1 parent d7ceb41 commit e8d74ad

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/backend/access/heap/heapam.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,6 @@ heapgettup_advance_block(HeapScanDesc scan, BlockNumber block, ScanDirection dir
647647
if (block >= scan->rs_nblocks)
648648
block = 0;
649649

650-
/* we're done if we're back at where we started */
651-
if (block == scan->rs_startblock)
652-
return InvalidBlockNumber;
653-
654-
/* check if the limit imposed by heap_setscanlimits() is met */
655-
if (scan->rs_numblocks != InvalidBlockNumber)
656-
{
657-
if (--scan->rs_numblocks == 0)
658-
return InvalidBlockNumber;
659-
}
660-
661650
/*
662651
* Report our new scan position for synchronization purposes. We
663652
* don't do that when moving backwards, however. That would just
@@ -673,6 +662,17 @@ heapgettup_advance_block(HeapScanDesc scan, BlockNumber block, ScanDirection dir
673662
if (scan->rs_base.rs_flags & SO_ALLOW_SYNC)
674663
ss_report_location(scan->rs_base.rs_rd, block);
675664

665+
/* we're done if we're back at where we started */
666+
if (block == scan->rs_startblock)
667+
return InvalidBlockNumber;
668+
669+
/* check if the limit imposed by heap_setscanlimits() is met */
670+
if (scan->rs_numblocks != InvalidBlockNumber)
671+
{
672+
if (--scan->rs_numblocks == 0)
673+
return InvalidBlockNumber;
674+
}
675+
676676
return block;
677677
}
678678
else

0 commit comments

Comments
 (0)