2626#include "utils/memutils.h"
2727
2828static int TupleHashTableMatch (struct tuplehash_hash * tb , const MinimalTuple tuple1 , const MinimalTuple tuple2 );
29+ static uint32 TupleHashTableHash_internal (struct tuplehash_hash * tb ,
30+ const MinimalTuple tuple );
2931static TupleHashEntry LookupTupleHashEntry_internal (
3032 TupleHashTable hashtable , TupleTableSlot * slot , bool * isnew , uint32 hash );
3133
@@ -38,7 +40,7 @@ static TupleHashEntry LookupTupleHashEntry_internal(
3840#define SH_ELEMENT_TYPE TupleHashEntryData
3941#define SH_KEY_TYPE MinimalTuple
4042#define SH_KEY firstTuple
41- #define SH_HASH_KEY (tb , key ) TupleHashTableHash (tb, key)
43+ #define SH_HASH_KEY (tb , key ) TupleHashTableHash_internal (tb, key)
4244#define SH_EQUAL (tb , a , b ) TupleHashTableMatch(tb, a, b) == 0
4345#define SH_SCOPE extern
4446#define SH_STORE_HASH
@@ -313,14 +315,36 @@ LookupTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot,
313315 hashtable -> in_hash_funcs = hashtable -> tab_hash_funcs ;
314316 hashtable -> cur_eq_func = hashtable -> tab_eq_func ;
315317
316- hash = TupleHashTableHash (hashtable -> hashtab , NULL );
318+ hash = TupleHashTableHash_internal (hashtable -> hashtab , NULL );
317319 entry = LookupTupleHashEntry_internal (hashtable , slot , isnew , hash );
318320
319321 MemoryContextSwitchTo (oldContext );
320322
321323 return entry ;
322324}
323325
326+ /*
327+ * Compute the hash value for a tuple
328+ */
329+ uint32
330+ TupleHashTableHash (TupleHashTable hashtable , TupleTableSlot * slot )
331+ {
332+ MemoryContext oldContext ;
333+ uint32 hash ;
334+
335+ hashtable -> inputslot = slot ;
336+ hashtable -> in_hash_funcs = hashtable -> tab_hash_funcs ;
337+
338+ /* Need to run the hash functions in short-lived context */
339+ oldContext = MemoryContextSwitchTo (hashtable -> tempcxt );
340+
341+ hash = TupleHashTableHash_internal (hashtable -> hashtab , NULL );
342+
343+ MemoryContextSwitchTo (oldContext );
344+
345+ return hash ;
346+ }
347+
324348/*
325349 * A variant of LookupTupleHashEntry for callers that have already computed
326350 * the hash value.
@@ -382,17 +406,16 @@ FindTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot,
382406}
383407
384408/*
385- * Compute the hash value for a tuple
386- *
387409 * If tuple is NULL, use the input slot instead. This convention avoids the
388410 * need to materialize virtual input tuples unless they actually need to get
389411 * copied into the table.
390412 *
391413 * Also, the caller must select an appropriate memory context for running
392414 * the hash functions. (dynahash.c doesn't change CurrentMemoryContext.)
393415 */
394- uint32
395- TupleHashTableHash (struct tuplehash_hash * tb , const MinimalTuple tuple )
416+ static uint32
417+ TupleHashTableHash_internal (struct tuplehash_hash * tb ,
418+ const MinimalTuple tuple )
396419{
397420 TupleHashTable hashtable = (TupleHashTable ) tb -> private_data ;
398421 int numCols = hashtable -> numCols ;
0 commit comments