PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
execGrouping.c File Reference
#include "postgres.h"
#include "access/hash.h"
#include "access/parallel.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "utils/lsyscache.h"
#include "utils/memutils.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(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 uint32 TupleHashTableHash (struct tuplehash_hash *tb, const MinimalTuple tuple)
 
static int TupleHashTableMatch (struct tuplehash_hash *tb, const MinimalTuple tuple1, const MinimalTuple tuple2)
 
bool execTuplesMatch (TupleTableSlot *slot1, TupleTableSlot *slot2, int numCols, AttrNumber *matchColIdx, FmgrInfo *eqfunctions, MemoryContext evalContext)
 
bool execTuplesUnequal (TupleTableSlot *slot1, TupleTableSlot *slot2, int numCols, AttrNumber *matchColIdx, FmgrInfo *eqfunctions, MemoryContext evalContext)
 
FmgrInfoexecTuplesMatchPrepare (int numCols, Oid *eqOperators)
 
void execTuplesHashPrepare (int numCols, Oid *eqOperators, FmgrInfo **eqFunctions, FmgrInfo **hashFunctions)
 
TupleHashTable BuildTupleHashTable (int numCols, AttrNumber *keyColIdx, FmgrInfo *eqfunctions, FmgrInfo *hashfunctions, long nbuckets, Size additionalsize, MemoryContext tablecxt, MemoryContext tempcxt, bool use_variable_hash_iv)
 
TupleHashEntry LookupTupleHashEntry (TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew)
 
TupleHashEntry FindTupleHashEntry (TupleHashTable hashtable, TupleTableSlot *slot, FmgrInfo *eqfunctions, FmgrInfo *hashfunctions)
 

Macro Definition Documentation

#define SH_DEFINE

Definition at line 45 of file execGrouping.c.

#define SH_ELEMENT_TYPE   TupleHashEntryData

Definition at line 37 of file execGrouping.c.

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

Definition at line 41 of file execGrouping.c.

#define SH_GET_HASH (   tb,
 
)    a->hash

Definition at line 44 of file execGrouping.c.

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

Definition at line 40 of file execGrouping.c.

#define SH_KEY   firstTuple

Definition at line 39 of file execGrouping.c.

#define SH_KEY_TYPE   MinimalTuple

Definition at line 38 of file execGrouping.c.

#define SH_PREFIX   tuplehash

Definition at line 36 of file execGrouping.c.

#define SH_SCOPE   extern

Definition at line 42 of file execGrouping.c.

#define SH_STORE_HASH

Definition at line 43 of file execGrouping.c.

Function Documentation

TupleHashTable BuildTupleHashTable ( int  numCols,
AttrNumber keyColIdx,
FmgrInfo eqfunctions,
FmgrInfo hashfunctions,
long  nbuckets,
Size  additionalsize,
MemoryContext  tablecxt,
MemoryContext  tempcxt,
bool  use_variable_hash_iv 
)

Definition at line 290 of file execGrouping.c.

References Assert, TupleHashTableData::cur_eq_funcs, TupleHashTableData::entrysize, TupleHashTableData::hash_iv, hash_uint32(), TupleHashTableData::hashtab, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, TupleHashTableData::keyColIdx, MemoryContextAlloc(), Min, NULL, TupleHashTableData::numCols, ParallelWorkerNumber, TupleHashTableData::tab_eq_funcs, TupleHashTableData::tab_hash_funcs, TupleHashTableData::tablecxt, TupleHashTableData::tableslot, TupleHashTableData::tempcxt, and work_mem.

Referenced by build_hash_table(), and buildSubPlanHash().

