* ExecParallelHashTableInsert * insert a tuple into a shared hash table or shared batch tuplestore */
| 1975 | * insert a tuple into a shared hash table or shared batch tuplestore |
| 1976 | */ |
| 1977 | void |
| 1978 | ExecParallelHashTableInsert(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 | |
| 1988 | retry: |
| 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 | } |
no test coverage detected