Re: Safer hash table initialization macro

Jelte Fennema <postgres@jeltef.nl>

From: "Jelte Fennema-Nio" <postgres@jeltef.nl>
To: "Chao Li" <li.evan.chao@gmail.com>
Cc: "Bertrand Drouvot" <bertranddrouvot.pg@gmail.com>, "Thomas Munro" <thomas.munro@gmail.com>, <pgsql-hackers@lists.postgresql.org>
Date: 2026-01-27T18:10:11Z
Lists: pgsql-hackers

Attachments

On Tue Jan 27, 2026 at 8:26 AM CET, Chao Li wrote:
> This function has a lot of duplicate checks on opts!=NULL, I think it can be simplified as:

Good suggestion. Done.

> 2 - 0002
> Why this function returns a structure by value? Which looks quite uncommon. Usually, when a function is named with “new”, it returns a pointer to a new object.

I changed the name to foreach_hash_start and made it a static inline
function in the header instead. I updated the comment to explain why
it's needed (i.e. to initialize the local varaiable).


> 3 - 0002
> foreach_hash feels fragile. It requires to call foreach_hash_term before break, which is easy to forget. And the documentation	doesn’t mention how to continue, how to return from a loop, and how to goto from inside a loop.

I agree that it'd be better if foreach_hash_term was not needed. But
that would be a lot bigger change (see the "SEQ SCAN TRACKING" comment).

I've updated the comment on foreach_hash_term to be more specific about
when it's needed.