@@ -30,7 +30,7 @@ static OffsetNumber _bt_binsrch(Relation rel, BTScanInsert key, Buffer buf);
3030static int _bt_binsrch_posting (BTScanInsert key , Page page ,
3131 OffsetNumber offnum );
3232static bool _bt_readpage (IndexScanDesc scan , ScanDirection dir ,
33- OffsetNumber offnum );
33+ OffsetNumber offnum , bool firstPage );
3434static void _bt_saveitem (BTScanOpaque so , int itemIndex ,
3535 OffsetNumber offnum , IndexTuple itup );
3636static 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 */
15221521static 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
0 commit comments