Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 06b10f8

Browse files
committed
Remove BTScanOpaqueData.firstPage
It's not necessary to keep the firstPage flag as a field of BTScanOpaqueData. This commit makes it an argument of the _bt_readpage() function. We can easily distinguish first-time and repeated calls (within the scan) of this function. Reported-by: Peter Geoghegan Discussion: https://postgr.es/m/CAH2-Wzk4SOsw%2BtHuTFiz8U9Jqj-R77rYPkhWKODCBb1mdHACXA%40mail.gmail.com Reviewed-by: Pavel Borisov
1 parent 3e527ae commit 06b10f8

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

src/backend/access/nbtree/nbtree.c

-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ btrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
409409

410410
so->markItemIndex = -1;
411411
so->arrayKeyCount = 0;
412-
so->firstPage = false;
413412
BTScanPosUnpinIfPinned(so->markPos);
414413
BTScanPosInvalidate(so->markPos);
415414

src/backend/access/nbtree/nbtsearch.c

+8-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static OffsetNumber _bt_binsrch(Relation rel, BTScanInsert key, Buffer buf);
3030
static int _bt_binsrch_posting(BTScanInsert key, Page page,
3131
OffsetNumber offnum);
3232
static bool _bt_readpage(IndexScanDesc scan, ScanDirection dir,
33-
OffsetNumber offnum);
33+
OffsetNumber offnum, bool firstPage);
3434
static void _bt_saveitem(BTScanOpaque so, int itemIndex,
3535
OffsetNumber offnum, IndexTuple itup);
3636
static int _bt_setuppostingitems(BTScanOpaque so, int itemIndex,
@@ -1395,7 +1395,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
13951395
offnum = _bt_binsrch(rel, &inskey, buf);
13961396
Assert(!BTScanPosIsValid(so->currPos));
13971397
so->currPos.buf = buf;
1398-
so->firstPage = true;
13991398

14001399
/*
14011400
* Now load data from the first page of the scan.
@@ -1416,7 +1415,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
14161415
* for the page. For example, when inskey is both < the leaf page's high
14171416
* key and > all of its non-pivot tuples, offnum will be "maxoff + 1".
14181417
*/
1419-
if (!_bt_readpage(scan, dir, offnum))
1418+
if (!_bt_readpage(scan, dir, offnum, true))
14201419
{
14211420
/*
14221421
* There's no actually-matching data on this page. Try to advance to
@@ -1520,7 +1519,8 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
15201519
* Returns true if any matching items found on the page, false if none.
15211520
*/
15221521
static bool
1523-
_bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum)
1522+
_bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum,
1523+
bool firstPage)
15241524
{
15251525
BTScanOpaque so = (BTScanOpaque) scan->opaque;
15261526
Page page;
@@ -1601,7 +1601,7 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum)
16011601
* We skip this for the first page in the scan to evade the possible
16021602
* slowdown of the point queries.
16031603
*/
1604-
if (!so->firstPage && minoff < maxoff)
1604+
if (!firstPage && minoff < maxoff)
16051605
{
16061606
ItemId iid;
16071607
IndexTuple itup;
@@ -1620,7 +1620,6 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum)
16201620
}
16211621
else
16221622
{
1623-
so->firstPage = false;
16241623
requiredMatchedByPrecheck = false;
16251624
}
16261625

@@ -2079,7 +2078,7 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno, ScanDirection dir)
20792078
PredicateLockPage(rel, blkno, scan->xs_snapshot);
20802079
/* see if there are any matches on this page */
20812080
/* note that this will clear moreRight if we can stop */
2082-
if (_bt_readpage(scan, dir, P_FIRSTDATAKEY(opaque)))
2081+
if (_bt_readpage(scan, dir, P_FIRSTDATAKEY(opaque), false))
20832082
break;
20842083
}
20852084
else if (scan->parallel_scan != NULL)
@@ -2170,7 +2169,7 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno, ScanDirection dir)
21702169
PredicateLockPage(rel, BufferGetBlockNumber(so->currPos.buf), scan->xs_snapshot);
21712170
/* see if there are any matches on this page */
21722171
/* note that this will clear moreLeft if we can stop */
2173-
if (_bt_readpage(scan, dir, PageGetMaxOffsetNumber(page)))
2172+
if (_bt_readpage(scan, dir, PageGetMaxOffsetNumber(page), false))
21742173
break;
21752174
}
21762175
else if (scan->parallel_scan != NULL)
@@ -2487,14 +2486,13 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
24872486

24882487
/* remember which buffer we have pinned */
24892488
so->currPos.buf = buf;
2490-
so->firstPage = true;
24912489

24922490
_bt_initialize_more_data(so, dir);
24932491

24942492
/*
24952493
* Now load data from the first page of the scan.
24962494
*/
2497-
if (!_bt_readpage(scan, dir, start))
2495+
if (!_bt_readpage(scan, dir, start, false))
24982496
{
24992497
/*
25002498
* There's no actually-matching data on this page. Try to advance to

src/include/access/nbtree.h

-3
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,6 @@ typedef struct BTScanOpaqueData
10511051
int *killedItems; /* currPos.items indexes of killed items */
10521052
int numKilled; /* number of currently stored items */
10531053

1054-
/* flag indicating the first page in the scan */
1055-
bool firstPage;
1056-
10571054
/*
10581055
* If we are doing an index-only scan, these are the tuple storage
10591056
* workspaces for the currPos and markPos respectively. Each is of size

0 commit comments

Comments
 (0)