From: Andres Freund Date: Tue, 14 Mar 2017 03:22:10 +0000 (-0700) Subject: WIP: Cache hash functions in nodeHash.c. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=796dd46a6bf220a8864e59248b6081f7f6aefe8c;p=users%2Fandresfreund%2Fpostgres.git WIP: Cache hash functions in nodeHash.c. Author: Reviewed-By: Discussion: https://postgr.es/m/ Backpatch: --- diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index cfc6b96093..21408f1c2d 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -317,6 +317,10 @@ ExecHashTableCreate(Hash *node, List *hashOperators, bool keepNulls) (FmgrInfo *) palloc(nkeys * sizeof(FmgrInfo)); hashtable->inner_hashfunctions = (FmgrInfo *) palloc(nkeys * sizeof(FmgrInfo)); + hashtable->outer_hashfunctioncalls = + (FunctionCallInfoData *) palloc(nkeys * sizeof(FunctionCallInfoData)); + hashtable->inner_hashfunctioncalls = + (FunctionCallInfoData *) palloc(nkeys * sizeof(FunctionCallInfoData)); hashtable->hashStrict = (bool *) palloc(nkeys * sizeof(bool)); i = 0; foreach(ho, hashOperators) @@ -329,7 +333,13 @@ ExecHashTableCreate(Hash *node, List *hashOperators, bool keepNulls) elog(ERROR, "could not find hash function for hash operator %u", hashop); fmgr_info(left_hashfn, &hashtable->outer_hashfunctions[i]); + InitFunctionCallInfoData(hashtable->outer_hashfunctioncalls[i], + &hashtable->outer_hashfunctions[i], + 1, InvalidOid, NULL, NULL); fmgr_info(right_hashfn, &hashtable->inner_hashfunctions[i]); + InitFunctionCallInfoData(hashtable->inner_hashfunctioncalls[i], + &hashtable->inner_hashfunctions[i], + 1, InvalidOid, NULL, NULL); hashtable->hashStrict[i] = op_strict(hashop); i++; } @@ -928,7 +938,7 @@ ExecHashGetHashValue(HashJoinTable hashtable, uint32 *hashvalue) { uint32 hashkey = 0; - FmgrInfo *hashfunctions; + FunctionCallInfo hashfunctions; ListCell *hk; int i = 0; MemoryContext oldContext; @@ -942,9 +952,9 @@ ExecHashGetHashValue(HashJoinTable hashtable, oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory); if (outer_tuple) - hashfunctions = hashtable->outer_hashfunctions; + hashfunctions = hashtable->outer_hashfunctioncalls; else - hashfunctions = hashtable->inner_hashfunctions; + hashfunctions = hashtable->inner_hashfunctioncalls; foreach(hk, hashkeys) { @@ -986,12 +996,13 @@ ExecHashGetHashValue(HashJoinTable hashtable, { /* Compute the hash function */ uint32 hkey; - - hkey = DatumGetUInt32(FunctionCall1(&hashfunctions[i], keyval)); + hashfunctions->arg[0] = keyval; + hkey = DatumGetUInt32(FunctionCallInvoke(hashfunctions)); hashkey ^= hkey; } i++; + hashfunctions++; } MemoryContextSwitchTo(oldContext); diff --git a/src/include/executor/hashjoin.h b/src/include/executor/hashjoin.h index ac840533ee..800eb05a0d 100644 --- a/src/include/executor/hashjoin.h +++ b/src/include/executor/hashjoin.h @@ -173,6 +173,8 @@ typedef struct HashJoinTableData */ FmgrInfo *outer_hashfunctions; /* lookup data for hash functions */ FmgrInfo *inner_hashfunctions; /* lookup data for hash functions */ + FunctionCallInfoData *outer_hashfunctioncalls; /* hash functions call */ + FunctionCallInfoData *inner_hashfunctioncalls; /* hash function call */ bool *hashStrict; /* is each hash join operator strict? */ Size spaceUsed; /* memory space currently used by tuples */