Hello, At Fri, 27 Nov 2026 01:02:35 +0100, "Jelte Fennema-Nio" <[email protected]> wrote in > Hi all, > > This is a restart of the "Safer hash table initialization macro" > thread[1]. That patchset needed a rework after Heikki's new shmem > request API (283e823f9dc), so starting a fresh thread seemed the best > option. > > The idea is mostly the same as before. With this patchset, creating > and > iterating over a hash table looks like this:
I like the overall direction of the API changes. Having read through the previous thread as well, I'd like to share a few high-level thoughts from the perspective of someone who doesn't find the current API all that bad :p I'm in favor of eliminating redundant specifications such as key and entry sizes and flags that can be mechanically derived from the supplied options, as long as the resulting behavior is intuitive. However, I would prefer to keep semantically significant choices, such as the key comparison semantics and the memory context, explicit. In particular, automatically inferring a choice and then providing a way to override it because the inference can be wrong seems more likely to cause confusion. I also think we should be careful not to obscure resource management responsibilities that still remain with the caller in the interest of making the code more concise. The requirement to explicitly terminate a hash scan when exiting a foreach_hash loop early is one example. Regarding the default memory context, a quick look at the roughly 100 hash_create() call sites suggests that only about 20% explicitly use CurrentMemoryContext, while a substantial number use TopMemoryContext, either explicitly or by default. There are also quite a few uses of transaction-specific or purpose-specific memory contexts. Given this distribution, I don't see a compelling reason to change the default from TopMemoryContext to CurrentMemoryContext. If anything, I'd be inclined to require an explicit choice of memory context rather than provide a default at all. As for the bulk conversion, I would prefer to avoid it, given the potential impact on backpatching future changes that touch the surrounding code, even if those changes are unrelated to hash table creation or iteration itself. Regards, -- Kyotaro Horiguchi NTT Open Source Software Center
