PostgreSQL Source Code  git master
execGrouping.c File Reference
#include "postgres.h"
#include "access/parallel.h"
#include "common/hashfn.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "utils/lsyscache.h"
#include "lib/simplehash.h"
Include dependency graph for execGrouping.c:

Go to the source code of this file.

Macros

#define SH_PREFIX   tuplehash
 
#define SH_ELEMENT_TYPE   TupleHashEntryData
 
#define SH_KEY_TYPE   MinimalTuple
 
#define SH_KEY   firstTuple
 
#define SH_HASH_KEY(tb, key)   TupleHashTableHash_internal(tb, key)
 
#define SH_EQUAL(tb, a, b)   TupleHashTableMatch(tb, a, b) == 0
 
#define SH_SCOPE   extern
 
#define SH_STORE_HASH
 
#define SH_GET_HASH(tb, a)   a->hash
 
#define SH_DEFINE
 

Functions

static int TupleHashTableMatch (struct tuplehash_hash *tb, const MinimalTuple tuple1, const MinimalTuple tuple2)
 
static uint32 TupleHashTableHash_internal (struct tuplehash_hash *tb, const MinimalTuple tuple)
 
static TupleHashEntry LookupTupleHashEntry_internal (TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 hash)
 
ExprStateexecTuplesMatchPrepare (TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
 
void execTuplesHashPrepare (int numCols, const Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
 
TupleHashTable BuildTupleHashTableExt (PlanState *parent, TupleDesc inputDesc, int numCols, AttrNumber *keyColIdx, const Oid *eqfuncoids, FmgrInfo *hashfunctions, Oid *collations, long nbuckets, Size additionalsize, MemoryContext metacxt, MemoryContext tablecxt, MemoryContext tempcxt, bool use_variable_hash_iv)
 
TupleHashTable BuildTupleHashTable (PlanState *parent, TupleDesc inputDesc, int numCols, AttrNumber *keyColIdx, const Oid *eqfuncoids, FmgrInfo *hashfunctions, Oid *collations, long nbuckets, Size additionalsize, MemoryContext tablecxt, MemoryContext tempcxt, bool use_variable_hash_iv)
 
void ResetTupleHashTable (TupleHashTable hashtable)
 
TupleHashEntry LookupTupleHashEntry (TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 *hash)
 
uint32 TupleHashTableHash (TupleHashTable hashtable, TupleTableSlot *slot)
 
TupleHashEntry LookupTupleHashEntryHash (TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 hash)
 
TupleHashEntry FindTupleHashEntry (TupleHashTable hashtable, TupleTableSlot *slot, ExprState *eqcomp, FmgrInfo *hashfunctions)
 

Macro Definition Documentation

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 44 of file execGrouping.c.

◆ SH_ELEMENT_TYPE

#define SH_ELEMENT_TYPE   TupleHashEntryData

Definition at line 36 of file execGrouping.c.

◆ SH_EQUAL

#define SH_EQUAL (   tb,
  a,
  b 
)    TupleHashTableMatch(tb, a, b) == 0

Definition at line 40 of file execGrouping.c.

◆ SH_GET_HASH

#define SH_GET_HASH (   tb,
  a 
)    a->hash

Definition at line 43 of file execGrouping.c.

◆ SH_HASH_KEY

#define SH_HASH_KEY (   tb,
  key 
)    TupleHashTableHash_internal(tb, key)

Definition at line 39 of file execGrouping.c.

◆ SH_KEY

#define SH_KEY   firstTuple

Definition at line 38 of file execGrouping.c.

◆ SH_KEY_TYPE

#define SH_KEY_TYPE   MinimalTuple

Definition at line 37 of file execGrouping.c.

◆ SH_PREFIX

#define SH_PREFIX   tuplehash

Definition at line 35 of file execGrouping.c.

◆ SH_SCOPE

#define SH_SCOPE   extern

Definition at line 41 of file execGrouping.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 42 of file execGrouping.c.

Function Documentation

◆ BuildTupleHashTable()

TupleHashTable BuildTupleHashTable ( PlanState parent,
TupleDesc  inputDesc,
int  numCols,
AttrNumber keyColIdx,
const Oid eqfuncoids,
FmgrInfo hashfunctions,
Oid collations,
long  nbuckets,
Size  additionalsize,
MemoryContext  tablecxt,
MemoryContext  tempcxt,
bool  use_variable_hash_iv 
)

