PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
execGrouping.c File Reference
#include "postgres.h"
#include <math.h>
#include "access/htup_details.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, MinimalTuple tuple1, MinimalTuple tuple2)
 
static uint32 TupleHashTableHash_internal (struct tuplehash_hash *tb, 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 BuildTupleHashTable (PlanState *parent, TupleDesc inputDesc, const TupleTableSlotOps *inputOps, int numCols, AttrNumber *keyColIdx, const Oid *eqfuncoids, FmgrInfo *hashfunctions, Oid *collations, double nelements, Size additionalsize, MemoryContext metacxt, MemoryContext tuplescxt, MemoryContext tempcxt, bool use_variable_hash_iv)
 
void ResetTupleHashTable (TupleHashTable hashtable)
 
Size EstimateTupleHashTableSpace (double nentries, Size tupleWidth, Size additionalsize)
 
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, ExprState *hashexpr)
 

Macro Definition Documentation

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 47 of file execGrouping.c.

◆ SH_ELEMENT_TYPE

#define SH_ELEMENT_TYPE   TupleHashEntryData

Definition at line 39 of file execGrouping.c.

◆ SH_EQUAL

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

Definition at line 43 of file execGrouping.c.

◆ SH_GET_HASH

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

Definition at line 46 of file execGrouping.c.

◆ SH_HASH_KEY

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

Definition at line 42 of file execGrouping.c.

◆ SH_KEY

#define SH_KEY   firstTuple

Definition at line 41 of file execGrouping.c.

◆ SH_KEY_TYPE

#define SH_KEY_TYPE   MinimalTuple

Definition at line 40 of file execGrouping.c.

◆ SH_PREFIX

#define SH_PREFIX   tuplehash

Definition at line 38 of file execGrouping.c.

◆ SH_SCOPE

#define SH_SCOPE   extern

Definition at line 44 of file execGrouping.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 45 of file execGrouping.c.

Function Documentation

◆ BuildTupleHashTable()

TupleHashTable BuildTupleHashTable ( PlanState parent,
TupleDesc  inputDesc,
const TupleTableSlotOps inputOps,
int  numCols,
AttrNumber keyColIdx,
const Oid eqfuncoids,
FmgrInfo hashfunctions,
Oid collations,
double  nelements,
Size  additionalsize,
MemoryContext  metacxt,
MemoryContext  tuplescxt,
MemoryContext  tempcxt,
bool  use_variable_hash_iv 
)

Definition at line 184 of file execGrouping.c.

