diff options
| author | David Rowley | 2024-12-11 00:47:16 +0000 |
|---|---|---|
| committer | David Rowley | 2024-12-11 00:47:16 +0000 |
| commit | 0f5738202b812a976e8612c85399b52d16a0abb6 (patch) | |
| tree | 9edf2821d761f7f42615573a45bf93f9ed64cf75 /src/include/nodes | |
| parent | a43567483c617fb046c805b61964d5168c9a0553 (diff) | |
Use ExprStates for hashing in GROUP BY and SubPlans
This speeds up obtaining hash values for GROUP BY and hashed SubPlans by
using the ExprState support for hashing, thus allowing JIT compilation for
obtaining hash values for these operations.
This, even without JIT compilation, has been shown to improve Hash
Aggregate performance in some cases by around 15% and hashed NOT IN
queries in one case by over 30%, however, real-world cases are likely to
see smaller gains as the test cases used were purposefully designed to
have high hashing overheads by keeping the hash table small to prevent
additional memory overheads that would be a factor when working with large
hash tables.
In passing, fix a hypothetical bug in ExecBuildHash32Expr() so that the
initial value is stored directly in the ExprState's result field if
there are no expressions to hash. None of the current users of this
function use an initial value, so the bug is only hypothetical.
Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
Discussion: https://postgr.es/m/CAApHDvpYSO3kc9UryMevWqthTBrxgfd9djiAjKHMPUSQeX9vdQ@mail.gmail.com
Diffstat (limited to 'src/include/nodes')
| -rw-r--r-- | src/include/nodes/execnodes.h | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 182a6956bb0..7f71b7625df 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -795,15 +795,15 @@ typedef struct ExecAuxRowMark * * All-in-memory tuple hash tables are used for a number of purposes. * - * Note: tab_hash_funcs are for the key datatype(s) stored in the table, - * and tab_eq_func are non-cross-type equality operators for those types. - * Normally these are the only functions used, but FindTupleHashEntry() - * supports searching a hashtable using cross-data-type hashing. For that, - * the caller must supply hash functions for the LHS datatype as well as - * the cross-type equality operators to use. in_hash_funcs and cur_eq_func - * are set to point to the caller's function arrays while doing such a search. - * During LookupTupleHashEntry(), they point to tab_hash_funcs and - * tab_eq_func respectively. + * Note: tab_hash_expr is for hashing the key datatype(s) stored in the table, + * and tab_eq_func is a non-cross-type ExprState for equality checks on those + * types. Normally these are the only ExprStates used, but + * FindTupleHashEntry() supports searching a hashtable using cross-data-type + * hashing. For that, the caller must supply an ExprState to hash the LHS + * datatype as well as the cross-type equality ExprState to use. in_hash_expr + * and cur_eq_func are set to point to the caller's hash and equality + * ExprStates while doing such a search. During LookupTupleHashEntry(), they + * point to tab_hash_expr and tab_eq_func respectively. * ---------------------------------------------------------------- */ typedef struct TupleHashEntryData *TupleHashEntry; @@ -830,7 +830,7 @@ typedef struct TupleHashTableData tuplehash_hash *hashtab; /* underlying hash table */ int numCols; /* number of columns in lookup key */ AttrNumber *keyColIdx; /* attr numbers of key columns */ - FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */ + ExprState *tab_hash_expr; /* ExprState for hashing table datatype(s) */ ExprState *tab_eq_func; /* comparator for table datatype(s) */ Oid *tab_collations; /* collations for hash and comparison */ MemoryContext tablecxt; /* memory context containing table */ @@ -839,9 +839,8 @@ typedef struct TupleHashTableData TupleTableSlot *tableslot; /* slot for referencing table entries */ /* The following fields are set transiently for each table search: */ TupleTableSlot *inputslot; /* current input tuple's slot */ - FmgrInfo *in_hash_funcs; /* hash functions for input datatype(s) */ + ExprState *in_hash_expr; /* ExprState for hashing input datatype(s) */ ExprState *cur_eq_func; /* comparator for input vs. table */ - uint32 hash_iv; /* hash-function IV */ ExprContext *exprcontext; /* expression context */ } TupleHashTableData; @@ -994,7 +993,7 @@ typedef struct SubPlanState * datatype(s) */ Oid *tab_collations; /* collations for hash and comparison */ FmgrInfo *tab_hash_funcs; /* hash functions for table datatype(s) */ - FmgrInfo *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */ + ExprState *lhs_hash_expr; /* hash expr for lefthand datatype(s) */ FmgrInfo *cur_eq_funcs; /* equality functions for LHS vs. table */ ExprState *cur_eq_comp; /* equality comparator for LHS vs. table */ } SubPlanState; |
