aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/hash/hashsearch.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-01-30 01:33:36 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-01-30 01:33:36 +0000
commita635c08fa10fe545d723bcec6eb73bfdca07e2c0 (patch)
tree83ac01972011232d6841e60cd830fe34ac2463d5 /src/backend/access/hash/hashsearch.c
parente8cd6f14a26bbecd3d8abcf36235a033cb035678 (diff)
downloadpostgresql-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/access/hash/hashsearch.c')
-rw-r--r--src/backend/access/hash/hashsearch.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/backend/access/hash/hashsearch.c b/src/backend/access/hash/hashsearch.c
index 5582c036417..52e867e3605 100644
--- a/src/backend/access/hash/hashsearch.c
+++ b/src/backend/access/hash/hashsearch.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.47 2007/01/20 18:43:35 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.48 2007/01/30 01:33:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -115,6 +115,7 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
{
Relation rel = scan->indexRelation;
HashScanOpaque so = (HashScanOpaque) scan->opaque;
+ ScanKey cur;
uint32 hashkey;
Bucket bucket;
BlockNumber blkno;
@@ -143,18 +144,37 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("hash indexes do not support whole-index scans")));
+ /* There may be more than one index qual, but we hash only the first */
+ cur = &scan->keyData[0];
+
+ /* We support only single-column hash indexes */
+ Assert(cur->sk_attno == 1);
+ /* And there's only one operator strategy, too */
+ Assert(cur->sk_strategy == HTEqualStrategyNumber);
+
/*
* If the constant in the index qual is NULL, assume it cannot match any
* items in the index.
*/
- if (scan->keyData[0].sk_flags & SK_ISNULL)
+ if (cur->sk_flags & SK_ISNULL)
return false;
/*
* Okay to compute the hash key. We want to do this before acquiring any
* locks, in case a user-defined hash function happens to be slow.
+ *
+ * If scankey operator is not a cross-type comparison, we can use the
+ * cached hash function; otherwise gotta look it up in the catalogs.
+ *
+ * We support the convention that sk_subtype == InvalidOid means the
+ * opclass input type; this is a hack to simplify life for ScanKeyInit().
*/
- hashkey = _hash_datum2hashkey(rel, scan->keyData[0].sk_argument);
+ if (cur->sk_subtype == rel->rd_opcintype[0] ||
+ cur->sk_subtype == InvalidOid)
+ hashkey = _hash_datum2hashkey(rel, cur->sk_argument);
+ else
+ hashkey = _hash_datum2hashkey_type(rel, cur->sk_argument,
+ cur->sk_subtype);
/*
* Acquire shared split lock so we can compute the target bucket safely