198{
199 TupleHashTable hashtable;
200 uint32 nbuckets;
201 MemoryContext oldcontext;
202 uint32 hash_iv = 0;
203
204 /*
205 * tuplehash_create requires a uint32 element count, so we had better
206 * clamp the given nelements to fit in that. As long as we have to do
207 * that, we might as well protect against completely insane input like
208 * zero or NaN. But it is not our job here to enforce issues like staying
209 * within hash_mem: the caller should have done that, and we don't have
210 * enough info to second-guess.
211 */
212 if (isnan(nelements) || nelements <= 0)
213 nbuckets = 1;
214 else if (nelements >= PG_UINT32_MAX)
215 nbuckets = PG_UINT32_MAX;
216 else
217 nbuckets = (uint32) nelements;
218
219 /* tuplescxt must be separate, else ResetTupleHashTable breaks things */
220 Assert(metacxt != tuplescxt);
221
222 /* ensure additionalsize is maxalign'ed */
223 additionalsize = MAXALIGN(additionalsize);
224
225 oldcontext = MemoryContextSwitchTo(metacxt);
226
227 hashtable = (TupleHashTable) palloc(sizeof(TupleHashTableData));
228
229 hashtable->numCols = numCols;
230 hashtable->keyColIdx = keyColIdx;
231 hashtable->tab_collations = collations;
232 hashtable->tuplescxt = tuplescxt;
233 hashtable->tempcxt = tempcxt;
234 hashtable->additionalsize = additionalsize;
235 hashtable->tableslot = NULL; /* will be made on first lookup */
236 hashtable->inputslot = NULL;
237 hashtable->in_hash_expr = NULL;
238 hashtable->cur_eq_func = NULL;
239
240 /*
241 * If parallelism is in use, even if the leader backend is performing the
242 * scan itself, we don't want to create the hashtable exactly the same way
243 * in all workers. As hashtables are iterated over in keyspace-order,
244 * doing so in all processes in the same way is likely to lead to
245 * "unbalanced" hashtables when the table size initially is
246 * underestimated.
247 */
248 if (use_variable_hash_iv)
250
251 hashtable->hashtab = tuplehash_create(metacxt, nbuckets, hashtable);
252
253 /*
254 * We copy the input tuple descriptor just for safety --- we assume all
255 * input tuples will have equivalent descriptors.
256 */
259
260 /* build hash ExprState for all columns */
261 hashtable->tab_hash_expr = ExecBuildHash32FromAttrs(inputDesc,
262 inputOps,
263 hashfunctions,
264 collations,
265 numCols,
266 keyColIdx,
267 parent,
268 hash_iv);
269
270 /* build comparator for all columns */
271 hashtable->tab_eq_func = ExecBuildGroupingEqual(inputDesc, inputDesc,
272 inputOps,
274 numCols,
275 keyColIdx, eqfuncoids, collations,
276 parent);
277
278 /*
279 * While not pretty, it's ok to not shut down this context, but instead
280 * rely on the containing memory context being reset, as
281 * ExecBuildGroupingEqual() only builds a very simple expression calling
282 * functions (i.e. nothing that'd employ RegisterExprContextCallback()).
283 */
285
286 MemoryContextSwitchTo(oldcontext);
287
288 return hashtable;
289}
int ParallelWorkerNumber
Definition: parallel.c:115
#define MAXALIGN(LEN)
Definition: c.h:814
#define PG_UINT32_MAX
Definition: c.h:599
uint32_t uint32
Definition: c.h:542
ExprState * ExecBuildHash32FromAttrs(TupleDesc desc, const TupleTableSlotOps *ops, FmgrInfo *hashfunctions, Oid *collations, int numCols, AttrNumber *keyColIdx, PlanState *parent, uint32 init_value)
Definition: execExpr.c:4141
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:4465
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1427
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
ExprContext * CreateStandaloneExprContext(void)
Definition: execUtils.c:357
struct TupleHashTableData * TupleHashTable
Definition: execnodes.h:845
static uint32 murmurhash32(uint32 data)
Definition: hashfn.h:92
Assert(PointerIsAligned(start, uint64))
void * palloc(Size size)
Definition: mcxt.c:1365
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
AttrNumber * keyColIdx
Definition: execnodes.h:872
tuplehash_hash * hashtab
Definition: execnodes.h:870
ExprState * in_hash_expr
Definition: execnodes.h:882
ExprState * tab_hash_expr
Definition: execnodes.h:873
MemoryContext tempcxt
Definition: execnodes.h:877
ExprState * tab_eq_func
Definition: execnodes.h:874
TupleTableSlot * tableslot
Definition: execnodes.h:879
ExprContext * exprcontext
Definition: execnodes.h:884
TupleTableSlot * inputslot
Definition: execnodes.h:881
ExprState * cur_eq_func
Definition: execnodes.h:883
MemoryContext tuplescxt
Definition: execnodes.h:876
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:252

References TupleHashTableData::additionalsize, Assert(), CreateStandaloneExprContext(), CreateTupleDescCopy(), TupleHashTableData::cur_eq_func, ExecBuildGroupingEqual(), ExecBuildHash32FromAttrs(), TupleHashTableData::exprcontext, TupleHashTableData::hashtab, TupleHashTableData::in_hash_expr, TupleHashTableData::inputslot, TupleHashTableData::keyColIdx, MakeSingleTupleTableSlot(), MAXALIGN, MemoryContextSwitchTo(), murmurhash32(), TupleHashTableData::numCols, palloc(), ParallelWorkerNumber, PG_UINT32_MAX, TupleHashTableData::tab_collations, TupleHashTableData::tab_eq_func, TupleHashTableData::tab_hash_expr, TupleHashTableData::tableslot, TupleHashTableData::tempcxt, TTSOpsMinimalTuple, and TupleHashTableData::tuplescxt.

Referenced by build_hash_table(), and buildSubPlanHash().

