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

Function ExecParallelHashJoinSetUpBatches

src/backend/executor/nodeHash.c:3652–3724  ·  view source on GitHub ↗

* One backend needs to set up the shared batch state including tuplestores. * Other backends will ensure they have correctly configured accessors by * called ExecParallelHashEnsureBatchAccessors(). */

Source from the content-addressed store, hash-verified

3650 * called ExecParallelHashEnsureBatchAccessors().
3651 */
3652static void
3653ExecParallelHashJoinSetUpBatches(HashJoinTable hashtable, int nbatch)
3654{
3655 ParallelHashJoinState *pstate = hashtable->parallel_state;
3656 ParallelHashJoinBatch *batches;
3657 MemoryContext oldcxt;
3658 int i;
3659
3660 Assert(hashtable->batches == NULL);
3661
3662 /* Allocate space. */
3663 pstate->batches =
3664 dsa_allocate0(hashtable->area,
3665 EstimateParallelHashJoinBatch(hashtable) * nbatch);
3666 pstate->nbatch = nbatch;
3667 batches = dsa_get_address(hashtable->area, pstate->batches);
3668
3669 /* Use hash join memory context. */
3670 oldcxt = MemoryContextSwitchTo(hashtable->hashCxt);
3671
3672 /* Allocate this backend's accessor array. */
3673 hashtable->nbatch = nbatch;
3674 hashtable->batches = (ParallelHashJoinBatchAccessor *)
3675 palloc0(sizeof(ParallelHashJoinBatchAccessor) * hashtable->nbatch);
3676
3677 /* Set up the shared state, tuplestores and backend-local accessors. */
3678 for (i = 0; i < hashtable->nbatch; ++i)
3679 {
3680 ParallelHashJoinBatchAccessor *accessor = &hashtable->batches[i];
3681 ParallelHashJoinBatch *shared = NthParallelHashJoinBatch(batches, i);
3682 char name[MAXPGPATH];
3683
3684 /*
3685 * All members of shared were zero-initialized. We just need to set
3686 * up the Barrier.
3687 */
3688 BarrierInit(&shared->batch_barrier, 0);
3689 if (i == 0)
3690 {
3691 /* Batch 0 doesn't need to be loaded. */
3692 BarrierAttach(&shared->batch_barrier);
3693 while (BarrierPhase(&shared->batch_barrier) < PHJ_BATCH_PROBING)
3694 BarrierArriveAndWait(&shared->batch_barrier, 0);
3695 BarrierDetach(&shared->batch_barrier);
3696 }
3697
3698 /* Initialize accessor state. All members were zero-initialized. */
3699 accessor->shared = shared;
3700
3701 /* Initialize the shared tuplestores. */
3702 snprintf(name, sizeof(name), "i%dof%d", i, hashtable->nbatch);
3703 accessor->inner_tuples =
3704 sts_initialize(ParallelHashJoinBatchInner(shared),
3705 pstate->nparticipants,
3706 hashtable->hjstate->worker_id,
3707 sizeof(uint32),
3708 SHARED_TUPLESTORE_SINGLE_PASS,
3709 &pstate->fileset,

Callers 2

ExecHashTableCreateFunction · 0.85

Calls 9

dsa_get_addressFunction · 0.85
MemoryContextSwitchToFunction · 0.85
BarrierInitFunction · 0.85
BarrierAttachFunction · 0.85
BarrierPhaseFunction · 0.85
BarrierArriveAndWaitFunction · 0.85
BarrierDetachFunction · 0.85
sts_initializeFunction · 0.85
palloc0Function · 0.50

Tested by

no test coverage detected