MCPcopy Create free account
hub / github.com/apache/cloudberry / BitmapAdjustPrefetchIterator

Function BitmapAdjustPrefetchIterator

src/backend/executor/nodeBitmapHeapscan.c:412–467  ·  view source on GitHub ↗

* BitmapAdjustPrefetchIterator - Adjust the prefetch iterator */

Source from the content-addressed store, hash-verified

410 * BitmapAdjustPrefetchIterator - Adjust the prefetch iterator
411 */
412static inline void
413BitmapAdjustPrefetchIterator(BitmapHeapScanState *node,
414 TBMIterateResult *tbmres)
415{
416#ifdef USE_PREFETCH
417 ParallelBitmapHeapState *pstate = node->pstate;
418
419 if (pstate == NULL)
420 {
421 GenericBMIterator *prefetch_iterator = node->prefetch_iterator;
422
423 if (node->prefetch_pages > 0)
424 {
425 /* The main iterator has closed the distance by one page */
426 node->prefetch_pages--;
427 }
428 else if (prefetch_iterator)
429 {
430 /* Do not let the prefetch iterator get behind the main one */
431 TBMIterateResult *tbmpre = tbm_generic_iterate(prefetch_iterator);
432
433 if (tbmpre == NULL || tbmpre->blockno != tbmres->blockno)
434 elog(ERROR, "prefetch and main iterators are out of sync");
435 }
436 return;
437 }
438
439 if (node->prefetch_maximum > 0)
440 {
441 TBMSharedIterator *prefetch_iterator = node->shared_prefetch_iterator;
442
443 SpinLockAcquire(&pstate->mutex);
444 if (pstate->prefetch_pages > 0)
445 {
446 pstate->prefetch_pages--;
447 SpinLockRelease(&pstate->mutex);
448 }
449 else
450 {
451 /* Release the mutex before iterating */
452 SpinLockRelease(&pstate->mutex);
453
454 /*
455 * In case of shared mode, we can not ensure that the current
456 * blockno of the main iterator and that of the prefetch iterator
457 * are same. It's possible that whatever blockno we are
458 * prefetching will be processed by another process. Therefore,
459 * we don't validate the blockno here as we do in non-parallel
460 * case.
461 */
462 if (prefetch_iterator)
463 tbm_shared_iterate(prefetch_iterator);
464 }
465 }
466#endif /* USE_PREFETCH */
467}
468
469/*

Callers 1

BitmapHeapNextFunction · 0.85

Calls 2

tbm_generic_iterateFunction · 0.85
tbm_shared_iterateFunction · 0.85

Tested by

no test coverage detected