◆ EstimateTupleHashTableSpace()

Size EstimateTupleHashTableSpace ( double  nentries,
Size  tupleWidth,
Size  additionalsize 
)

Definition at line 321 of file execGrouping.c.

324{
325 Size sh_space;
326 double tuples_space;
327
328 /* First estimate the space needed for the simplehash table */
329 sh_space = tuplehash_estimate_space(nentries);
330
331 /* Give up if that's already too big */
332 if (sh_space >= SIZE_MAX)
333 return sh_space;
334
335 /*
336 * Compute space needed for hashed tuples with additional data. nentries
337 * must be somewhat sane, so it should be safe to compute this product.
338 *
339 * We assume that the hashed tuples will be kept in a BumpContext so that
340 * there is not additional per-tuple overhead.
341 *
342 * (Note that this is only accurate if MEMORY_CONTEXT_CHECKING is off,
343 * else bump.c will add a MemoryChunk header to each tuple. However, it
344 * seems undesirable for debug builds to make different planning choices
345 * than production builds, so we assume the production behavior always.)
346 */
347 tuples_space = nentries * (MAXALIGN(SizeofMinimalTupleHeader) +
348 MAXALIGN(tupleWidth) +
349 MAXALIGN(additionalsize));
350
351 /*
352 * Check for size_t overflow. This coding is trickier than it may appear,
353 * because on 64-bit machines SIZE_MAX cannot be represented exactly as a
354 * double. We must cast it explicitly to suppress compiler warnings about
355 * an inexact conversion, and we must trust that any double value that
356 * compares strictly less than "(double) SIZE_MAX" will cast to a
357 * representable size_t value.
358 */
359 if (sh_space + tuples_space >= (double) SIZE_MAX)
360 return SIZE_MAX;
361
362 /* We don't bother estimating size of the miscellaneous overhead data */
363 return (Size) (sh_space + tuples_space);
364}
size_t Size
Definition: c.h:614
#define SizeofMinimalTupleHeader
Definition: htup_details.h:699

References MAXALIGN, and SizeofMinimalTupleHeader.

Referenced by EstimateSetOpHashTableSpace(), and EstimateSubplanHashTableSpace().

◆ execTuplesHashPrepare()

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

Definition at line 100 of file execGrouping.c.

