pgsql: Reduce leakage during PL/pgSQL function compilation.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Reduce leakage during PL/pgSQL function compilation.
Date: 2025-08-03 02:00:50
Message-ID: E1uiO1p-000SoA-2t@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Reduce leakage during PL/pgSQL function compilation.

format_procedure leaks memory, so run it in a short-lived context
not the session-lifespan cache context for the PL/pgSQL function.

parse_datatype called the core parser in the function's cache context,
thus leaking potentially a lot of storage into that context. We were
also being a bit careless with the TypeName structures made in that
code path and others. Most of the time we don't need to retain the
TypeName, so make sure it is made in the short-lived temp context,
and copy it only if we do need to retain it.

These are far from the only leaks in PL/pgSQL compilation, but
they're the biggest as far as I've seen, and further improvement
looks like it'd require delicate and bug-prone surgery.

Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Discussion: https://postgr.es/m/285483.1746756246@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9f18fa9995628fef752d704d874eeed0bab815e5

Modified Files
--------------
src/pl/plpgsql/src/pl_comp.c | 28 ++++++++++++++++++++++------
src/pl/plpgsql/src/pl_gram.y | 8 +++++++-
2 files changed, 29 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-08-03 17:01:59 pgsql: Take a little more care in set_backtrace().
Previous Message Fujii Masao 2025-08-03 01:55:01 pgsql: Fix assertion failure in pgbench when handling multiple pipeline