296 {
297  TupleHashTable hashtable;
298  Size entrysize = sizeof(TupleHashEntryData) + additionalsize;
299 
300  Assert(nbuckets > 0);
301 
302  /* Limit initial table size request to not more than work_mem */
303  nbuckets = Min(nbuckets, (long) ((work_mem * 1024L) / entrysize));
304 
305  hashtable = (TupleHashTable)
306  MemoryContextAlloc(tablecxt, sizeof(TupleHashTableData));
307 
308  hashtable->numCols = numCols;
309  hashtable->keyColIdx = keyColIdx;
310  hashtable->tab_hash_funcs = hashfunctions;
311  hashtable->tab_eq_funcs = eqfunctions;
312  hashtable->tablecxt = tablecxt;
313  hashtable->tempcxt = tempcxt;
314  hashtable->entrysize = entrysize;
315  hashtable->tableslot = NULL; /* will be made on first lookup */
316  hashtable->inputslot = NULL;
317  hashtable->in_hash_funcs = NULL;
318  hashtable->cur_eq_funcs = NULL;
319 
320  /*
321  * If parallelism is in use, even if the master backend is performing the
322  * scan itself, we don't want to create the hashtable exactly the same way
323  * in all workers. As hashtables are iterated over in keyspace-order,
324  * doing so in all processes in the same way is likely to lead to
325  * "unbalanced" hashtables when the table size initially is
326  * underestimated.
327  */
328  if (use_variable_hash_iv)
330  else
331  hashtable->hash_iv = 0;
332 
333  hashtable->hashtab = tuplehash_create(tablecxt, nbuckets, hashtable);
334 
335  return hashtable;
336 }
TupleTableSlot * inputslot
Definition: execnodes.h:541
#define Min(x, y)
Definition: c.h:802
AttrNumber * keyColIdx
Definition: execnodes.h:533
FmgrInfo * tab_hash_funcs
Definition: execnodes.h:534
FmgrInfo * in_hash_funcs
Definition: execnodes.h:542
struct TupleHashEntryData TupleHashEntryData
MemoryContext tablecxt
Definition: execnodes.h:536
struct TupleHashTableData * TupleHashTable
Definition: execnodes.h:511
int ParallelWorkerNumber
Definition: parallel.c:96
Datum hash_uint32(uint32 k)
Definition: hashfunc.c:512
int work_mem
Definition: globals.c:112
tuplehash_hash * hashtab
Definition: execnodes.h:531
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
TupleTableSlot * tableslot
Definition: execnodes.h:539
size_t Size
Definition: c.h:353
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:749
FmgrInfo * cur_eq_funcs
Definition: execnodes.h:543
MemoryContext tempcxt
Definition: execnodes.h:537
FmgrInfo * tab_eq_funcs
Definition: execnodes.h:535
void execTuplesHashPrepare ( int  numCols,
Oid eqOperators,
FmgrInfo **  eqFunctions,
FmgrInfo **  hashFunctions 
)

Definition at line 233 of file execGrouping.c.

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

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

