]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix hypothetical bug in heap backward scans
authorDavid Rowley <drowley@postgresql.org>
Mon, 25 Jan 2021 07:01:00 +0000 (20:01 +1300)
committerDavid Rowley <drowley@postgresql.org>
Mon, 25 Jan 2021 07:01:00 +0000 (20:01 +1300)
commit317de9c45d88dd67718b4e411e2918ffbc96f5ae
treec1b14b9bf4d895d9b0cc8ef9a649abfadd22a182
parent7e078675168befe07b40b472a315de5423c2600a
Fix hypothetical bug in heap backward scans

Both heapgettup() and heapgettup_pagemode() incorrectly set the first page
to scan in a backward scan in which the number of pages to scan was
specified by heap_setscanlimits().  The code incorrectly started the scan
at the end of the relation when startBlk was 0, or otherwise at
startBlk - 1, neither of which is correct when only scanning a subset of
pages.

The fix here checks if heap_setscanlimits() has changed the number of
pages to scan and if so we set the first page to scan as the final page in
the specified range during backward scans.

Proper adjustment of this code was forgotten when heap_setscanlimits() was
added in 7516f5259 back in 9.5.  However, practice, nowhere in core code
performs backward scans after having used heap_setscanlimits(), yet, it is
possible an extension uses the heap functions in this way, hence
backpatch.

An upcoming patch does use heap_setscanlimits() with backward scans, so
this must be fixed before that can go in.

Author: David Rowley
Discussion: https://postgr.es/m/CAApHDvpGc9h0_oVD2CtgBcxCS1N-qDYZSeBRnUh+0CWJA9cMaA@mail.gmail.com
Backpatch-through: 9.5, all supported versions
src/backend/access/heap/heapam.c