From e825abb530f2edb8649d6d294ca501b082435eca Mon Sep 17 00:00:00 2001 From: John Naylor Date: Mon, 18 Dec 2023 11:10:28 +0700 Subject: [PATCH v11 3/8] Use fasthash for the search path cache This serves to demonstrate the incremental API, allowing inlined hash calculation without a strlen call. This brings the general case performance closer to the optimization done in commit a86c61c9ee. WIP: roleid should be mixed in normally, unless we have reason to just use it as a seed. Jeff Davis, with switch to chunked interface by me Discussion: https://www.postgresql.org/message-id/b40292c99e623defe5eadedab1d438cf51a4107c.camel%40j-davis.com --- src/backend/catalog/namespace.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 5027efc91d..7fe2fd1fd4 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -41,7 +41,7 @@ #include "catalog/pg_ts_template.h" #include "catalog/pg_type.h" #include "commands/dbcommands.h" -#include "common/hashfn.h" +#include "common/hashfn_unstable.h" #include "funcapi.h" #include "mb/pg_wchar.h" #include "miscadmin.h" @@ -247,11 +247,25 @@ static bool MatchNamedCall(HeapTuple proctup, int nargs, List *argnames, static inline uint32 spcachekey_hash(SearchPathCacheKey key) { - const unsigned char *bytes = (const unsigned char *) key.searchPath; - int blen = strlen(key.searchPath); + const char *const start = key.searchPath; + const char *buf = key.searchPath; + fasthash_state hs; - return hash_combine(hash_bytes(bytes, blen), - hash_uint32(key.roleid)); + /* WIP: maybe roleid should be mixed in normally */ + fasthash_init(&hs, FH_UNKNOWN_LENGTH, key.roleid); + while (*buf) + { + int chunk_len = 0; + + while (chunk_len < FH_SIZEOF_ACCUM && buf[chunk_len] != '\0') + chunk_len++; + + fasthash_accum(&hs, buf, chunk_len); + buf += chunk_len; + } + + /* pass the length to tweak the final mix */ + return fasthash_final32(&hs, buf - start); } static inline bool -- 2.43.0