Re: BUG #19040: Memory leak in hashed subplan node due to missing hashtempcxt reset

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "李海洋(陌痕)" <mohen(dot)lhy(at)alibaba-inc(dot)com>
Cc: feichanghong <feichanghong(at)qq(dot)com>, ocean_li_996 <ocean_li_996(at)163(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #19040: Memory leak in hashed subplan node due to missing hashtempcxt reset
Date: 2025-09-08 20:46:10
Message-ID: 721997.1757364370@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I wrote:
> I thought about that too, but that would result in two short-lived
> contexts and two reset operations per tuple cycle where only one
> is needed. I'm rather tempted to fix nodeSubplan.c by making it
> use innerecontext->ecxt_per_tuple_memory instead of a separate
> hash tmpcontext. That context is getting reset already, at least in
> buildSubPlanHash(). That's probably too risky for the back branches
> but we could do it in HEAD.

Concretely, I'm thinking about the attached. 0001 is the same
logic as in the v02 patch, but I felt we could make the code
be shorter and prettier instead of longer and uglier. That's
meant for back-patch, and then 0002 is for master only.

regards, tom lane

Attachment Content-Type Size
v04-0001-Fix-memory-leakage-in-nodeSubplan.c.patch text/x-diff 6.1 KB
v04-0002-Eliminate-duplicative-hashtempcxt-in-nodeSubplan.patch text/x-diff 3.9 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message 李海洋 (陌痕) 2025-09-09 01:52:26 回复:BUG #19040: Memory leak in hashed subplan node due to missing hashtempcxt reset
Previous Message Tom Lane 2025-09-08 17:23:12 Re: BUG #19040: Memory leak in hashed subplan node due to missing hashtempcxt reset