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

Function ExecParallelHashTableInsert

src/backend/executor/nodeHash.c:1977–2034  ·  view source on GitHub ↗

* ExecParallelHashTableInsert * insert a tuple into a shared hash table or shared batch tuplestore */

Source from the content-addressed store, hash-verified

1975 * insert a tuple into a shared hash table or shared batch tuplestore
1976 */
1977void
1978ExecParallelHashTableInsert(HashJoinTable hashtable,
1979 TupleTableSlot *slot,
1980 uint32 hashvalue)
1981{
1982 bool shouldFree;
1983 MinimalTuple tuple = ExecFetchSlotMinimalTuple(slot, &shouldFree);
1984 dsa_pointer shared;
1985 int bucketno;
1986 int batchno;
1987
1988retry:
1989 ExecHashGetBucketAndBatch(hashtable, hashvalue, &bucketno, &batchno);
1990
1991 if (batchno == 0)
1992 {
1993 HashJoinTuple hashTuple;
1994
1995 /* Try to load it into memory. */
1996 Assert(BarrierPhase(&hashtable->parallel_state->build_barrier) ==
1997 PHJ_BUILD_HASHING_INNER);
1998 hashTuple = ExecParallelHashTupleAlloc(hashtable,
1999 HJTUPLE_OVERHEAD + tuple->t_len,
2000 &shared);
2001 if (hashTuple == NULL)
2002 goto retry;
2003
2004 /* Store the hash value in the HashJoinTuple header. */
2005 hashTuple->hashvalue = hashvalue;
2006 memcpy(HJTUPLE_MINTUPLE(hashTuple), tuple, tuple->t_len);
2007
2008 /* Push it onto the front of the bucket's list */
2009 ExecParallelHashPushTuple(&hashtable->buckets.shared[bucketno],
2010 hashTuple, shared);
2011 }
2012 else
2013 {
2014 size_t tuple_size = MAXALIGN(HJTUPLE_OVERHEAD + tuple->t_len);
2015
2016 Assert(batchno > 0);
2017
2018 /* Try to preallocate space in the batch if necessary. */
2019 if (hashtable->batches[batchno].preallocated < tuple_size)
2020 {
2021 if (!ExecParallelHashTuplePrealloc(hashtable, batchno, tuple_size))
2022 goto retry;
2023 }
2024
2025 Assert(hashtable->batches[batchno].preallocated >= tuple_size);
2026 hashtable->batches[batchno].preallocated -= tuple_size;
2027 sts_puttuple(hashtable->batches[batchno].inner_tuples, &hashvalue,
2028 tuple);
2029 }
2030 ++hashtable->batches[batchno].ntuples;
2031
2032 if (shouldFree)
2033 heap_free_minimal_tuple(tuple);
2034}

Callers 1

MultiExecParallelHashFunction · 0.85

Calls 8

BarrierPhaseFunction · 0.85
sts_puttupleFunction · 0.85
heap_free_minimal_tupleFunction · 0.85

Tested by

no test coverage detected