104{
105 int i;
106
107 *eqFuncOids = (Oid *) palloc(numCols * sizeof(Oid));
108 *hashFunctions = (FmgrInfo *) palloc(numCols * sizeof(FmgrInfo));
109
110 for (i = 0; i < numCols; i++)
111 {
112 Oid eq_opr = eqOperators[i];
113 Oid eq_function;
114 Oid left_hash_function;
115 Oid right_hash_function;
116
117 eq_function = get_opcode(eq_opr);
118 if (!get_op_hash_functions(eq_opr,
119 &left_hash_function, &right_hash_function))
120 elog(ERROR, "could not find hash function for hash operator %u",
121 eq_opr);
122 /* We're not supporting cross-type cases here */
123 Assert(left_hash_function == right_hash_function);
124 (*eqFuncOids)[i] = eq_function;
125 fmgr_info(right_hash_function, &(*hashFunctions)[i]);
126 }
127}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:128
int i
Definition: isn.c:77
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1452
bool get_op_hash_functions(Oid opno, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
Definition: lsyscache.c:582
unsigned int Oid
Definition: postgres_ext.h:32
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 61 of file execGrouping.c.

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

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

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

◆ FindTupleHashEntry()

TupleHashEntry FindTupleHashEntry ( TupleHashTable  hashtable,
TupleTableSlot slot,
ExprState eqcomp,
ExprState hashexpr 
)

Definition at line 469 of file execGrouping.c.

472{
473 TupleHashEntry entry;
474 MemoryContext oldContext;
476
477 /* Need to run the hash functions in short-lived context */
478 oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
479
480 /* Set up data needed by hash and match functions */
481 hashtable->inputslot = slot;
482 hashtable->in_hash_expr = hashexpr;
483 hashtable->cur_eq_func = eqcomp;
484
485 /* Search the hash table */
486 key = NULL; /* flag to reference inputslot */
487 entry = tuplehash_lookup(hashtable->hashtab, key);
488 MemoryContextSwitchTo(oldContext);
489
490 return entry;
491}

References TupleHashTableData::cur_eq_func, TupleHashTableData::hashtab, TupleHashTableData::in_hash_expr, 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 382 of file execGrouping.c.

384{
385 TupleHashEntry entry;
386 MemoryContext oldContext;
387 uint32 local_hash;
388
389 /* Need to run the hash functions in short-lived context */
390 oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
391
392 /* set up data needed by hash and match functions */
393 hashtable->inputslot = slot;
394 hashtable->in_hash_expr = hashtable->tab_hash_expr;
395 hashtable->cur_eq_func = hashtable->tab_eq_func;
396
397 local_hash = TupleHashTableHash_internal(hashtable->hashtab, NULL);
398 entry = LookupTupleHashEntry_internal(hashtable, slot, isnew, local_hash);
399
400 if (hash != NULL)
401 *hash = local_hash;
402
403 Assert(entry == NULL || entry->hash == local_hash);
404
405 MemoryContextSwitchTo(oldContext);
406
407 return entry;
408}
static uint32 TupleHashTableHash_internal(struct tuplehash_hash *tb, MinimalTuple tuple)
Definition: execGrouping.c:502
static TupleHashEntry LookupTupleHashEntry_internal(TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 hash)
Definition: execGrouping.c:550
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_expr, TupleHashTableData::inputslot, LookupTupleHashEntry_internal(), MemoryContextSwitchTo(), TupleHashTableData::tab_eq_func, TupleHashTableData::tab_hash_expr, 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 550 of file execGrouping.c.

552{
553 TupleHashEntryData *entry;
554 bool found;
556
557 key = NULL; /* flag to reference inputslot */
558
559 if (isnew)
560 {
561 entry = tuplehash_insert_hash(hashtable->hashtab, key, hash, &found);
562
563 if (found)
564 {
565 /* found pre-existing entry */
566 *isnew = false;
567 }
568 else
569 {
570 /* created new entry */
571 *isnew = true;
572
574
575 /*
576 * Copy the first tuple into the tuples context, and request
577 * additionalsize extra bytes before the allocation.
578 *
579 * The caller can get a pointer to the additional data with
580 * TupleHashEntryGetAdditional(), and store arbitrary data there.
581 * Placing both the tuple and additional data in the same
582 * allocation avoids the need to store an extra pointer in
583 * TupleHashEntryData or allocate an additional chunk.
584 */
586 hashtable->additionalsize);
587 }
588 }
589 else
590 {
591 entry = tuplehash_lookup_hash(hashtable->hashtab, key, hash);
592 }
593
594 return entry;
595}
MinimalTuple firstTuple
Definition: execnodes.h:855
static MinimalTuple ExecCopySlotMinimalTupleExtra(TupleTableSlot *slot, Size extra)
Definition: tuptable.h:507

References TupleHashTableData::additionalsize, ExecCopySlotMinimalTupleExtra(), TupleHashEntryData::firstTuple, hash(), TupleHashTableData::hashtab, sort-test::key, MemoryContextSwitchTo(), and TupleHashTableData::tuplescxt.

Referenced by LookupTupleHashEntry(), and LookupTupleHashEntryHash().

◆ LookupTupleHashEntryHash()

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

Definition at line 437 of file execGrouping.c.

439{
440 TupleHashEntry entry;
441 MemoryContext oldContext;
442
443 /* Need to run the hash functions in short-lived context */
444 oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
445
446 /* set up data needed by hash and match functions */
447 hashtable->inputslot = slot;
448 hashtable->in_hash_expr = hashtable->tab_hash_expr;
449 hashtable->cur_eq_func = hashtable->tab_eq_func;
450
451 entry = LookupTupleHashEntry_internal(hashtable, slot, isnew, hash);
452 Assert(entry == NULL || entry->hash == hash);
453
454 MemoryContextSwitchTo(oldContext);
455
456 return entry;
457}

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

Referenced by agg_refill_hash_table().

◆ ResetTupleHashTable()

void ResetTupleHashTable ( TupleHashTable  hashtable)

Definition at line 302 of file execGrouping.c.

