From 02c7b845d204b7a123536a3a2a1a01d4b0c64858 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Wed, 7 Aug 2024 23:18:09 +0300
Subject: [PATCH v1] Add a caveat to hash_seq_init_with_hash_value() header
 comment

The typical use-case for hash_seq_init_with_hash_value() is syscache
callback.  Add a caveat that the default hash function doesn't match syscache
hash function.  So, one needs to define a custom hash function.

Reported-by: Pavel Stehule
Discussion: https://postgr.es/m/CAFj8pRAXmv6eyYx%3DE_BTfyK%3DO_%2ByOF8sXB%3D0bn9eOBt90EgWRA%40mail.gmail.com
---
 src/backend/utils/hash/dynahash.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index 8040416a13c..5d9c62b652a 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -1395,6 +1395,11 @@ hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
 /*
  * Same as above but scan by the given hash value.
  * See also hash_seq_search().
+ *
+ * NOTE: the default hash function doesn't match syscache hash function.
+ * Thus, if you're going to use this function in syscache callback, make sure
+ * you're using custom hash function.  See relatt_cache_syshash()
+ * for example.
  */
 void
 hash_seq_init_with_hash_value(HASH_SEQ_STATUS *status, HTAB *hashp,
-- 
2.39.3 (Apple Git-146)

