postgresql/src
John Naylor e97b672c88 Add inline incremental hash functions for in-memory use
It can be useful for a hash function to expose separate initialization,
accumulation, and finalization steps.  In particular, this is useful
for building inline hash functions for simplehash.  Instead of trying
to whack around hash_bytes while maintaining its current behavior on
all platforms, we base this work on fasthash (MIT licensed) which
is simple, faster than hash_bytes for inputs over 12 bytes long,
and also passes the hash function testing suite SMHasher.

The fasthash functions have been reimplemented using our added-on
incremental interface to validate that this method will still give
the same answer, provided we have the input length ahead of time.

This functionality lives in a new header hashfn_unstable.h. The name
implies we have the freedom to change things across versions that
would be unacceptable for our other hash functions that are used for
e.g. hash indexes and hash partitioning. As such, these should only
be used for in-memory data structures like hash tables. There is also
no guarantee of being independent of endianness or pointer size.

As demonstration, use fasthash for pgstat_hash_hash_key.  Previously
this called the 32-bit murmur finalizer on the three elements,
then joined them with hash_combine(). The new function is simpler,
faster and takes up less binary space. While the collision and bias
behavior were almost certainly fine with the previous coding, now we
have objective confidence of that.

There are other places that could benefit from this, but that is left
for future work.

Reviewed by Jeff Davis, Heikki Linnakangas, Jian He, Junwang Zhao
Credit to Andres Freund for the idea

Discussion: https://postgr.es/m/20231122223432.lywt4yz2bn7tlp27%40awork3.anarazel.de
2024-01-19 12:44:09 +07:00
..
backend Fix incorrect placeholder in walreceiver.c 2024-01-19 13:20:49 +09:00
bin psql: Add ignore_slash_options in bind's inactive branch 2024-01-19 14:18:20 +09:00
common Cleanup for unicode-update build target and test. 2024-01-11 12:35:29 -08:00
fe_utils Update copyright for 2024 2024-01-03 20:49:05 -05:00
include Add inline incremental hash functions for in-memory use 2024-01-19 12:44:09 +07:00
interfaces Remove some comments related to pqPipelineSync() and PQsendPipelineSync() 2024-01-17 15:53:59 +09:00
makefiles Update copyright for 2024 2024-01-03 20:49:05 -05:00
pl Fix plpgsql to allow new-style SQL CREATE FUNCTION as a SQL command. 2024-01-18 16:11:16 -05:00
port Update copyright for 2024 2024-01-03 20:49:05 -05:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test psql: Add ignore_slash_options in bind's inactive branch 2024-01-19 14:18:20 +09:00
timezone Update copyright for 2024 2024-01-03 20:49:05 -05:00
tools Add inline incremental hash functions for in-memory use 2024-01-19 12:44:09 +07:00
tutorial Update copyright for 2024 2024-01-03 20:49:05 -05:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in Initialize data directories with --lc-messages=C for tests. 2023-12-21 15:10:13 -08:00
Makefile.shlib Stop using "-multiply_defined suppress" on macOS. 2023-09-26 21:06:21 -04:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
nls-global.mk Remove distprep 2023-11-06 15:18:04 +01:00