303{
304 tuplehash_reset(hashtable->hashtab);
305 MemoryContextReset(hashtable->tuplescxt);
306}
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:400

References TupleHashTableData::hashtab, MemoryContextReset(), and TupleHashTableData::tuplescxt.

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

◆ TupleHashTableHash()

uint32 TupleHashTableHash ( TupleHashTable  hashtable,
TupleTableSlot slot 
)

Definition at line 414 of file execGrouping.c.

415{
416 MemoryContext oldContext;
417 uint32 hash;
418
419 hashtable->inputslot = slot;
420 hashtable->in_hash_expr = hashtable->tab_hash_expr;
421
422 /* Need to run the hash functions in short-lived context */
423 oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
424
425 hash = TupleHashTableHash_internal(hashtable->hashtab, NULL);
426
427 MemoryContextSwitchTo(oldContext);
428
429 return hash;
430}

References hash(), TupleHashTableData::hashtab, TupleHashTableData::in_hash_expr, TupleHashTableData::inputslot, MemoryContextSwitchTo(), TupleHashTableData::tab_hash_expr, TupleHashTableData::tempcxt, and TupleHashTableHash_internal().

◆ TupleHashTableHash_internal()

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

Definition at line 502 of file execGrouping.c.

504{
505 TupleHashTable hashtable = (TupleHashTable) tb->private_data;
506 uint32 hashkey;
507 TupleTableSlot *slot;
508 bool isnull;
509
510 if (tuple == NULL)
511 {
512 /* Process the current input tuple for the table */
513 hashtable->exprcontext->ecxt_innertuple = hashtable->inputslot;
514 hashkey = DatumGetUInt32(ExecEvalExpr(hashtable->in_hash_expr,
515 hashtable->exprcontext,
516 &isnull));
517 }
518 else
519 {
520 /*
521 * Process a tuple already stored in the table.
522 *
523 * (this case never actually occurs due to the way simplehash.h is
524 * used, as the hash-value is stored in the entries)
525 */
526 slot = hashtable->exprcontext->ecxt_innertuple = hashtable->tableslot;
527 ExecStoreMinimalTuple(tuple, slot, false);
528 hashkey = DatumGetUInt32(ExecEvalExpr(hashtable->tab_hash_expr,
529 hashtable->exprcontext,
530 &isnull));
531 }
532
533 /*
534 * The hashing done above, even with an initial value, doesn't tend to
535 * result in good hash perturbation. Running the value produced above
536 * through murmurhash32 leads to near perfect hash perturbation.
537 */
538 return murmurhash32(hashkey);
539}
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1635
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
Definition: executor.h:393
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
static uint32 DatumGetUInt32(Datum X)
Definition: postgres.h:232
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:275

References DatumGetUInt32(), ExprContext::ecxt_innertuple, ExecEvalExpr(), ExecStoreMinimalTuple(), TupleHashTableData::exprcontext, if(), TupleHashTableData::in_hash_expr, TupleHashTableData::inputslot, murmurhash32(), TupleHashTableData::tab_hash_expr, and TupleHashTableData::tableslot.

Referenced by LookupTupleHashEntry(), and TupleHashTableHash().

◆ TupleHashTableMatch()

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

Definition at line 601 of file execGrouping.c.

602{
603 TupleTableSlot *slot1;
604 TupleTableSlot *slot2;
605 TupleHashTable hashtable = (TupleHashTable) tb->private_data;
606 ExprContext *econtext = hashtable->exprcontext;
607
608 /*
609 * We assume that simplehash.h will only ever call us with the first
610 * argument being an actual table entry, and the second argument being
611 * LookupTupleHashEntry's dummy TupleHashEntryData. The other direction
612 * could be supported too, but is not currently required.
613 */
614 Assert(tuple1 != NULL);
615 slot1 = hashtable->tableslot;
616 ExecStoreMinimalTuple(tuple1, slot1, false);
617 Assert(tuple2 == NULL);
618 slot2 = hashtable->inputslot;
619
620 /* For crosstype comparisons, the inputslot must be first */
621 econtext->ecxt_innertuple = slot2;
622 econtext->ecxt_outertuple = slot1;
623 return !ExecQualAndReset(hashtable->cur_eq_func, econtext);
624}
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition: executor.h:546

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