From 8e7c526a975023ab72141d513bbcc8e352815c53 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@tigerdata.com>
Date: Thu, 29 Oct 2026 13:31:32 +0300
Subject: [PATCH v1 2/2] Make hash_stats() static

The function was declared in hsearch.h, but it is not part of the
dynahash API.  Make it static and compile only under HASH_STATISTICS.

Author: Aleksander Alekseev <aleksander@tigerdata.com>
Reviewed-by: TODO FIXME
Discussion: TODO FIXME
---
 src/backend/utils/hash/dynahash.c | 15 ++++++++++-----
 src/include/utils/hsearch.h       |  1 -
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index 47d3cacc532..4e57009cfbb 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -80,8 +80,8 @@
  * are not implemented; otherwise functionality is identical.
  *
  * Compilation controls:
- * HASH_STATISTICS causes some usage statistics to be maintained, which can be
- * logged by calling hash_stats().
+ * HASH_STATISTICS causes some usage statistics to be maintained, which are
+ * logged when the hashtable is destroyed.
  *
  * Problems & fixes to ejp@ausmelb.oz. WARNING: relies on pre-processor
  * concatenation property, in probably unnecessary code 'optimization'.
@@ -285,6 +285,9 @@ static int	next_pow2_int(int64 num);
 static void register_seq_scan(HTAB *hashp);
 static void deregister_seq_scan(HTAB *hashp);
 static bool has_seq_scans(HTAB *hashp);
+#ifdef HASH_STATISTICS
+static void hash_stats(const char *caller, HTAB *hashp);
+#endif
 
 
 /*
@@ -803,7 +806,9 @@ hash_destroy(HTAB *hashp)
 		/* so this hashtable must have its own context */
 		Assert(hashp->hcxt != NULL);
 
+#ifdef HASH_STATISTICS
 		hash_stats(__func__, hashp);
+#endif
 
 		/*
 		 * Free everything by destroying the hash table's memory context.
@@ -812,10 +817,10 @@ hash_destroy(HTAB *hashp)
 	}
 }
 
-void
+#ifdef HASH_STATISTICS
+static void
 hash_stats(const char *caller, HTAB *hashp)
 {
-#ifdef HASH_STATISTICS
 	HASHHDR    *hctl = hashp->hctl;
 
 	elog(DEBUG4,
@@ -823,8 +828,8 @@ hash_stats(const char *caller, HTAB *hashp)
 		 caller != NULL ? caller : "(unknown)", hashp->tabname, hctl->accesses,
 		 hctl->collisions, hctl->expansions, hash_get_num_entries(hashp),
 		 hctl->keysize, hctl->max_bucket, hctl->nsegs);
-#endif
 }
+#endif
 
 /*******************************SEARCH ROUTINES *****************************/
 
diff --git a/src/include/utils/hsearch.h b/src/include/utils/hsearch.h
index c238466c3eb..59180719b9d 100644
--- a/src/include/utils/hsearch.h
+++ b/src/include/utils/hsearch.h
@@ -127,7 +127,6 @@ typedef struct
 extern HTAB *hash_create(const char *tabname, int64 nelem,
 						 const HASHCTL *info, int flags);
 extern void hash_destroy(HTAB *hashp);
-extern void hash_stats(const char *caller, HTAB *hashp);
 extern void *hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action,
 						 bool *foundPtr);
 extern uint32 get_hash_value(HTAB *hashp, const void *keyPtr);
-- 
2.43.0

