nbtree: Minor sibling link traversal tweaks.

Tweak some code comments for clarity, and relocate some local variable
declarations to the scope where they're actually used.

Follow-up to recent commit 1bd4bc85.
This commit is contained in:
Peter Geoghegan 2024-10-28 12:22:52 -04:00
parent de5afddc3b
commit 123474cbce

View File

@ -1580,7 +1580,7 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum,
so->currPos.currPage); so->currPos.currPage);
} }
/* initialize remaining currPos fields (before moreLeft/moreright) */ /* initialize remaining currPos fields (before moreLeft/moreRight) */
so->currPos.lsn = BufferGetLSNAtomic(so->currPos.buf); so->currPos.lsn = BufferGetLSNAtomic(so->currPos.buf);
so->currPos.dir = dir; so->currPos.dir = dir;
so->currPos.nextTupleOffset = 0; so->currPos.nextTupleOffset = 0;
@ -2154,7 +2154,7 @@ _bt_readfirstpage(IndexScanDesc scan, OffsetNumber offnum, ScanDirection dir)
so->numKilled = 0; /* just paranoia */ so->numKilled = 0; /* just paranoia */
so->markItemIndex = -1; /* ditto */ so->markItemIndex = -1; /* ditto */
/* Initialize currPos for so->currPos */ /* Initialize so->currPos for the first page (page in so->currPos.buf) */
if (so->needPrimScan) if (so->needPrimScan)
{ {
Assert(so->numArrayKeys); Assert(so->numArrayKeys);
@ -2175,7 +2175,7 @@ _bt_readfirstpage(IndexScanDesc scan, OffsetNumber offnum, ScanDirection dir)
} }
/* /*
* Attempt to load matching tuples from the page in so->currPos.buf. * Attempt to load matching tuples from the first page.
* *
* Note that _bt_readpage will finish initializing the so->currPos fields. * Note that _bt_readpage will finish initializing the so->currPos fields.
* _bt_readpage also releases parallel scan (even when it returns false). * _bt_readpage also releases parallel scan (even when it returns false).
@ -2208,8 +2208,7 @@ _bt_readfirstpage(IndexScanDesc scan, OffsetNumber offnum, ScanDirection dir)
* Caller's blkno is the next interesting page's link, taken from either the * Caller's blkno is the next interesting page's link, taken from either the
* previously-saved right link or left link. lastcurrblkno is the page that * previously-saved right link or left link. lastcurrblkno is the page that
* was current at the point where the blkno link was saved, which we use to * was current at the point where the blkno link was saved, which we use to
* reason about concurrent page splits/page deletions during backwards scans * reason about concurrent page splits/page deletions during backwards scans.
* (_bt_parallel_seize also requires it, regardless of scan direction).
* *
* On entry, caller shouldn't hold any locks or pins on any page (we work * On entry, caller shouldn't hold any locks or pins on any page (we work
* directly off of blkno and lastcurrblkno instead). Parallel scan callers * directly off of blkno and lastcurrblkno instead). Parallel scan callers
@ -2234,8 +2233,6 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno,
{ {
Relation rel = scan->indexRelation; Relation rel = scan->indexRelation;
BTScanOpaque so = (BTScanOpaque) scan->opaque; BTScanOpaque so = (BTScanOpaque) scan->opaque;
Page page;
BTPageOpaque opaque;
Assert(so->currPos.currPage == lastcurrblkno || scan->parallel_scan != NULL); Assert(so->currPos.currPage == lastcurrblkno || scan->parallel_scan != NULL);
Assert(!BTScanPosIsPinned(so->currPos)); Assert(!BTScanPosIsPinned(so->currPos));
@ -2251,14 +2248,14 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno,
for (;;) for (;;)
{ {
/* Page page;
* if we're at end of scan, give up and mark parallel scan as done, so BTPageOpaque opaque;
* that all the workers can finish their scan
*/
if (blkno == P_NONE || if (blkno == P_NONE ||
(ScanDirectionIsForward(dir) ? (ScanDirectionIsForward(dir) ?
!so->currPos.moreRight : !so->currPos.moreLeft)) !so->currPos.moreRight : !so->currPos.moreLeft))
{ {
/* most recent _bt_readpage call (for lastcurrblkno) ended scan */
_bt_parallel_done(scan); _bt_parallel_done(scan);
BTScanPosInvalidate(so->currPos); BTScanPosInvalidate(so->currPos);
return false; return false;