@@ -1161,28 +1161,18 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
1161
1161
* If we found no usable boundary keys, we have to start from one end of
1162
1162
* the tree. Walk down that edge to the first or last key, and scan from
1163
1163
* there.
1164
+ *
1165
+ * Note: calls _bt_readfirstpage for us, which releases the parallel scan.
1164
1166
*/
1165
1167
if (keysz == 0 )
1166
- {
1167
- bool match ;
1168
-
1169
- match = _bt_endpoint (scan , dir );
1170
-
1171
- if (!match )
1172
- {
1173
- /* No match, so mark (parallel) scan finished */
1174
- _bt_parallel_done (scan );
1175
- }
1176
-
1177
- return match ;
1178
- }
1168
+ return _bt_endpoint (scan , dir );
1179
1169
1180
1170
/*
1181
1171
* We want to start the scan somewhere within the index. Set up an
1182
1172
* insertion scankey we can use to search for the boundary point we
1183
1173
* identified above. The insertion scankey is built using the keys
1184
1174
* identified by startKeys[]. (Remaining insertion scankey fields are
1185
- * initialized after initial-positioning strategy is finalized.)
1175
+ * initialized after initial-positioning scan keys are finalized.)
1186
1176
*/
1187
1177
Assert (keysz <= INDEX_MAX_KEYS );
1188
1178
for (i = 0 ; i < keysz ; i ++ )
@@ -1425,12 +1415,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
1425
1415
1426
1416
if (!BufferIsValid (so -> currPos .buf ))
1427
1417
{
1428
- /*
1429
- * Mark parallel scan as done, so that all the workers can finish
1430
- * their scan.
1431
- */
1432
1418
_bt_parallel_done (scan );
1433
- BTScanPosInvalidate (so -> currPos );
1434
1419
return false;
1435
1420
}
1436
1421
}
@@ -2267,8 +2252,8 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno,
2267
2252
!so -> currPos .moreRight : !so -> currPos .moreLeft ))
2268
2253
{
2269
2254
/* most recent _bt_readpage call (for lastcurrblkno) ended scan */
2270
- _bt_parallel_done (scan );
2271
2255
BTScanPosInvalidate (so -> currPos );
2256
+ _bt_parallel_done (scan );
2272
2257
return false;
2273
2258
}
2274
2259
@@ -2288,8 +2273,8 @@ _bt_readnextpage(IndexScanDesc scan, BlockNumber blkno,
2288
2273
if (so -> currPos .buf == InvalidBuffer )
2289
2274
{
2290
2275
/* must have been a concurrent deletion of leftmost page */
2291
- _bt_parallel_done (scan );
2292
2276
BTScanPosInvalidate (so -> currPos );
2277
+ _bt_parallel_done (scan );
2293
2278
return false;
2294
2279
}
2295
2280
}
@@ -2564,8 +2549,10 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost)
2564
2549
*
2565
2550
* This is used by _bt_first() to set up a scan when we've determined
2566
2551
* that the scan must start at the beginning or end of the index (for
2567
- * a forward or backward scan respectively). Exit conditions are the
2568
- * same as for _bt_first().
2552
+ * a forward or backward scan respectively).
2553
+ *
2554
+ * Parallel scan callers must have seized the scan before calling here.
2555
+ * Exit conditions are the same as for _bt_first().
2569
2556
*/
2570
2557
static bool
2571
2558
_bt_endpoint (IndexScanDesc scan , ScanDirection dir )
@@ -2577,10 +2564,11 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
2577
2564
OffsetNumber start ;
2578
2565
BTScanPosItem * currItem ;
2579
2566
2567
+ Assert (!BTScanPosIsValid (so -> currPos ));
2568
+
2580
2569
/*
2581
2570
* Scan down to the leftmost or rightmost leaf page. This is a simplified
2582
- * version of _bt_search(). We don't maintain a stack since we know we
2583
- * won't need it.
2571
+ * version of _bt_search().
2584
2572
*/
2585
2573
so -> currPos .buf = _bt_get_endpoint (rel , 0 , ScanDirectionIsBackward (dir ));
2586
2574
@@ -2591,7 +2579,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
2591
2579
* exists.
2592
2580
*/
2593
2581
PredicateLockRelation (rel , scan -> xs_snapshot );
2594
- BTScanPosInvalidate ( so -> currPos );
2582
+ _bt_parallel_done ( scan );
2595
2583
return false;
2596
2584
}
2597
2585
0 commit comments