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

Function ExecHashTableDetachBatch

src/backend/executor/nodeHash.c:3833–3890  ·  view source on GitHub ↗

* If we are currently attached to a shared hash join batch, detach. If we * are last to detach, clean up. */

Source from the content-addressed store, hash-verified

3831 * are last to detach, clean up.
3832 */
3833void
3834ExecHashTableDetachBatch(HashJoinTable hashtable)
3835{
3836 if (hashtable->parallel_state != NULL &&
3837 hashtable->curbatch >= 0)
3838 {
3839 int curbatch = hashtable->curbatch;
3840 ParallelHashJoinBatch *batch = hashtable->batches[curbatch].shared;
3841
3842 /* Make sure any temporary files are closed. */
3843 sts_end_parallel_scan(hashtable->batches[curbatch].inner_tuples);
3844 sts_end_parallel_scan(hashtable->batches[curbatch].outer_tuples);
3845
3846 /* Detach from the batch we were last working on. */
3847 /*
3848 * CBDB_PARALLEL: Parallel Hash Left Anti Semi (Not-In) Join(parallel-aware)
3849 * If phs_lasj_has_null is true, that means we have found null when building hash table,
3850 * there were no batches to detach.
3851 */
3852 if (!hashtable->parallel_state->phs_lasj_has_null && BarrierArriveAndDetach(&batch->batch_barrier))
3853 {
3854 /*
3855 * Technically we shouldn't access the barrier because we're no
3856 * longer attached, but since there is no way it's moving after
3857 * this point it seems safe to make the following assertion.
3858 */
3859 Assert(BarrierPhase(&batch->batch_barrier) == PHJ_BATCH_DONE);
3860
3861 /* Free shared chunks and buckets. */
3862 while (DsaPointerIsValid(batch->chunks))
3863 {
3864 HashMemoryChunk chunk =
3865 dsa_get_address(hashtable->area, batch->chunks);
3866 dsa_pointer next = chunk->next.shared;
3867
3868 dsa_free(hashtable->area, batch->chunks);
3869 batch->chunks = next;
3870 }
3871 if (DsaPointerIsValid(batch->buckets))
3872 {
3873 dsa_free(hashtable->area, batch->buckets);
3874 batch->buckets = InvalidDsaPointer;
3875 }
3876 }
3877
3878 /*
3879 * Track the largest batch we've been attached to. Though each
3880 * backend might see a different subset of batches, explain.c will
3881 * scan the results from all backends to find the largest value.
3882 */
3883 hashtable->spacePeak =
3884 Max(hashtable->spacePeak,
3885 batch->size + sizeof(dsa_pointer_atomic) * hashtable->nbuckets);
3886
3887 /* Remember that we are not attached to a batch. */
3888 hashtable->curbatch = -1;
3889 }
3890}

Callers 3

ExecShutdownHashJoinFunction · 0.85

Calls 5

sts_end_parallel_scanFunction · 0.85
BarrierArriveAndDetachFunction · 0.85
BarrierPhaseFunction · 0.85
dsa_get_addressFunction · 0.85
dsa_freeFunction · 0.85

Tested by

no test coverage detected