Small optimization with expanding dynamic hash table

From: cca5507 <cca5507(at)qq(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Small optimization with expanding dynamic hash table
Date: 2025-07-07 06:00:09
Message-ID: tencent_571C8FF040D62E25F4A0F0AAD63EA545A605@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, hackers

If I understand correctly, we only need to check the&nbsp;specific bit to&nbsp;determine&nbsp;whether a hash element needs&nbsp;relocation:

diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index 1ad155d446e..32fbae71995 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -1626,7 +1626,7 @@ expand_table(HTAB *hashp)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;currElement = nextElement)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nextElement = currElement-&gt;link;
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((long) calc_bucket(hctl, currElement-&gt;hashvalue) == old_bucket)
+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!(currElement-&gt;hashvalue &amp; (hctl-&gt;low_mask + 1)))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *oldlink = currElement;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oldlink = &amp;currElement-&gt;link;

--
Regards,
ChangAo Chen

Attachment Content-Type Size
v1-0001-Small-optimization-with-expanding-dynamic-hash-ta.patch application/octet-stream 839 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2025-07-07 06:58:18 Re: Avoid circular header file dependency
Previous Message Michael Paquier 2025-07-07 05:56:29 Re: Adding wait events statistics