pgsql: Avoid query-lifetime memory leaks in XMLTABLE (bug #15321)

From: Andrew Gierth <rhodiumtoad(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid query-lifetime memory leaks in XMLTABLE (bug #15321)
Date: 2018-08-13 01:07:54
Message-ID: E1fp1Ks-0004u0-5a@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid query-lifetime memory leaks in XMLTABLE (bug #15321)

Multiple calls to XMLTABLE in a query (e.g. laterally applying it to a
table with an xml column, an important use-case) were leaking large
amounts of memory into the per-query context, blowing up memory usage.

Repair by reorganizing memory context usage in nodeTableFuncscan; use
the usual per-tuple context for row-by-row evaluations instead of
perValueCxt, and use the explicitly created context -- renamed from
perValueCxt to perTableCxt -- for arguments and state for each
individual table-generation operation.

Backpatch to PG10 where this code was introduced.

Original report by IRC user begriffs; analysis and patch by me.
Reviewed by Tom Lane and Pavel Stehule.

Discussion: https://postgr.es/m/153394403528.10284.7530399040974170549@wrigleys.postgresql.org

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/556140424c4b46a7076cdf13f306bd92db797b61

Modified Files
--------------
src/backend/executor/nodeTableFuncscan.c | 29 ++++++++++++++++++++++++-----
src/include/nodes/execnodes.h | 2 +-
2 files changed, 25 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2018-08-13 03:30:08 pgsql: Prohibit shutting down resources if there is a possibility of ba
Previous Message Thomas Munro 2018-08-13 00:06:09 Re: pgsql: Fix bogus loop logic in 013_crash_restart test's pump_until subr