Fix incorrect block accounting in TID Range Scans

heapgettup_advance_block() (or heapgettup() and heapgettup_pagemode() in
versions before v16) would incorrectly decrement rs_numblocks when
advancing to the next block.  Ordinarily this was fine, but if the TID
Range scan plan was used by a scrollable cursor and the cursor was fetched
backwards enough to result in another block being required, then
rs_numblocks may have reached 0 prematurely resulting in the scan ending
prematurely.

Reported-by: Jeff Davis <[email protected]>
Author: Ewan Young <[email protected]>
Author: David Rowley <[email protected]>
Discussion: 
https://postgr.es/m/[email protected]
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/374522aa63af1187c15dd21db0b2c988b55c9a3a

Modified Files
--------------
src/backend/access/heap/heapam.c           | 20 +++++++++++---------
src/test/regress/expected/tidrangescan.out | 26 ++++++++++++++++++++++++++
src/test/regress/sql/tidrangescan.sql      | 12 ++++++++++++
3 files changed, 49 insertions(+), 9 deletions(-)

Reply via email to