* BitmapAdjustPrefetchIterator - Adjust the prefetch iterator */
| 410 | * BitmapAdjustPrefetchIterator - Adjust the prefetch iterator |
| 411 | */ |
| 412 | static inline void |
| 413 | BitmapAdjustPrefetchIterator(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 | /* |
no test coverage detected