Definition at line 254 of file execGrouping.c.

264 {
265  return BuildTupleHashTableExt(parent,
266  inputDesc,
267  numCols, keyColIdx,
268  eqfuncoids,
269  hashfunctions,
270  collations,
271  nbuckets, additionalsize,
272  tablecxt,
273  tablecxt,
274  tempcxt,
275  use_variable_hash_iv);
276 }
TupleHashTable BuildTupleHashTableExt(PlanState *parent, TupleDesc inputDesc, int numCols, AttrNumber *keyColIdx, const Oid *eqfuncoids, FmgrInfo *hashfunctions, Oid *collations, long nbuckets, Size additionalsize, MemoryContext metacxt, MemoryContext tablecxt, MemoryContext tempcxt, bool use_variable_hash_iv)
Definition: execGrouping.c:153

References BuildTupleHashTableExt().

◆ BuildTupleHashTableExt()

TupleHashTable BuildTupleHashTableExt ( PlanState parent,
TupleDesc  inputDesc,
int  numCols,
AttrNumber keyColIdx,
const Oid eqfuncoids,
FmgrInfo hashfunctions,
Oid collations,
long  nbuckets,
Size  additionalsize,
MemoryContext  metacxt,
MemoryContext  tablecxt,
MemoryContext  tempcxt,
bool  use_variable_hash_iv 
)

Definition at line 153 of file execGrouping.c.

164 {
165  TupleHashTable hashtable;
166  Size entrysize = sizeof(TupleHashEntryData) + additionalsize;
167  Size hash_mem_limit;
168  MemoryContext oldcontext;
169  bool allow_jit;
170 
171  Assert(nbuckets > 0);
172 
173  /* Limit initial table size request to not more than hash_mem */
174  hash_mem_limit = get_hash_memory_limit() / entrysize;
175  if (nbuckets > hash_mem_limit)
176  nbuckets = hash_mem_limit;
177 
178  oldcontext = MemoryContextSwitchTo(metacxt);
179 
180  hashtable = (TupleHashTable) palloc(sizeof(TupleHashTableData));
181 
182  hashtable->numCols = numCols;
183  hashtable->keyColIdx = keyColIdx;
184  hashtable->tab_hash_funcs = hashfunctions;
185  hashtable->tab_collations = collations;
186  hashtable->tablecxt = tablecxt;
187  hashtable->tempcxt = tempcxt;
188  hashtable->entrysize = entrysize;
189  hashtable->tableslot = NULL; /* will be made on first lookup */
190  hashtable->inputslot = NULL;
191  hashtable->in_hash_funcs = NULL;
192  hashtable->cur_eq_func = NULL;
193 
194  /*
195  * If parallelism is in use, even if the leader backend is performing the
196  * scan itself, we don't want to create the hashtable exactly the same way
197  * in all workers. As hashtables are iterated over in keyspace-order,
198  * doing so in all processes in the same way is likely to lead to
199  * "unbalanced" hashtables when the table size initially is
200  * underestimated.
201  */
202  if (use_variable_hash_iv)
204  else
205  hashtable->hash_iv = 0;
206 
207  hashtable->hashtab = tuplehash_create(metacxt, nbuckets, hashtable);
208 
209  /*
210  * We copy the input tuple descriptor just for safety --- we assume all
211  * input tuples will have equivalent descriptors.
212  */
215 
216  /*
217  * If the old reset interface is used (i.e. BuildTupleHashTable, rather
218  * than BuildTupleHashTableExt), allowing JIT would lead to the generated
219  * functions to a) live longer than the query b) be re-generated each time
220  * the table is being reset. Therefore prevent JIT from being used in that
221  * case, by not providing a parent node (which prevents accessing the
222  * JitContext in the EState).
223  */
224  allow_jit = metacxt != tablecxt;
225 
226  /* build comparator for all columns */
227  /* XXX: should we support non-minimal tuples for the inputslot? */
228  hashtable->tab_eq_func = ExecBuildGroupingEqual(inputDesc, inputDesc,
230  numCols,
231  keyColIdx, eqfuncoids, collations,
232  allow_jit ? parent : NULL);
233 
234  /*
235  * While not pretty, it's ok to not shut down this context, but instead
236  * rely on the containing memory context being reset, as
237  * ExecBuildGroupingEqual() only builds a very simple expression calling
238  * functions (i.e. nothing that'd employ RegisterExprContextCallback()).
239  */
241 
242  MemoryContextSwitchTo(oldcontext);
243 
244  return hashtable;
245 }
int ParallelWorkerNumber
Definition: parallel.c:112
#define Assert(condition)
Definition: c.h:858
size_t Size
Definition: c.h:605
ExprState * ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc, const TupleTableSlotOps *lops, const TupleTableSlotOps *rops, int numCols, const AttrNumber *keyColIdx, const Oid *eqfunctions, const Oid *collations, PlanState *parent)
Definition: execExpr.c:3946
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1325
ExprContext * CreateStandaloneExprContext(void)
Definition: execUtils.c:355
struct TupleHashTableData * TupleHashTable
Definition: execnodes.h:797
struct TupleHashEntryData TupleHashEntryData
static uint32 murmurhash32(uint32 data)
Definition: hashfn.h:92
void * palloc(Size size)
Definition: mcxt.c:1316
size_t get_hash_memory_limit(void)
Definition: nodeHash.c:3595
MemoryContextSwitchTo(old_ctx)
AttrNumber * keyColIdx
Definition: execnodes.h:819
FmgrInfo * tab_hash_funcs
Definition: execnodes.h:820
tuplehash_hash * hashtab
Definition: execnodes.h:817
MemoryContext tempcxt
Definition: execnodes.h:824
ExprState * tab_eq_func
Definition: execnodes.h:821
TupleTableSlot * tableslot
Definition: execnodes.h:826
ExprContext * exprcontext
Definition: execnodes.h:832
MemoryContext tablecxt
Definition: execnodes.h:823
TupleTableSlot * inputslot
Definition: execnodes.h:828
ExprState * cur_eq_func
Definition: execnodes.h:830
FmgrInfo * in_hash_funcs
Definition: execnodes.h:829
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:133

