mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Simplify abbreviated key hashing during cardinality estimation
In the wake of commit 2a600a93c, Datums are 64-bit values, so
we no longer need to fold the abbreviated key to 32 bits before
hashing. Instead, use murmurhash64(), which is simpler and avoids
a function call. Also replace hash_uint32() with murmurhash32()
in related places.
Author: Aleksander Alekseev <aleksander@tigerdata.com>
Suggested-by: John Naylor <johncnaylorls@gmail.com>
Reviewed-by: Aditya Gollamudi <adigollamudi@gmail.com> (earlier version)
Reviewed-by: Michael Paquier <michael@paquier.xyz> (earlier version)
Discussion: https://postgr.es/m/CAJ7c6TMPhDRQMmkUHPv8oOK97B1mR8NRS61DgjpdaZUPAwaeZQ%40mail.gmail.com
This commit is contained in:
@@ -1110,17 +1110,12 @@ bytea_abbrev_convert(Datum original, SortSupport ssup)
|
||||
Min(len, PG_CACHE_LINE_SIZE)));
|
||||
|
||||
if (len > PG_CACHE_LINE_SIZE)
|
||||
hash ^= DatumGetUInt32(hash_uint32((uint32) len));
|
||||
hash ^= murmurhash32((uint32) len);
|
||||
|
||||
addHyperLogLog(&bss->full_card, hash);
|
||||
|
||||
/* Hash abbreviated key */
|
||||
{
|
||||
uint32 tmp;
|
||||
|
||||
tmp = DatumGetUInt32(res) ^ (uint32) (DatumGetUInt64(res) >> 32);
|
||||
hash = DatumGetUInt32(hash_uint32(tmp));
|
||||
}
|
||||
hash = (uint32) murmurhash64(DatumGetUInt64(res));
|
||||
|
||||
addHyperLogLog(&bss->abbr_card, hash);
|
||||
|
||||
|
||||
@@ -738,13 +738,8 @@ network_abbrev_convert(Datum original, SortSupport ssup)
|
||||
|
||||
/* Hash abbreviated key */
|
||||
if (uss->estimating)
|
||||
{
|
||||
uint32 tmp;
|
||||
|
||||
tmp = DatumGetUInt32(res) ^ (uint32) (DatumGetUInt64(res) >> 32);
|
||||
|
||||
addHyperLogLog(&uss->abbr_card, DatumGetUInt32(hash_uint32(tmp)));
|
||||
}
|
||||
addHyperLogLog(&uss->abbr_card,
|
||||
(uint32) murmurhash64(DatumGetUInt64(res)));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -2404,12 +2404,8 @@ numeric_abbrev_convert_var(const NumericVar *var, NumericSortSupport *nss)
|
||||
result = -result;
|
||||
|
||||
if (nss->estimating)
|
||||
{
|
||||
uint32 tmp = ((uint32) result
|
||||
^ (uint32) ((uint64) result >> 32));
|
||||
|
||||
addHyperLogLog(&nss->abbr_card, DatumGetUInt32(hash_uint32(tmp)));
|
||||
}
|
||||
addHyperLogLog(&nss->abbr_card,
|
||||
(uint32) murmurhash64((uint64) result));
|
||||
|
||||
return NumericAbbrevGetDatum(result);
|
||||
}
|
||||
|
||||
@@ -521,13 +521,8 @@ uuid_abbrev_convert(Datum original, SortSupport ssup)
|
||||
uss->input_count += 1;
|
||||
|
||||
if (uss->estimating)
|
||||
{
|
||||
uint32 tmp;
|
||||
|
||||
tmp = DatumGetUInt32(res) ^ (uint32) (DatumGetUInt64(res) >> 32);
|
||||
|
||||
addHyperLogLog(&uss->abbr_card, DatumGetUInt32(hash_uint32(tmp)));
|
||||
}
|
||||
addHyperLogLog(&uss->abbr_card,
|
||||
(uint32) murmurhash64(DatumGetUInt64(res)));
|
||||
|
||||
/*
|
||||
* Byteswap on little-endian machines.
|
||||
|
||||
@@ -2158,17 +2158,12 @@ varstr_abbrev_convert(Datum original, SortSupport ssup)
|
||||
Min(len, PG_CACHE_LINE_SIZE)));
|
||||
|
||||
if (len > PG_CACHE_LINE_SIZE)
|
||||
hash ^= DatumGetUInt32(hash_uint32((uint32) len));
|
||||
hash ^= murmurhash32((uint32) len);
|
||||
|
||||
addHyperLogLog(&sss->full_card, hash);
|
||||
|
||||
/* Hash abbreviated key */
|
||||
{
|
||||
uint32 tmp;
|
||||
|
||||
tmp = DatumGetUInt32(res) ^ (uint32) (DatumGetUInt64(res) >> 32);
|
||||
hash = DatumGetUInt32(hash_uint32(tmp));
|
||||
}
|
||||
hash = (uint32) murmurhash64(DatumGetUInt64(res));
|
||||
|
||||
addHyperLogLog(&sss->abbr_card, hash);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user