From f79b8beafae2b0fa462f27d02d735313b15fb351 Mon Sep 17 00:00:00 2001
From: ChangAo Chen <cca5507@qq.com>
Date: Fri, 11 Jul 2025 19:58:44 +0800
Subject: [PATCH v3] Small optimization with expanding dynamic hash table

When expanding table, all hashvalues in the old bucket must have
'hashvalue & high_mask' equal to the old bucket's no or the new
bucket's no. We can calc bucket just by 'hashvalue & high_mask'
because the if condition in calc_bucket() must be false.
(old bucket's no < new bucket's no = max bucket's no)
---
 src/backend/utils/hash/dynahash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index 1ad155d446e..475da6add1c 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -1626,7 +1626,7 @@ expand_table(HTAB *hashp)
 		 currElement = nextElement)
 	{
 		nextElement = currElement->link;
-		if ((long) calc_bucket(hctl, currElement->hashvalue) == old_bucket)
+		if ((long) (currElement->hashvalue & hctl->high_mask) == old_bucket)
 		{
 			*oldlink = currElement;
 			oldlink = &currElement->link;
-- 
2.34.1

