36 #define SH_PREFIX tuplehash 37 #define SH_ELEMENT_TYPE TupleHashEntryData 38 #define SH_KEY_TYPE MinimalTuple 39 #define SH_KEY firstTuple 40 #define SH_HASH_KEY(tb, key) TupleHashTableHash_internal(tb, key) 41 #define SH_EQUAL(tb, a, b) TupleHashTableMatch(tb, a, b) == 0 42 #define SH_SCOPE extern 44 #define SH_GET_HASH(tb, a) a->hash 62 const Oid *eqOperators,
63 const Oid *collations,
74 for (i = 0; i < numCols; i++)
79 numCols, keyColIdx, eqFunctions, collations,
97 const Oid *eqOperators,
106 for (i = 0; i < numCols; i++)
108 Oid eq_opr = eqOperators[
i];
110 Oid left_hash_function;
111 Oid right_hash_function;
115 &left_hash_function, &right_hash_function))
116 elog(
ERROR,
"could not find hash function for hash operator %u",
119 Assert(left_hash_function == right_hash_function);
120 (*eqFuncOids)[
i] = eq_function;
121 fmgr_info(right_hash_function, &(*hashFunctions)[i]);
157 const Oid *eqfuncoids,
160 long nbuckets,
Size additionalsize,
164 bool use_variable_hash_iv)
175 nbuckets =
Min(nbuckets, (
long) ((hash_mem * 1024L) / entrysize));
201 if (use_variable_hash_iv)
206 hashtable->
hashtab = tuplehash_create(metacxt, nbuckets, hashtable);
223 allow_jit = metacxt != tablecxt;
230 keyColIdx, eqfuncoids, collations,
231 allow_jit ? parent : NULL);
256 const Oid *eqfuncoids,
259 long nbuckets,
Size additionalsize,
262 bool use_variable_hash_iv)
270 nbuckets, additionalsize,
274 use_variable_hash_iv);
285 tuplehash_reset(hashtable->
hashtab);
325 Assert(entry == NULL || entry->
hash == local_hash);
409 entry = tuplehash_lookup(hashtable->
hashtab, key);
428 int numCols = hashtable->
numCols;
454 for (
i = 0;
i < numCols;
i++)
461 hashkey = (hashkey << 1) | ((hashkey & 0x80000000) ? 1 : 0);
505 entry = tuplehash_insert_hash(hashtable->
hashtab, key, hash, &found);
525 entry = tuplehash_lookup_hash(hashtable->
hashtab, key, hash);
555 econtext->ecxt_innertuple = slot2;
556 econtext->ecxt_outertuple = slot1;
ExprContext * exprcontext
#define DatumGetUInt32(X)
ExprContext * CreateStandaloneExprContext(void)
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)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
bool get_op_hash_functions(Oid opno, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
TupleHashEntry LookupTupleHashEntryHash(TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 hash)
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
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)
TupleTableSlot * inputslot
static uint32 TupleHashTableHash_internal(struct tuplehash_hash *tb, const MinimalTuple tuple)
TupleHashEntry FindTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot, ExprState *eqcomp, FmgrInfo *hashfunctions)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static uint32 murmurhash32(uint32 data)
TupleHashEntry LookupTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 *hash)
void execTuplesHashPrepare(int numCols, const Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
void ResetTupleHashTable(TupleHashTable hashtable)
FmgrInfo * tab_hash_funcs
static int TupleHashTableMatch(struct tuplehash_hash *tb, const MinimalTuple tuple1, const MinimalTuple tuple2)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
struct TupleHashEntryData TupleHashEntryData
static TupleHashEntry LookupTupleHashEntry_internal(TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 hash)
static MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
struct TupleHashTableData * TupleHashTable
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
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)
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
RegProcedure get_opcode(Oid opno)
#define Assert(condition)
TupleTableSlot * tableslot
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
uint32 TupleHashTableHash(TupleHashTable hashtable, TupleTableSlot *slot)
static unsigned hash(unsigned *uv, int n)
const TupleTableSlotOps TTSOpsMinimalTuple