237 {
238  int i;
239 
240  *eqFunctions = (FmgrInfo *) palloc(numCols * sizeof(FmgrInfo));
241  *hashFunctions = (FmgrInfo *) palloc(numCols * sizeof(FmgrInfo));
242 
243  for (i = 0; i < numCols; i++)
244  {
245  Oid eq_opr = eqOperators[i];
246  Oid eq_function;
247  Oid left_hash_function;
248  Oid right_hash_function;
249 
250  eq_function = get_opcode(eq_opr);
251  if (!get_op_hash_functions(eq_opr,
252  &left_hash_function, &right_hash_function))
253  elog(ERROR, "could not find hash function for hash operator %u",
254  eq_opr);
255  /* We're not supporting cross-type cases here */
256  Assert(left_hash_function == right_hash_function);
257  fmgr_info(eq_function, &(*eqFunctions)[i]);
258  fmgr_info(right_hash_function, &(*hashFunctions)[i]);
259  }
260 }
Definition: fmgr.h:53
bool get_op_hash_functions(Oid opno, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
Definition: lsyscache.c:507
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1062
#define Assert(condition)
Definition: c.h:671
void * palloc(Size size)
Definition: mcxt.c:891
int i
#define elog
Definition: elog.h:219
bool execTuplesMatch ( TupleTableSlot slot1,
TupleTableSlot slot2,
int  numCols,
AttrNumber matchColIdx,
FmgrInfo eqfunctions,
MemoryContext  evalContext 
)

Definition at line 69 of file execGrouping.c.

References DatumGetBool, FunctionCall2, i, MemoryContextReset(), MemoryContextSwitchTo(), and slot_getattr().

Referenced by agg_retrieve_direct(), are_peers(), ExecGroup(), ExecUnique(), hypothetical_dense_rank_final(), process_ordered_aggregate_multi(), setop_retrieve_direct(), spool_tuples(), and TupleHashTableMatch().

75 {
76  MemoryContext oldContext;
77  bool result;
78  int i;
79 
80  /* Reset and switch into the temp context. */
81  MemoryContextReset(evalContext);
82  oldContext = MemoryContextSwitchTo(evalContext);
83 
84  /*
85  * We cannot report a match without checking all the fields, but we can
86  * report a non-match as soon as we find unequal fields. So, start
87  * comparing at the last field (least significant sort key). That's the
88  * most likely to be different if we are dealing with sorted input.
89  */
90  result = true;
91 
92  for (i = numCols; --i >= 0;)
93  {
94  AttrNumber att = matchColIdx[i];
95  Datum attr1,
96  attr2;
97  bool isNull1,
98  isNull2;
99 
100  attr1 = slot_getattr(slot1, att, &isNull1);
101 
102  attr2 = slot_getattr(slot2, att, &isNull2);
103 
104  if (isNull1 != isNull2)
105  {
106  result = false; /* one null and one not; they aren't equal */
107  break;
108  }
109 
110  if (isNull1)
111  continue; /* both are null, treat as equal */
112 
113  /* Apply the type-specific equality function */
114 
115  if (!DatumGetBool(FunctionCall2(&eqfunctions[i],
116  attr1, attr2)))
117  {
118  result = false; /* they aren't equal */
119  break;
120  }
121  }
122 
123  MemoryContextSwitchTo(oldContext);
124 
125  return result;
126 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define FunctionCall2(flinfo, arg1, arg2)
Definition: fmgr.h:575
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:135
#define DatumGetBool(X)
Definition: postgres.h:401
uintptr_t Datum
Definition: postgres.h:374
int i
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: heaptuple.c:1143
int16 AttrNumber
Definition: attnum.h:21
FmgrInfo* execTuplesMatchPrepare ( int  numCols,
Oid eqOperators 
)

Definition at line 204 of file execGrouping.c.

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

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

206 {
207  FmgrInfo *eqFunctions = (FmgrInfo *) palloc(numCols * sizeof(FmgrInfo));
208  int i;
209 
210  for (i = 0; i < numCols; i++)
211  {
212  Oid eq_opr = eqOperators[i];
213  Oid eq_function;
214 
215  eq_function = get_opcode(eq_opr);
216  fmgr_info(eq_function, &eqFunctions[i]);
217  }
218 
219  return eqFunctions;
220 }
Definition: fmgr.h:53
unsigned int Oid
Definition: postgres_ext.h:31
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:159
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1062
void * palloc(Size size)
Definition: mcxt.c:891
int i
bool execTuplesUnequal ( TupleTableSlot slot1,
TupleTableSlot slot2,
int  numCols,
AttrNumber matchColIdx,
FmgrInfo eqfunctions,
MemoryContext  evalContext 
)

Definition at line 139 of file execGrouping.c.

References DatumGetBool, FunctionCall2, i, MemoryContextReset(), MemoryContextSwitchTo(), and slot_getattr().

Referenced by findPartialMatch().

145 {
146  MemoryContext oldContext;
147  bool result;
148  int i;
149 
150  /* Reset and switch into the temp context. */
151  MemoryContextReset(evalContext);
152  oldContext = MemoryContextSwitchTo(evalContext);
153 
154  /*
155  * We cannot report a match without checking all the fields, but we can
156  * report a non-match as soon as we find unequal fields. So, start
157  * comparing at the last field (least significant sort key). That's the
158  * most likely to be different if we are dealing with sorted input.
159  */
160  result = false;
161 
162  for (i = numCols; --i >= 0;)
163  {
164  AttrNumber att = matchColIdx[i];
165  Datum attr1,
166  attr2;
167  bool isNull1,
168  isNull2;
169 
170  attr1 = slot_getattr(slot1, att, &isNull1);
171 
172  if (isNull1)
173  continue; /* can't prove anything here */
174 
175  attr2 = slot_getattr(slot2, att, &isNull2);
176 
177  if (isNull2)
178  continue; /* can't prove anything here */
179 
180  /* Apply the type-specific equality function */
181 
182  if (!DatumGetBool(FunctionCall2(&eqfunctions[i],
183  attr1, attr2)))
184  {
185  result = true; /* they are unequal */
186  break;
187  }
188  }
189 
190  MemoryContextSwitchTo(oldContext);
191 
192  return result;
193 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define FunctionCall2(flinfo, arg1, arg2)
Definition: fmgr.h:575
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:135
#define DatumGetBool(X)
Definition: postgres.h:401
uintptr_t Datum
Definition: postgres.h:374
int i
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: heaptuple.c:1143
int16 AttrNumber
Definition: attnum.h:21
TupleHashEntry FindTupleHashEntry ( TupleHashTable  hashtable,
TupleTableSlot slot,
FmgrInfo eqfunctions,
FmgrInfo hashfunctions 
)

Definition at line 425 of file execGrouping.c.

References TupleHashTableData::cur_eq_funcs, TupleHashTableData::hashtab, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, MemoryContextSwitchTo(), NULL, and TupleHashTableData::tempcxt.

Referenced by ExecHashSubPlan().

428 {
429  TupleHashEntry entry;
430  MemoryContext oldContext;
431  MinimalTuple key;
432 
433  /* Need to run the hash functions in short-lived context */
434  oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
435 
436  /* Set up data needed by hash and match functions */
437  hashtable->inputslot = slot;
438  hashtable->in_hash_funcs = hashfunctions;
439  hashtable->cur_eq_funcs = eqfunctions;
440 
441  /* Search the hash table */
442  key = NULL; /* flag to reference inputslot */
443  entry = tuplehash_lookup(hashtable->hashtab, key);
444  MemoryContextSwitchTo(oldContext);
445 
446  return entry;
447 }
TupleTableSlot * inputslot
Definition: execnodes.h:541
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
FmgrInfo * in_hash_funcs
Definition: execnodes.h:542
tuplehash_hash * hashtab
Definition: execnodes.h:531
#define NULL
Definition: c.h:226
FmgrInfo * cur_eq_funcs
Definition: execnodes.h:543
MemoryContext tempcxt
Definition: execnodes.h:537
TupleHashEntry LookupTupleHashEntry ( TupleHashTable  hashtable,
TupleTableSlot slot,
bool isnew 
)

Definition at line 351 of file execGrouping.c.

References TupleHashEntryData::additional, CreateTupleDescCopy(), TupleHashTableData::cur_eq_funcs, ExecCopySlotMinimalTuple(), TupleHashEntryData::firstTuple, TupleHashTableData::hashtab, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, MakeSingleTupleTableSlot(), MemoryContextSwitchTo(), NULL, TupleHashTableData::tab_eq_funcs, TupleHashTableData::tab_hash_funcs, TupleHashTableData::tablecxt, TupleHashTableData::tableslot, TupleHashTableData::tempcxt, and TupleTableSlot::tts_tupleDescriptor.

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

353 {
354  TupleHashEntryData *entry;
355  MemoryContext oldContext;
356  bool found;
357  MinimalTuple key;
358 
359  /* If first time through, clone the input slot to make table slot */
360  if (hashtable->tableslot == NULL)
361  {
362  TupleDesc tupdesc;
363 
364  oldContext = MemoryContextSwitchTo(hashtable->tablecxt);
365 
366  /*
367  * We copy the input tuple descriptor just for safety --- we assume
368  * all input tuples will have equivalent descriptors.
369  */
370  tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
371  hashtable->tableslot = MakeSingleTupleTableSlot(tupdesc);
372  MemoryContextSwitchTo(oldContext);
373  }
374 
375  /* Need to run the hash functions in short-lived context */
376  oldContext = MemoryContextSwitchTo(hashtable->tempcxt);
377 
378  /* set up data needed by hash and match functions */
379  hashtable->inputslot = slot;
380  hashtable->in_hash_funcs = hashtable->tab_hash_funcs;
381  hashtable->cur_eq_funcs = hashtable->tab_eq_funcs;
382 
383  key = NULL; /* flag to reference inputslot */
384 
385  if (isnew)
386  {
387  entry = tuplehash_insert(hashtable->hashtab, key, &found);
388 
389  if (found)
390  {
391  /* found pre-existing entry */
392  *isnew = false;
393  }
394  else
395  {
396  /* created new entry */
397  *isnew = true;
398  /* zero caller data */
399  entry->additional = NULL;
400  MemoryContextSwitchTo(hashtable->tablecxt);
401  /* Copy the first tuple into the table context */
402  entry->firstTuple = ExecCopySlotMinimalTuple(slot);
403  }
404  }
405  else
406  {
407  entry = tuplehash_lookup(hashtable->hashtab, key);
408  }
409 
410  MemoryContextSwitchTo(oldContext);
411 
412  return entry;
413 }
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:141
TupleTableSlot * inputslot
Definition: execnodes.h:541
MinimalTuple firstTuple
Definition: execnodes.h:515
MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
Definition: execTuples.c:577
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
FmgrInfo * tab_hash_funcs
Definition: execnodes.h:534
FmgrInfo * in_hash_funcs
Definition: execnodes.h:542
MemoryContext tablecxt
Definition: execnodes.h:536
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc)
Definition: execTuples.c:199
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
tuplehash_hash * hashtab
Definition: execnodes.h:531
#define NULL
Definition: c.h:226
TupleTableSlot * tableslot
Definition: execnodes.h:539
FmgrInfo * cur_eq_funcs
Definition: execnodes.h:543
MemoryContext tempcxt
Definition: execnodes.h:537
FmgrInfo * tab_eq_funcs
Definition: execnodes.h:535
static uint32 TupleHashTableHash ( struct tuplehash_hash *  tb,
const MinimalTuple  tuple 
)
static

Definition at line 463 of file execGrouping.c.

References DatumGetUInt32, ExecStoreMinimalTuple(), FunctionCall1, TupleHashTableData::hash_iv, i, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, TupleHashTableData::keyColIdx, NULL, TupleHashTableData::numCols, slot_getattr(), TupleHashTableData::tab_hash_funcs, and TupleHashTableData::tableslot.

464 {
465  TupleHashTable hashtable = (TupleHashTable) tb->private_data;
466  int numCols = hashtable->numCols;
467  AttrNumber *keyColIdx = hashtable->keyColIdx;
468  uint32 hashkey = hashtable->hash_iv;
469  TupleTableSlot *slot;
470  FmgrInfo *hashfunctions;
471  int i;
472 
473  if (tuple == NULL)
474  {
475  /* Process the current input tuple for the table */
476  slot = hashtable->inputslot;
477  hashfunctions = hashtable->in_hash_funcs;
478  }
479  else
480  {
481  /*
482  * Process a tuple already stored in the table.
483  *
484  * (this case never actually occurs due to the way simplehash.h is
485  * used, as the hash-value is stored in the entries)
486  */
487  slot = hashtable->tableslot;
488  ExecStoreMinimalTuple(tuple, slot, false);
489  hashfunctions = hashtable->tab_hash_funcs;
490  }
491 
492  for (i = 0; i < numCols; i++)
493  {
494  AttrNumber att = keyColIdx[i];
495  Datum attr;
496  bool isNull;
497 
498  /* rotate hashkey left 1 bit at each step */
499  hashkey = (hashkey << 1) | ((hashkey & 0x80000000) ? 1 : 0);
500 
501  attr = slot_getattr(slot, att, &isNull);
502 
503  if (!isNull) /* treat nulls as having hash key 0 */
504  {
505  uint32 hkey;
506 
507  hkey = DatumGetUInt32(FunctionCall1(&hashfunctions[i],
508  attr));
509  hashkey ^= hkey;
510  }
511  }
512 
513  return hashkey;
514 }
#define DatumGetUInt32(X)
Definition: postgres.h:494
Definition: fmgr.h:53
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:384
TupleTableSlot * inputslot
Definition: execnodes.h:541
AttrNumber * keyColIdx
Definition: execnodes.h:533
FmgrInfo * tab_hash_funcs
Definition: execnodes.h:534
FmgrInfo * in_hash_funcs
Definition: execnodes.h:542
struct TupleHashTableData * TupleHashTable
Definition: execnodes.h:511
unsigned int uint32
Definition: c.h:265
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
TupleTableSlot * tableslot
Definition: execnodes.h:539
int i
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:573
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: heaptuple.c:1143
int16 AttrNumber
Definition: attnum.h:21
static int TupleHashTableMatch ( struct tuplehash_hash *  tb,
const MinimalTuple  tuple1,
const MinimalTuple  tuple2 
)
static

Definition at line 525 of file execGrouping.c.

References Assert, TupleHashTableData::cur_eq_funcs, ExecStoreMinimalTuple(), execTuplesMatch(), TupleHashTableData::inputslot, TupleHashTableData::keyColIdx, NULL, TupleHashTableData::numCols, TupleHashTableData::tableslot, and TupleHashTableData::tempcxt.

526 {
527  TupleTableSlot *slot1;
528  TupleTableSlot *slot2;
529  TupleHashTable hashtable = (TupleHashTable) tb->private_data;
530 
531  /*
532  * We assume that simplehash.h will only ever call us with the first
533  * argument being an actual table entry, and the second argument being
534  * LookupTupleHashEntry's dummy TupleHashEntryData. The other direction
535  * could be supported too, but is not currently required.
536  */
537  Assert(tuple1 != NULL);
538  slot1 = hashtable->tableslot;
539  ExecStoreMinimalTuple(tuple1, slot1, false);
540  Assert(tuple2 == NULL);
541  slot2 = hashtable->inputslot;
542 
543  /* For crosstype comparisons, the inputslot must be first */
544  if (execTuplesMatch(slot2,
545  slot1,
546  hashtable->numCols,
547  hashtable->keyColIdx,
548  hashtable->cur_eq_funcs,
549  hashtable->tempcxt))
550  return 0;
551  else
552  return 1;
553 }
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:384
TupleTableSlot * inputslot
Definition: execnodes.h:541
AttrNumber * keyColIdx
Definition: execnodes.h:533
bool execTuplesMatch(TupleTableSlot *slot1, TupleTableSlot *slot2, int numCols, AttrNumber *matchColIdx, FmgrInfo *eqfunctions, MemoryContext evalContext)
Definition: execGrouping.c:69
struct TupleHashTableData * TupleHashTable
Definition: execnodes.h:511
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
TupleTableSlot * tableslot
Definition: execnodes.h:539
FmgrInfo * cur_eq_funcs
Definition: execnodes.h:543
MemoryContext tempcxt
Definition: execnodes.h:537