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

Function ExecParallelHashTuplePrealloc

src/backend/executor/nodeHash.c:4042–4092  ·  view source on GitHub ↗

* Increase the space preallocated in this backend for a given inner batch by * at least a given amount. This allows us to track whether a given batch * would fit in memory when loaded back in. Also increase the number of * batches or buckets if required. * * This maintains a running estimation of how much space will be taken when we * load the batch back into memory by simulating the way c

Source from the content-addressed store, hash-verified

4040 * again.
4041 */
4042static bool
4043ExecParallelHashTuplePrealloc(HashJoinTable hashtable, int batchno, size_t size)
4044{
4045 ParallelHashJoinState *pstate = hashtable->parallel_state;
4046 ParallelHashJoinBatchAccessor *batch = &hashtable->batches[batchno];
4047 size_t want = Max(size, HASH_CHUNK_SIZE - HASH_CHUNK_HEADER_SIZE);
4048
4049 Assert(batchno > 0);
4050 Assert(batchno < hashtable->nbatch);
4051 Assert(size == MAXALIGN(size));
4052
4053 LWLockAcquire(&pstate->lock, LW_EXCLUSIVE);
4054
4055 /* Has another participant commanded us to help grow? */
4056 if (pstate->growth == PHJ_GROWTH_NEED_MORE_BATCHES ||
4057 pstate->growth == PHJ_GROWTH_NEED_MORE_BUCKETS)
4058 {
4059 ParallelHashGrowth growth = pstate->growth;
4060
4061 LWLockRelease(&pstate->lock);
4062 if (growth == PHJ_GROWTH_NEED_MORE_BATCHES)
4063 ExecParallelHashIncreaseNumBatches(hashtable);
4064 else if (growth == PHJ_GROWTH_NEED_MORE_BUCKETS)
4065 ExecParallelHashIncreaseNumBuckets(hashtable);
4066
4067 return false;
4068 }
4069
4070 if (pstate->growth != PHJ_GROWTH_DISABLED &&
4071 batch->at_least_one_chunk &&
4072 (batch->shared->estimated_size + want + HASH_CHUNK_HEADER_SIZE
4073 > pstate->space_allowed))
4074 {
4075 /*
4076 * We have determined that this batch would exceed the space budget if
4077 * loaded into memory. Command all participants to help repartition.
4078 */
4079 batch->shared->space_exhausted = true;
4080 pstate->growth = PHJ_GROWTH_NEED_MORE_BATCHES;
4081 LWLockRelease(&pstate->lock);
4082
4083 return false;
4084 }
4085
4086 batch->at_least_one_chunk = true;
4087 batch->shared->estimated_size += want + HASH_CHUNK_HEADER_SIZE;
4088 batch->preallocated = want;
4089 LWLockRelease(&pstate->lock);
4090
4091 return true;
4092}
4093
4094/*
4095 * Calculate the limit on how much memory can be used by Hash and similar

Callers 1

Calls 4

LWLockAcquireFunction · 0.85
LWLockReleaseFunction · 0.85

Tested by

no test coverage detected