* Make sure this backend has up-to-date accessors for the current set of * batches. */
| 3748 | * batches. |
| 3749 | */ |
| 3750 | static void |
| 3751 | ExecParallelHashEnsureBatchAccessors(HashJoinTable hashtable) |
| 3752 | { |
| 3753 | ParallelHashJoinState *pstate = hashtable->parallel_state; |
| 3754 | ParallelHashJoinBatch *batches; |
| 3755 | MemoryContext oldcxt; |
| 3756 | int i; |
| 3757 | |
| 3758 | if (hashtable->batches != NULL) |
| 3759 | { |
| 3760 | if (hashtable->nbatch == pstate->nbatch) |
| 3761 | return; |
| 3762 | ExecParallelHashCloseBatchAccessors(hashtable); |
| 3763 | } |
| 3764 | |
| 3765 | /* |
| 3766 | * It's possible for a backend to start up very late so that the whole |
| 3767 | * join is finished and the shm state for tracking batches has already |
| 3768 | * been freed by ExecHashTableDetach(). In that case we'll just leave |
| 3769 | * hashtable->batches as NULL so that ExecParallelHashJoinNewBatch() gives |
| 3770 | * up early. |
| 3771 | */ |
| 3772 | if (!DsaPointerIsValid(pstate->batches)) |
| 3773 | return; |
| 3774 | |
| 3775 | /* Use hash join memory context. */ |
| 3776 | oldcxt = MemoryContextSwitchTo(hashtable->hashCxt); |
| 3777 | |
| 3778 | /* Allocate this backend's accessor array. */ |
| 3779 | hashtable->nbatch = pstate->nbatch; |
| 3780 | hashtable->batches = (ParallelHashJoinBatchAccessor *) |
| 3781 | palloc0(sizeof(ParallelHashJoinBatchAccessor) * hashtable->nbatch); |
| 3782 | |
| 3783 | /* Find the base of the pseudo-array of ParallelHashJoinBatch objects. */ |
| 3784 | batches = (ParallelHashJoinBatch *) |
| 3785 | dsa_get_address(hashtable->area, pstate->batches); |
| 3786 | |
| 3787 | /* Set up the accessor array and attach to the tuplestores. */ |
| 3788 | for (i = 0; i < hashtable->nbatch; ++i) |
| 3789 | { |
| 3790 | ParallelHashJoinBatchAccessor *accessor = &hashtable->batches[i]; |
| 3791 | ParallelHashJoinBatch *shared = NthParallelHashJoinBatch(batches, i); |
| 3792 | |
| 3793 | accessor->shared = shared; |
| 3794 | accessor->preallocated = 0; |
| 3795 | accessor->done = false; |
| 3796 | accessor->inner_tuples = |
| 3797 | sts_attach(ParallelHashJoinBatchInner(shared), |
| 3798 | hashtable->hjstate->worker_id, |
| 3799 | &pstate->fileset); |
| 3800 | accessor->outer_tuples = |
| 3801 | sts_attach(ParallelHashJoinBatchOuter(shared, |
| 3802 | pstate->nparticipants), |
| 3803 | hashtable->hjstate->worker_id, |
| 3804 | &pstate->fileset); |
| 3805 | } |
| 3806 | |
| 3807 | MemoryContextSwitchTo(oldcxt); |
no test coverage detected