Re: Safer hash table initialization macro

From: "Jelte Fennema-Nio" <postgres(at)jeltef(dot)nl>
To: "Bertrand Drouvot" <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Safer hash table initialization macro
Date: 2025-12-04 15:29:55
Message-ID: DEPJFNNOXN6C.39PM8C3I63DKU@jeltef.nl
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed Dec 3, 2025 at 12:17 PM CET, Bertrand Drouvot wrote:
> I suggest we move forward one
> step at a time, first step being the new macros. Does that make sense to you?

Normally I would agree, but in this case I think the new macros you
proposing would become obsolete once we have the better hash table
creation functions I have in mind. And if we're going to update all
places where we create hash tables, I'd rather update them to something
really nice than a small improvement.

I couldn't let it go (nerd-sniped). So here's a patchset that adds some
macros that I think are pretty nice. Including a foreach_hash macro.

I'm a bit on the fence about the C11 _Generic code to determine whether
we should use HASH_BLOBS or HASH_STRINGS based on the type of the key.
It works really nicely in practice, but I'm worried it's a bit too much
magic. Probably we should at least have an override to allow using
HASH_BLOBS anyway for a char array (in case it's not null terminated).

Attachment Content-Type Size
v2-0001-Add-hash_make-macros.patch text/x-patch 13.2 KB
v2-0002-Use-hash_make-macros-throughout-the-codebase.patch text/x-patch 95.6 KB
v2-0003-Inline-functions-that-have-now-become-trivial.patch text/x-patch 4.5 KB
v2-0004-Add-foreach_hash-macro.patch text/x-patch 2.3 KB
v2-0005-Use-foreach_hash-macro-throughout-the-codebase.patch text/x-patch 67.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Maxim Orlov 2025-12-04 15:33:47 Re: POC: make mxidoff 64 bits
Previous Message David Klika 2025-12-04 15:17:51 Re: Adding REPACK [concurrently]