diff options
author | Robert Haas <rhaas@postgresql.org> | 2017-08-31 22:21:21 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2017-08-31 22:21:21 -0400 |
commit | 81c5e46c490e2426db243eada186995da5bb0ba7 (patch) | |
tree | a6cb745131c45a06fa43746a17a69e1dc9daa44a /src/backend/utils/adt/date.c | |
parent | 2d44c58c79aeef2d376be0141057afbb9ec6b5bc (diff) | |
download | postgresql-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/utils/adt/date.c')
-rw-r--r-- | src/backend/utils/adt/date.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index 7d89d794381..34c0b52d583 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -1509,6 +1509,12 @@ time_hash(PG_FUNCTION_ARGS) } Datum +time_hash_extended(PG_FUNCTION_ARGS) +{ + return hashint8extended(fcinfo); +} + +Datum time_larger(PG_FUNCTION_ARGS) { TimeADT time1 = PG_GETARG_TIMEADT(0); @@ -2214,6 +2220,21 @@ timetz_hash(PG_FUNCTION_ARGS) } 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) { TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); |