WIP: Cache hash functions in nodeHash.c.
authorAndres Freund <andres@anarazel.de>
Tue, 14 Mar 2017 03:22:10 +0000 (20:22 -0700)
committerAndres Freund <andres@anarazel.de>
Tue, 14 Mar 2017 06:34:02 +0000 (23:34 -0700)
Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

src/backend/executor/nodeHash.c
src/include/executor/hashjoin.h

index cfc6b9609355ceb426b07c1df21eb1ddaccad399..21408f1c2d51f74f83c52f5d4465bd87795c50b7 100644 (file)
@@ -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);
index ac840533ee1b2133e3b09099ab37f7cba1b75c62..800eb05a0d6df660ae1b20c34497002e43b84ebc 100644 (file)
@@ -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 */