mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +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:
@@ -1508,6 +1508,12 @@ time_hash(PG_FUNCTION_ARGS)
|
||||
return hashint8(fcinfo);
|
||||
}
|
||||
|
||||
Datum
|
||||
time_hash_extended(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return hashint8extended(fcinfo);
|
||||
}
|
||||
|
||||
Datum
|
||||
time_larger(PG_FUNCTION_ARGS)
|
||||
{
|
||||
@@ -2213,6 +2219,21 @@ timetz_hash(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_UINT32(thash);
|
||||
}
|
||||
|
||||
Datum
|
||||
timetz_hash_extended(PG_FUNCTION_ARGS)
|
||||
{
|
||||
TimeTzADT *key = PG_GETARG_TIMETZADT_P(0);
|
||||
uint64 seed = PG_GETARG_DATUM(1);
|
||||
uint64 thash;
|
||||
|
||||
/* Same approach as timetz_hash */
|
||||
thash = DatumGetUInt64(DirectFunctionCall2(hashint8extended,
|
||||
Int64GetDatumFast(key->time),
|
||||
seed));
|
||||
thash ^= DatumGetUInt64(hash_uint32_extended(key->zone, seed));
|
||||
PG_RETURN_UINT64(thash);
|
||||
}
|
||||
|
||||
Datum
|
||||
timetz_larger(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user