Re: Memory leak in InitMaterializedSRF when a set-returning function is called once per row (15+)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tynan Couture-Rashid <tynan(at)awardedsoftware(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Memory leak in InitMaterializedSRF when a set-returning function is called once per row (15+)
Date: 2026-12-04 23:27:58
Message-ID: 2570290.1796426878@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tynan Couture-Rashid <tynan(at)awardedsoftware(dot)com> writes:
> I tracked down a per-call memory leak in
> InitMaterializedSRF(). It shows up via jsonb_each() and similar
> set-returning functions. We had a bad query in production and the plan
> called jsonb_each() about 87 million times, exacerbating this leak and
> causing the server to run out of memory.

Thanks for the report and the patches. Questions:

1. Do we actually need both patches? It seems like 0002 alone might
solve the problem more efficiently.

2. Why does 0001 propose using CreateTupleDescCopyConstr?
The adjacent call is just CreateTupleDescCopy, so this looks
inconsistent. I do not think the result of get_call_result_type
would ever carry constraints, though I admit I didn't dig.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Tom Lane 2026-12-04 23:19:35 Re: Large regex fails with XX000 instead of a regex error