References Assert, CreateStandaloneExprContext(), CreateTupleDescCopy(), TupleHashTableData::cur_eq_func, TupleHashTableData::entrysize, ExecBuildGroupingEqual(), TupleHashTableData::exprcontext, get_hash_memory_limit(), TupleHashTableData::hash_iv, TupleHashTableData::hashtab, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, TupleHashTableData::keyColIdx, MakeSingleTupleTableSlot(), MemoryContextSwitchTo(), murmurhash32(), TupleHashTableData::numCols, palloc(), ParallelWorkerNumber, TupleHashTableData::tab_collations, TupleHashTableData::tab_eq_func, TupleHashTableData::tab_hash_funcs, TupleHashTableData::tablecxt, TupleHashTableData::tableslot, TupleHashTableData::tempcxt, and TTSOpsMinimalTuple.

Referenced by build_hash_table(), buildSubPlanHash(), and BuildTupleHashTable().

◆ execTuplesHashPrepare()

void execTuplesHashPrepare ( int  numCols,
const Oid eqOperators,
Oid **  eqFuncOids,
FmgrInfo **  hashFunctions 
)

Definition at line 95 of file execGrouping.c.

99 {
100  int i;
101 
102  *eqFuncOids = (Oid *) palloc(numCols * sizeof(Oid));
103  *hashFunctions = (FmgrInfo *) palloc(numCols * sizeof(FmgrInfo));
104 
105  for (i = 0; i < numCols; i++)
106  {
107  Oid eq_opr = eqOperators[i];
108  Oid eq_function;
109  Oid left_hash_function;
110  Oid right_hash_function;
111 
112  eq_function = get_opcode(eq_opr);
113  if (!get_op_hash_functions(eq_opr,
114  &left_hash_function, &right_hash_function))
115  elog(ERROR, "could not find hash function for hash operator %u",
116  eq_opr);
117  /* We're not supporting cross-type cases here */
118  Assert(left_hash_function == right_hash_function);
119  (*eqFuncOids)[i] = eq_function;
120  fmgr_info(right_hash_function, &(*hashFunctions)[i]);
121  }
122 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
int i
Definition: isn.c:73
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1285
bool get_op_hash_functions(Oid opno, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
Definition: lsyscache.c:510
unsigned int Oid
Definition: postgres_ext.h:31
Definition: fmgr.h:57

References Assert, elog, ERROR, fmgr_info(), get_op_hash_functions(), get_opcode(), i, and palloc().

Referenced by ExecInitRecursiveUnion(), ExecInitSetOp(), and find_hash_columns().

◆ execTuplesMatchPrepare()

ExprState* execTuplesMatchPrepare ( TupleDesc  desc,
int  numCols,
const AttrNumber keyColIdx,
const Oid eqOperators,
const Oid collations,
PlanState parent 
)

Definition at line 58 of file execGrouping.c.

64 {
65  Oid *eqFunctions = (Oid *) palloc(numCols * sizeof(Oid));
66  int i;
67  ExprState *expr;
68 
69  if (numCols == 0)
70  return NULL;
71 
72  /* lookup equality functions */
73  for (i = 0; i < numCols; i++)
74  eqFunctions[i] = get_opcode(eqOperators[i]);
75 
76  /* build actual expression */
77  expr = ExecBuildGroupingEqual(desc, desc, NULL, NULL,
78  numCols, keyColIdx, eqFunctions, collations,
79  parent);
80 
81  return expr;
82 }

References ExecBuildGroupingEqual(), get_opcode(), i, and palloc().

Referenced by build_pertrans_for_aggref(), ExecInitAgg(), ExecInitGroup(), ExecInitLimit(), ExecInitSetOp(), ExecInitUnique(), ExecInitWindowAgg(), and hypothetical_dense_rank_final().

◆ FindTupleHashEntry()

TupleHashEntry FindTupleHashEntry ( TupleHashTable  hashtable,
TupleTableSlot slot,
ExprState eqcomp,
FmgrInfo hashfunctions 
)

Definition at line 392 of file execGrouping.c.

395 {
396  TupleHashEntry entry;
397  MemoryContext oldContext;
399 
400  /* Need to run the hash functions in short-lived context */
401  oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
402 
403  /* Set up data needed by hash and match functions */
404  hashtable->inputslot = slot;
405  hashtable->in_hash_funcs = hashfunctions;
406  hashtable->cur_eq_func = eqcomp;
407 
408  /* Search the hash table */
409  key = NULL; /* flag to reference inputslot */
410  entry = tuplehash_lookup(hashtable->hashtab, key);
411  MemoryContextSwitchTo(oldContext);
412 
413  return entry;
414 }

References TupleHashTableData::cur_eq_func, TupleHashTableData::hashtab, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, sort-test::key, MemoryContextSwitchTo(), and TupleHashTableData::tempcxt.

Referenced by ExecHashSubPlan().

◆ LookupTupleHashEntry()

TupleHashEntry LookupTupleHashEntry ( TupleHashTable  hashtable,
TupleTableSlot slot,
bool isnew,
uint32 hash 
)

Definition at line 305 of file execGrouping.c.

307 {
308  TupleHashEntry entry;
309  MemoryContext oldContext;
310  uint32 local_hash;
311 
312  /* Need to run the hash functions in short-lived context */
313  oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
314 
315  /* set up data needed by hash and match functions */
316  hashtable->inputslot = slot;
317  hashtable->in_hash_funcs = hashtable->tab_hash_funcs;
318  hashtable->cur_eq_func = hashtable->tab_eq_func;
319 
320  local_hash = TupleHashTableHash_internal(hashtable->hashtab, NULL);
321  entry = LookupTupleHashEntry_internal(hashtable, slot, isnew, local_hash);
322 
323  if (hash != NULL)
324  *hash = local_hash;
325 
326  Assert(entry == NULL || entry->hash == local_hash);
327 
328  MemoryContextSwitchTo(oldContext);
329 
330  return entry;
331 }
unsigned int uint32
Definition: c.h:506
static uint32 TupleHashTableHash_internal(struct tuplehash_hash *tb, const MinimalTuple tuple)
Definition: execGrouping.c:425
static TupleHashEntry LookupTupleHashEntry_internal(TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 hash)
Definition: execGrouping.c:495
static unsigned hash(unsigned *uv, int n)
Definition: rege_dfa.c:715

References Assert, TupleHashTableData::cur_eq_func, hash(), TupleHashEntryData::hash, TupleHashTableData::hashtab, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, LookupTupleHashEntry_internal(), MemoryContextSwitchTo(), TupleHashTableData::tab_eq_func, TupleHashTableData::tab_hash_funcs, TupleHashTableData::tempcxt, and TupleHashTableHash_internal().

Referenced by buildSubPlanHash(), ExecRecursiveUnion(), lookup_hash_entries(), and setop_fill_hash_table().

◆ LookupTupleHashEntry_internal()

static TupleHashEntry LookupTupleHashEntry_internal ( TupleHashTable  hashtable,
TupleTableSlot slot,
bool isnew,
uint32  hash 
)
inlinestatic

Definition at line 495 of file execGrouping.c.

497 {
498  TupleHashEntryData *entry;
499  bool found;
501 
502  key = NULL; /* flag to reference inputslot */
503 
504  if (isnew)
505  {
506  entry = tuplehash_insert_hash(hashtable->hashtab, key, hash, &found);
507 
508  if (found)
509  {
510  /* found pre-existing entry */
511  *isnew = false;
512  }
513  else
514  {
515  /* created new entry */
516  *isnew = true;
517  /* zero caller data */
518  entry->additional = NULL;
519  MemoryContextSwitchTo(hashtable->tablecxt);
520  /* Copy the first tuple into the table context */
521  entry->firstTuple = ExecCopySlotMinimalTuple(slot);
522  }
523  }
524  else
525  {
526  entry = tuplehash_lookup_hash(hashtable->hashtab, key, hash);
527  }
528 
529  return entry;
530 }
MinimalTuple firstTuple
Definition: execnodes.h:801
static MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
Definition: tuptable.h:492

References TupleHashEntryData::additional, ExecCopySlotMinimalTuple(), TupleHashEntryData::firstTuple, hash(), TupleHashTableData::hashtab, sort-test::key, MemoryContextSwitchTo(), and TupleHashTableData::tablecxt.

Referenced by LookupTupleHashEntry(), and LookupTupleHashEntryHash().

◆ LookupTupleHashEntryHash()

TupleHashEntry LookupTupleHashEntryHash ( TupleHashTable  hashtable,
TupleTableSlot slot,
bool isnew,
uint32  hash 
)

Definition at line 360 of file execGrouping.c.

362 {
363  TupleHashEntry entry;
364  MemoryContext oldContext;
365 
366  /* Need to run the hash functions in short-lived context */
367  oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
368 
369  /* set up data needed by hash and match functions */
370  hashtable->inputslot = slot;
371  hashtable->in_hash_funcs = hashtable->tab_hash_funcs;
372  hashtable->cur_eq_func = hashtable->tab_eq_func;
373 
374  entry = LookupTupleHashEntry_internal(hashtable, slot, isnew, hash);
375  Assert(entry == NULL || entry->hash == hash);
376 
377  MemoryContextSwitchTo(oldContext);
378 
379  return entry;
380 }

References Assert, TupleHashTableData::cur_eq_func, hash(), TupleHashEntryData::hash, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, LookupTupleHashEntry_internal(), MemoryContextSwitchTo(), TupleHashTableData::tab_eq_func, TupleHashTableData::tab_hash_funcs, and TupleHashTableData::tempcxt.

Referenced by agg_refill_hash_table().

◆ ResetTupleHashTable()

void ResetTupleHashTable ( TupleHashTable  hashtable)

Definition at line 284 of file execGrouping.c.

285 {
286  tuplehash_reset(hashtable->hashtab);
287 }

References TupleHashTableData::hashtab.

Referenced by agg_refill_hash_table(), build_hash_tables(), buildSubPlanHash(), ExecReScanRecursiveUnion(), and ExecReScanSetOp().

◆ TupleHashTableHash()

uint32 TupleHashTableHash ( TupleHashTable  hashtable,
TupleTableSlot slot 
)

Definition at line 337 of file execGrouping.c.

338 {
339  MemoryContext oldContext;
340  uint32 hash;
341 
342  hashtable->inputslot = slot;
343  hashtable->in_hash_funcs = hashtable->tab_hash_funcs;
344 
345  /* Need to run the hash functions in short-lived context */
346  oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
347 
348  hash = TupleHashTableHash_internal(hashtable->hashtab, NULL);
349 
350  MemoryContextSwitchTo(oldContext);
351 
352  return hash;
353 }

References hash(), TupleHashTableData::hashtab, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, MemoryContextSwitchTo(), TupleHashTableData::tab_hash_funcs, TupleHashTableData::tempcxt, and TupleHashTableHash_internal().

◆ TupleHashTableHash_internal()

static uint32 TupleHashTableHash_internal ( struct tuplehash_hash *  tb,
const MinimalTuple  tuple 
)
inlinestatic

Definition at line 425 of file execGrouping.c.

427 {
428  TupleHashTable hashtable = (TupleHashTable) tb->private_data;
429  int numCols = hashtable->numCols;
430  AttrNumber *keyColIdx = hashtable->keyColIdx;
431  uint32 hashkey = hashtable->hash_iv;
432  TupleTableSlot *slot;
433  FmgrInfo *hashfunctions;
434  int i;
435 
436  if (tuple == NULL)
437  {
438  /* Process the current input tuple for the table */
439  slot = hashtable->inputslot;
440  hashfunctions = hashtable->in_hash_funcs;
441  }
442  else
443  {
444  /*
445  * Process a tuple already stored in the table.
446  *
447  * (this case never actually occurs due to the way simplehash.h is
448  * used, as the hash-value is stored in the entries)
449  */
450  slot = hashtable->tableslot;
451  ExecStoreMinimalTuple(tuple, slot, false);
452  hashfunctions = hashtable->tab_hash_funcs;
453  }
454 
455  for (i = 0; i < numCols; i++)
456  {
457  AttrNumber att = keyColIdx[i];
458  Datum attr;
459  bool isNull;
460 
461  /* combine successive hashkeys by rotating */
462  hashkey = pg_rotate_left32(hashkey, 1);
463 
464  attr = slot_getattr(slot, att, &isNull);
465 
466  if (!isNull) /* treat nulls as having hash key 0 */
467  {
468  uint32 hkey;
469 
470  hkey = DatumGetUInt32(FunctionCall1Coll(&hashfunctions[i],
471  hashtable->tab_collations[i],
472  attr));
473  hashkey ^= hkey;
474  }
475  }
476 
477  /*
478  * The way hashes are combined above, among each other and with the IV,
479  * doesn't lead to good bit perturbation. As the IV's goal is to lead to
480  * achieve that, perform a round of hashing of the combined hash -
481  * resulting in near perfect perturbation.
482  */
483  return murmurhash32(hashkey);
484 }
int16 AttrNumber
Definition: attnum.h:21
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1533
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1129
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
static uint32 pg_rotate_left32(uint32 word, int n)
Definition: pg_bitutils.h:404
static uint32 DatumGetUInt32(Datum X)
Definition: postgres.h:222
uintptr_t Datum
Definition: postgres.h:64
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:395

References DatumGetUInt32(), ExecStoreMinimalTuple(), FunctionCall1Coll(), TupleHashTableData::hash_iv, i, if(), TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, TupleHashTableData::keyColIdx, murmurhash32(), TupleHashTableData::numCols, pg_rotate_left32(), slot_getattr(), TupleHashTableData::tab_collations, TupleHashTableData::tab_hash_funcs, and TupleHashTableData::tableslot.

Referenced by LookupTupleHashEntry(), and TupleHashTableHash().

◆ TupleHashTableMatch()

static int TupleHashTableMatch ( struct tuplehash_hash *  tb,
const MinimalTuple  tuple1,
const MinimalTuple  tuple2 
)
static

Definition at line 536 of file execGrouping.c.

537 {
538  TupleTableSlot *slot1;
539  TupleTableSlot *slot2;
540  TupleHashTable hashtable = (TupleHashTable) tb->private_data;
541  ExprContext *econtext = hashtable->exprcontext;
542 
543  /*
544  * We assume that simplehash.h will only ever call us with the first
545  * argument being an actual table entry, and the second argument being
546  * LookupTupleHashEntry's dummy TupleHashEntryData. The other direction
547  * could be supported too, but is not currently required.
548  */
549  Assert(tuple1 != NULL);
550  slot1 = hashtable->tableslot;
551  ExecStoreMinimalTuple(tuple1, slot1, false);
552  Assert(tuple2 == NULL);
553  slot2 = hashtable->inputslot;
554 
555  /* For crosstype comparisons, the inputslot must be first */
556  econtext->ecxt_innertuple = slot2;
557  econtext->ecxt_outertuple = slot1;
558  return !ExecQualAndReset(hashtable->cur_eq_func, econtext);
559 }
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition: executor.h:440

References Assert, TupleHashTableData::cur_eq_func, ExecQualAndReset(), ExecStoreMinimalTuple(), TupleHashTableData::exprcontext, TupleHashTableData::inputslot, and TupleHashTableData::tableslot.