Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c45a1db

Browse files
nbtree: _bt_readnextpage doesn't affect markPos.
_bt_readnextpage expects so->currPos.buf to be InvalidBuffer (and for the position's page to be unlocked) when called. However, it does not expect there to be no pins held on any page. In particular, so->markPos might hold a separate pin, both before and after the call. Fix some comments that seemed to suggest otherwise. Follow-up commit to commit 7c319f5, which made _bt_killitems drop pins it acquired itself.
1 parent a0c7b76 commit c45a1db

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/backend/access/nbtree/nbtsearch.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,9 +2282,12 @@ _bt_readfirstpage(IndexScanDesc scan, OffsetNumber offnum, ScanDirection dir)
22822282
* previously-saved right link or left link. lastcurrblkno is the page that
22832283
* was current at the point where the blkno link was saved, which we use to
22842284
* reason about concurrent page splits/page deletions during backwards scans.
2285+
* In the common case where seized=false, blkno is either so->currPos.nextPage
2286+
* or so->currPos.prevPage, and lastcurrblkno is so->currPos.currPage.
22852287
*
2286-
* On entry, caller shouldn't hold any locks or pins on any page (we work
2287-
* directly off of blkno and lastcurrblkno instead). Parallel scan callers
2288+
* On entry, so->currPos shouldn't be locked by caller. so->currPos.buf must
2289+
* be InvalidBuffer/unpinned as needed by caller (note that lastcurrblkno
2290+
* won't need to be read again in almost all cases). Parallel scan callers
22882291
* that seized the scan before calling here should pass seized=true; such a
22892292
* caller's blkno and lastcurrblkno arguments come from the seized scan.
22902293
* seized=false callers just pass us the blkno/lastcurrblkno taken from their
@@ -2301,8 +2304,8 @@ _bt_readfirstpage(IndexScanDesc scan, OffsetNumber offnum, ScanDirection dir)
23012304
* success exit (except during so->dropPin index scans, when we drop the pin
23022305
* eagerly to avoid blocking VACUUM).
23032306
*
2304-
* If there are no more matching records in the given direction, we drop all
2305-
* locks and pins, invalidate so->currPos, and return false.
2307+
* If there are no more matching records in the given direction, we invalidate
2308+
* so->currPos (while ensuring it retains no locks or pins), and return false.
23062309
*
23072310
* We always release the scan for a parallel scan caller, regardless of
23082311
* success or failure; we'll call _bt_parallel_release as soon as possible.

0 commit comments

Comments
 (0)