Skip to content

Commit

Permalink
Improve comment about pins & locks on step to the left.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrittn committed Mar 13, 2015
1 parent 76118b5 commit 22066fc
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/backend/access/nbtree/nbtsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,19 +1383,26 @@ _bt_steppage(IndexScanDesc scan, ScanDirection dir)
/* Remember we left a page with data */
so->currPos.moreRight = true;

/* XXX: Can walking left be lighter on the locking and pins? */
if (BTScanPosIsPinned(so->currPos))
LockBuffer(so->currPos.buf, BT_READ);
else
so->currPos.buf = _bt_getbuf(rel, so->currPos.currPage, BT_READ);

/*
* Walk left to the next page with data. This is much more complex
* than the walk-right case because of the possibility that the page
* to our left splits while we are in flight to it, plus the
* possibility that the page we were on gets deleted after we leave
* it. See nbtree/README for details.
*
* It might be possible to rearrange this code to have less overhead
* in pinning and locking, but that would require capturing the left
* pointer when the page is initially read, and using it here, along
* with big changes to _bt_walk_left() and the code below. It is not
* clear whether this would be a win, since if the page immediately to
* the left splits after we read this page and before we step left, we
* would need to visit more pages than with the current code.
*/
if (BTScanPosIsPinned(so->currPos))
LockBuffer(so->currPos.buf, BT_READ);
else
so->currPos.buf = _bt_getbuf(rel, so->currPos.currPage, BT_READ);

for (;;)
{
/* Done if we know there are no matching keys to the left */
Expand Down

0 comments on commit 22066fc

Please sign in to comment.