diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-01-30 01:33:36 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-01-30 01:33:36 +0000 |
commit | a635c08fa10fe545d723bcec6eb73bfdca07e2c0 (patch) | |
tree | 83ac01972011232d6841e60cd830fe34ac2463d5 /src/backend/executor/nodeHash.c | |
parent | e8cd6f14a26bbecd3d8abcf36235a033cb035678 (diff) | |
download | postgresql-a635c08fa10fe545d723bcec6eb73bfdca07e2c0.tar.gz postgresql-a635c08fa10fe545d723bcec6eb73bfdca07e2c0.zip |
Add support for cross-type hashing in hash index searches and hash joins.
Hashing for aggregation purposes still needs work, so it's not time to
mark any cross-type operators as hashable for general use, but these cases
work if the operators are so marked by hand in the system catalogs.
Diffstat (limited to 'src/backend/executor/nodeHash.c')
-rw-r--r-- | src/backend/executor/nodeHash.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index dffe8cb0d30..88d9360e422 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeHash.c,v 1.109 2007/01/28 23:21:26 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeHash.c,v 1.110 2007/01/30 01:33:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -94,7 +94,7 @@ MultiExecHash(HashState *node) break; /* We have to compute the hash value */ econtext->ecxt_innertuple = slot; - if (ExecHashGetHashValue(hashtable, econtext, hashkeys, false, + if (ExecHashGetHashValue(hashtable, econtext, hashkeys, false, false, &hashvalue)) { ExecHashTableInsert(hashtable, slot, hashvalue); @@ -267,19 +267,23 @@ ExecHashTableCreate(Hash *node, List *hashOperators) * Also remember whether the join operators are strict. */ nkeys = list_length(hashOperators); - hashtable->hashfunctions = (FmgrInfo *) palloc(nkeys * sizeof(FmgrInfo)); + hashtable->outer_hashfunctions = + (FmgrInfo *) palloc(nkeys * sizeof(FmgrInfo)); + hashtable->inner_hashfunctions = + (FmgrInfo *) palloc(nkeys * sizeof(FmgrInfo)); hashtable->hashStrict = (bool *) palloc(nkeys * sizeof(bool)); i = 0; foreach(ho, hashOperators) { Oid hashop = lfirst_oid(ho); - Oid hashfn; + Oid left_hashfn; + Oid right_hashfn; - hashfn = get_op_hash_function(hashop); - if (!OidIsValid(hashfn)) + if (!get_op_hash_functions(hashop, &left_hashfn, &right_hashfn)) elog(ERROR, "could not find hash function for hash operator %u", hashop); - fmgr_info(hashfn, &hashtable->hashfunctions[i]); + fmgr_info(left_hashfn, &hashtable->outer_hashfunctions[i]); + fmgr_info(right_hashfn, &hashtable->inner_hashfunctions[i]); hashtable->hashStrict[i] = op_strict(hashop); i++; } @@ -674,10 +678,12 @@ bool ExecHashGetHashValue(HashJoinTable hashtable, ExprContext *econtext, List *hashkeys, + bool outer_tuple, bool keep_nulls, uint32 *hashvalue) { uint32 hashkey = 0; + FmgrInfo *hashfunctions; ListCell *hk; int i = 0; MemoryContext oldContext; @@ -690,6 +696,11 @@ ExecHashGetHashValue(HashJoinTable hashtable, oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory); + if (outer_tuple) + hashfunctions = hashtable->outer_hashfunctions; + else + hashfunctions = hashtable->inner_hashfunctions; + foreach(hk, hashkeys) { ExprState *keyexpr = (ExprState *) lfirst(hk); @@ -728,8 +739,7 @@ ExecHashGetHashValue(HashJoinTable hashtable, /* Compute the hash function */ uint32 hkey; - hkey = DatumGetUInt32(FunctionCall1(&hashtable->hashfunctions[i], - keyval)); + hkey = DatumGetUInt32(FunctionCall1(&hashfunctions[i], keyval)); hashkey ^= hkey; } |