From a635c08fa10fe545d723bcec6eb73bfdca07e2c0 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 30 Jan 2007 01:33:36 +0000 Subject: 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. --- src/backend/access/hash/hashutil.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/backend/access/hash/hashutil.c') diff --git a/src/backend/access/hash/hashutil.c b/src/backend/access/hash/hashutil.c index eadbe7aabe..afa7c09a53 100644 --- a/src/backend/access/hash/hashutil.c +++ b/src/backend/access/hash/hashutil.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hashutil.c,v 1.50 2007/01/05 22:19:22 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hashutil.c,v 1.51 2007/01/30 01:33:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,6 +18,7 @@ #include "access/hash.h" #include "access/reloptions.h" #include "executor/execdebug.h" +#include "utils/lsyscache.h" /* @@ -63,6 +64,9 @@ _hash_checkqual(IndexScanDesc scan, IndexTuple itup) /* * _hash_datum2hashkey -- given a Datum, call the index's hash procedure + * + * The Datum is assumed to be of the index's column type, so we can use the + * "primary" hash procedure that's tracked for us by the generic index code. */ uint32 _hash_datum2hashkey(Relation rel, Datum key) @@ -75,6 +79,31 @@ _hash_datum2hashkey(Relation rel, Datum key) return DatumGetUInt32(FunctionCall1(procinfo, key)); } +/* + * _hash_datum2hashkey_type -- given a Datum of a specified type, + * hash it in a fashion compatible with this index + * + * This is much more expensive than _hash_datum2hashkey, so use it only in + * cross-type situations. + */ +uint32 +_hash_datum2hashkey_type(Relation rel, Datum key, Oid keytype) +{ + RegProcedure hash_proc; + + /* XXX assumes index has only one attribute */ + hash_proc = get_opfamily_proc(rel->rd_opfamily[0], + keytype, + keytype, + HASHPROC); + if (!RegProcedureIsValid(hash_proc)) + elog(ERROR, "missing support function %d(%u,%u) for index \"%s\"", + HASHPROC, keytype, keytype, + RelationGetRelationName(rel)); + + return DatumGetUInt32(OidFunctionCall1(hash_proc, key)); +} + /* * _hash_hashkey2bucket -- determine which bucket the hashkey maps to. */ -- cgit v1.2.1