mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
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
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user