aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/opclasscmds.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-08-31 22:21:21 -0400
committerRobert Haas <rhaas@postgresql.org>2017-08-31 22:21:21 -0400
commit81c5e46c490e2426db243eada186995da5bb0ba7 (patch)
treea6cb745131c45a06fa43746a17a69e1dc9daa44a /src/backend/commands/opclasscmds.c
parent2d44c58c79aeef2d376be0141057afbb9ec6b5bc (diff)
downloadpostgresql-81c5e46c490e2426db243eada186995da5bb0ba7.tar.gz
postgresql-81c5e46c490e2426db243eada186995da5bb0ba7.zip
Introduce 64-bit hash functions with a 64-bit seed.
This will be useful for hash partitioning, which needs a way to seed the hash functions to avoid problems such as a hash index on a hash partitioned table clumping all values into a small portion of the bucket space; it's also useful for anything that wants a 64-bit hash value rather than a 32-bit hash value. Just in case somebody wants a 64-bit hash value that is compatible with the existing 32-bit hash values, make the low 32-bits of the 64-bit hash value match the 32-bit hash value when the seed is 0. Robert Haas and Amul Sul Discussion: http://postgr.es/m/CA+Tgmoafx2yoJuhCQQOL5CocEi-w_uG4S2xT0EtgiJnPGcHW3g@mail.gmail.com
Diffstat (limited to 'src/backend/commands/opclasscmds.c')
-rw-r--r--src/backend/commands/opclasscmds.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index a31b1acb9c6..d23e6d6f250 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -18,6 +18,7 @@
#include <limits.h>
#include "access/genam.h"
+#include "access/hash.h"
#include "access/heapam.h"
#include "access/nbtree.h"
#include "access/htup_details.h"
@@ -1129,7 +1130,8 @@ assignProcTypes(OpFamilyMember *member, Oid amoid, Oid typeoid)
/*
* btree comparison procs must be 2-arg procs returning int4, while btree
* sortsupport procs must take internal and return void. hash support
- * procs must be 1-arg procs returning int4. Otherwise we don't know.
+ * proc 1 must be a 1-arg proc returning int4, while proc 2 must be a
+ * 2-arg proc returning int8. Otherwise we don't know.
*/
if (amoid == BTREE_AM_OID)
{
@@ -1172,14 +1174,28 @@ assignProcTypes(OpFamilyMember *member, Oid amoid, Oid typeoid)
}
else if (amoid == HASH_AM_OID)
{
- if (procform->pronargs != 1)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("hash procedures must have one argument")));
- if (procform->prorettype != INT4OID)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("hash procedures must return integer")));
+ if (member->number == HASHSTANDARD_PROC)
+ {
+ if (procform->pronargs != 1)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("hash procedure 1 must have one argument")));
+ if (procform->prorettype != INT4OID)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("hash procedure 1 must return integer")));
+ }
+ else if (member->number == HASHEXTENDED_PROC)
+ {
+ if (procform->pronargs != 2)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("hash procedure 2 must have two arguments")));
+ if (procform->prorettype != INT8OID)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("hash procedure 2 must return bigint")));
+ }
/*
* If lefttype/righttype isn't specified, use the proc's input type