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

Function dense_alloc

src/backend/executor/nodeHash.c:3424–3491  ·  view source on GitHub ↗

* Allocate 'size' bytes from the currently active HashMemoryChunk */

Source from the content-addressed store, hash-verified

3422 * Allocate 'size' bytes from the currently active HashMemoryChunk
3423 */
3424static void *
3425dense_alloc(HashJoinTable hashtable, Size size)
3426{
3427 HashMemoryChunk newChunk;
3428 char *ptr;
3429
3430 /* just in case the size is not already aligned properly */
3431 size = MAXALIGN(size);
3432
3433 /*
3434 * If tuple size is larger than threshold, allocate a separate chunk.
3435 */
3436 if (size > HASH_CHUNK_THRESHOLD)
3437 {
3438 /* allocate new chunk and put it at the beginning of the list */
3439 newChunk = (HashMemoryChunk) MemoryContextAlloc(hashtable->batchCxt,
3440 HASH_CHUNK_HEADER_SIZE + size);
3441 newChunk->maxlen = size;
3442 newChunk->used = size;
3443 newChunk->ntuples = 1;
3444
3445 /*
3446 * Add this chunk to the list after the first existing chunk, so that
3447 * we don't lose the remaining space in the "current" chunk.
3448 */
3449 if (hashtable->chunks != NULL)
3450 {
3451 newChunk->next = hashtable->chunks->next;
3452 hashtable->chunks->next.unshared = newChunk;
3453 }
3454 else
3455 {
3456 newChunk->next.unshared = hashtable->chunks;
3457 hashtable->chunks = newChunk;
3458 }
3459
3460 return HASH_CHUNK_DATA(newChunk);
3461 }
3462
3463 /*
3464 * See if we have enough space for it in the current chunk (if any). If
3465 * not, allocate a fresh chunk.
3466 */
3467 if ((hashtable->chunks == NULL) ||
3468 (hashtable->chunks->maxlen - hashtable->chunks->used) < size)
3469 {
3470 /* allocate new chunk and put it at the beginning of the list */
3471 newChunk = (HashMemoryChunk) MemoryContextAlloc(hashtable->batchCxt,
3472 HASH_CHUNK_HEADER_SIZE + HASH_CHUNK_SIZE);
3473
3474 newChunk->maxlen = HASH_CHUNK_SIZE;
3475 newChunk->used = size;
3476 newChunk->ntuples = 1;
3477
3478 newChunk->next.unshared = hashtable->chunks;
3479 hashtable->chunks = newChunk;
3480
3481 return HASH_CHUNK_DATA(newChunk);

Callers 3

ExecHashTableInsertFunction · 0.85

Calls 1

MemoryContextAllocFunction · 0.85

Tested by

no test coverage detected