@@ -30,7 +30,7 @@ static OffsetNumber _bt_binsrch(Relation rel, BTScanInsert key, Buffer buf);
30
30
static int _bt_binsrch_posting (BTScanInsert key , Page page ,
31
31
OffsetNumber offnum );
32
32
static bool _bt_readpage (IndexScanDesc scan , ScanDirection dir ,
33
- OffsetNumber offnum );
33
+ OffsetNumber offnum , bool firstPage );
34
34
static void _bt_saveitem (BTScanOpaque so , int itemIndex ,
35
35
OffsetNumber offnum , IndexTuple itup );
36
36
static int _bt_setuppostingitems (BTScanOpaque so , int itemIndex ,
@@ -1395,7 +1395,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
1395
1395
offnum = _bt_binsrch (rel , & inskey , buf );
1396
1396
Assert (!BTScanPosIsValid (so -> currPos ));
1397
1397
so -> currPos .buf = buf ;
1398
- so -> firstPage = true;
1399
1398
1400
1399
/*
1401
1400
* Now load data from the first page of the scan.
@@ -1416,7 +1415,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
1416
1415
* for the page. For example, when inskey is both < the leaf page's high
1417
1416
* key and > all of its non-pivot tuples, offnum will be "maxoff + 1".
1418
1417
*/
1419
- if (!_bt_readpage (scan , dir , offnum ))
1418
+ if (!_bt_readpage (scan , dir , offnum , true ))
1420
1419
{
1421
1420
/*
1422
1421
* There's no actually-matching data on this page. Try to advance to
@@ -1520,7 +1519,8 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
1520
1519
* Returns true if any matching items found on the page, false if none.
1521
1520
*/
1522
1521
static bool
1523
- _bt_readpage (IndexScanDesc scan , ScanDirection dir , OffsetNumber offnum )
1522
+ _bt_readpage (IndexScanDesc scan , ScanDirection dir , OffsetNumber offnum ,
1523
+ bool firstPage )
1524
1524
{
1525
1525
BTScanOpaque so = (BTScanOpaque ) scan -> opaque ;
1526
1526
Page page ;
@@ -1601,7 +1601,7 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum)
1601
1601
* We skip this for the first page in the scan to evade the possible
1602
1602
* slowdown of the point queries.
1603
1603
*/
1604
- if (!so -> firstPage && minoff < maxoff )
1604
+ if (!firstPage && minoff < maxoff )
1605
1605
{
1606
1606
ItemId iid ;
1607
1607
IndexTuple itup ;
@@ -1620,7 +1620,6 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum)
1620
1620
}
1621
1621
else
1622
1622
{
1623
- so -> firstPage = false;
1624
1623
requiredMatchedByPrecheck = false;
1625
1624
}
1626
1625
@@ -2079,7 +2078,7 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno, ScanDirection dir)
2079
2078
PredicateLockPage (rel , blkno , scan -> xs_snapshot );
2080
2079
/* see if there are any matches on this page */
2081
2080
/* 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 ))
2083
2082
break ;
2084
2083
}
2085
2084
else if (scan -> parallel_scan != NULL )
@@ -2170,7 +2169,7 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno, ScanDirection dir)
2170
2169
PredicateLockPage (rel , BufferGetBlockNumber (so -> currPos .buf ), scan -> xs_snapshot );
2171
2170
/* see if there are any matches on this page */
2172
2171
/* 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 ))
2174
2173
break ;
2175
2174
}
2176
2175
else if (scan -> parallel_scan != NULL )
@@ -2487,14 +2486,13 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
2487
2486
2488
2487
/* remember which buffer we have pinned */
2489
2488
so -> currPos .buf = buf ;
2490
- so -> firstPage = true;
2491
2489
2492
2490
_bt_initialize_more_data (so , dir );
2493
2491
2494
2492
/*
2495
2493
* Now load data from the first page of the scan.
2496
2494
*/
2497
- if (!_bt_readpage (scan , dir , start ))
2495
+ if (!_bt_readpage (scan , dir , start , false ))
2498
2496
{
2499
2497
/*
2500
2498
* There's no actually-matching data on this page. Try to advance to
0 commit comments