From e3a33a9a9f1a6afb80c9b83c1456c1a36fbcb70b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 8 Jun 2005 23:02:05 +0000 Subject: Marginal hack to avoid spending a lot of time in find_join_rel during large planning problems: when the list of join rels gets too long, make an auxiliary hash table that hashes on the identifying Bitmapset. --- src/backend/nodes/bitmapset.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/backend/nodes/bitmapset.c') diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c index 699f0439ff..5f4ca9a779 100644 --- a/src/backend/nodes/bitmapset.c +++ b/src/backend/nodes/bitmapset.c @@ -14,7 +14,7 @@ * Copyright (c) 2003-2005, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/bitmapset.c,v 1.7 2005/01/01 20:44:15 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/bitmapset.c,v 1.8 2005/06/08 23:02:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -763,3 +763,28 @@ bms_first_member(Bitmapset *a) } return -1; } + +/* + * bms_hash_value - compute a hash key for a Bitmapset + * + * Note: we must ensure that any two bitmapsets that are bms_equal() will + * hash to the same value; in practice this means that trailing all-zero + * words cannot affect the result. Longitudinal XOR provides a reasonable + * hash value that has this property. + */ +uint32 +bms_hash_value(const Bitmapset *a) +{ + bitmapword result = 0; + int nwords; + int wordnum; + + if (a == NULL) + return 0; /* All empty sets hash to 0 */ + nwords = a->nwords; + for (wordnum = 0; wordnum < nwords; wordnum++) + { + result ^= a->words[wordnum]; + } + return (uint32) result; +} -- cgit v1.2.1