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

Function ExecParallelHashJoinNewBatch

src/backend/executor/nodeHashjoin.c:1422–1552  ·  view source on GitHub ↗

* Choose a batch to work on, and attach to it. Returns true if successful, * false if there are no more batches. */

Source from the content-addressed store, hash-verified

1420 * false if there are no more batches.
1421 */
1422static bool
1423ExecParallelHashJoinNewBatch(HashJoinState *hjstate)
1424{
1425 HashJoinTable hashtable = hjstate->hj_HashTable;
1426 int start_batchno;
1427 int batchno;
1428 Barrier *batch0_barrier = NULL;
1429 ParallelHashJoinState *pstate = hashtable->parallel_state;
1430
1431 /*
1432 * If we started up so late that the batch tracking array has been freed
1433 * already by ExecHashTableDetach(), then we are finished. See also
1434 * ExecParallelHashEnsureBatchAccessors().
1435 */
1436 if (hashtable->batches == NULL)
1437 return false;
1438
1439 /*
1440 * If we were already attached to a batch, remember not to bother checking
1441 * it again, and detach from it (possibly freeing the hash table if we are
1442 * last to detach).
1443 */
1444 if (hashtable->curbatch >= 0)
1445 {
1446 hashtable->batches[hashtable->curbatch].done = true;
1447 ExecHashTableDetachBatch(hashtable);
1448 }
1449
1450 /*
1451 * Search for a batch that isn't done. We use an atomic counter to start
1452 * our search at a different batch in every participant when there are
1453 * more batches than participants.
1454 */
1455 batchno = start_batchno =
1456 pg_atomic_fetch_add_u32(&hashtable->parallel_state->distributor, 1) %
1457 hashtable->nbatch;
1458 do
1459 {
1460 uint32 hashvalue;
1461 MinimalTuple tuple;
1462 TupleTableSlot *slot;
1463
1464 if (!hashtable->batches[batchno].done)
1465 {
1466 SharedTuplestoreAccessor *inner_tuples;
1467 Barrier *batch_barrier =
1468 &hashtable->batches[batchno].shared->batch_barrier;
1469 int phase = BarrierAttach(batch_barrier);
1470
1471 if (hashtable->nbatch == 1 && batchno == 0 && ((HashJoin *)hjstate->js.ps.plan)->batch0_barrier)
1472 {
1473 Assert(phase == PHJ_BATCH_PROBING);
1474
1475 batch0_barrier = &pstate->batch0_barrier;
1476 BarrierArriveAndWait(batch0_barrier, WAIT_EVENT_PARALLEL_FINISH);
1477 }
1478
1479 switch (phase)

Callers 1

ExecHashJoinImplFunction · 0.85

Calls 13

ExecHashTableDetachBatchFunction · 0.85
pg_atomic_fetch_add_u32Function · 0.85
BarrierAttachFunction · 0.85
BarrierArriveAndWaitFunction · 0.85
sts_begin_parallel_scanFunction · 0.85
sts_parallel_scan_nextFunction · 0.85
sts_end_parallel_scanFunction · 0.85
BarrierDetachFunction · 0.85

Tested by

no test coverage detected