| From: | Nathan Bossart <nathandbossart(at)gmail(dot)com> |
|---|---|
| To: | Jelte Fennema-Nio <postgres(at)jeltef(dot)nl> |
| Cc: | Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, bertranddrouvot(dot)pg(at)gmail(dot)com, hlinnaka(at)iki(dot)fi, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Safer and simpler HTAB macros (foreach_hash and hash_make), take two |
| Date: | 2026-11-30 18:13:51 |
| Message-ID: | aw2839dzmJodXgOu@nathan |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
+1 for the general idea.
On Sun, Nov 29, 2026 at 11:55:23AM +0100, Jelte Fennema-Nio wrote:
> On Fri Nov 27, 2026 at 3:28 AM CET, Kyotaro Horiguchi wrote:
>> The requirement to explicitly terminate a hash scan when exiting a
>> foreach_hash loop early is one example.
>
> I totally agree that's easy to miss, but that requirement was already
> there: where we call hash_seq_term() today, we now call
> foreach_hash_term() in this patch. It's also pretty rare: only 5 of the
> 111 converted loops need it.
I wondered about calling it unconditionally from the macros, but I'm
guessing that requires something that looks like PG_END_TRY(), which we
probably want to avoid.
>> Given this distribution, I don't see a compelling reason to change
>> the default from TopMemoryContext to CurrentMemoryContext.
>
> [...]
>
> My main argument is not about the numbers though. I think the
> important part is that using TopMemoryContext should require being
> explicit, to avoid accidental leaks like the ones fixed in 0b392314315
> and aaff0a559f8.
Regardless of whether we _should_ change the default memory context, I
don't think it belongs in this patch set. IMHO the new macros should aim
to change as little as possible, and then we can look into changing the
semantics once they're committed. IOW let's not change multiple variables
at once if we can avoid it.
>> As for the bulk conversion, I would prefer to avoid it, given the
>> potential impact on backpatching
>
> I'm fine with the conversion patches not getting committed. They are
> mostly there as a review aid, to show that the new APIs are nicer to
> use. I'll already be very happy if I can use the new APIs in my own
> code and extensions.
>
> That said, I tried to estimate how often that would happen. Of the 2048
> commits on REL_16_STABLE since it branched off, 5 change lines that
> overlap with or are adjacent to lines changed by the conversion. So
> that's about 1.5 conflicts per year for that branch, across all committers.
That's encouraging. We didn't convert everything to foreach_ptr() and
friends, but I don't think we did much analysis on the potential rate of
conflicts like this. If we did bulk convert, would we want to do something
with the existing functions? We'd probably want all new code to use the
new macros, but obviously we need to continue supporting the functions for
third-party code for a while. Something to think about...
--
nathan
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andres Freund | 2026-11-30 18:31:20 | Re: Speed up binary COPY TO by not allocating 1 kB per datum |
| Previous Message | Melanie Plageman | 2026-11-30 18:01:38 | Re: CI failure: postgres_fdw_get_connections |