BUG #15321: XMLTABLE leaks memory like crazy - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15321: XMLTABLE leaks memory like crazy
Date
Msg-id 153394403528.10284.7530399040974170549@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #15321: XMLTABLE leaks memory like crazy
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      15321
Logged by:          Andrew Gierth
Email address:      andrew@tao11.riddles.org.uk
PostgreSQL version: 10.5
Operating system:   any
Description:

From a report on IRC:

XMLTABLE runs a lot of setup code in the per-query memory context -
resulting in allocations of copies of namespace names, other values, and
_multiple copies of the passed-in XML document_, which are not freed
anywhere.

Accordingly, virtually any lateral call to XMLTABLE on non-toy amounts of
data will blow up the server memory usage:

select count(*)
  from (select ('<rec xmlns="http://foobar">'
                ||
repeat('<obj><col1>foo</col1><col2>bar</col2></obj>',10+(i%10))
                || '</rec>')::xml as content
          from generate_series(1,1000000) i) s,
       xmltable(xmlnamespaces('http://foobar' AS x),
                'x:obj'
                passing t.content
                columns col1 text path 'x:col1'
                columns col2 text path 'x:col2'
                );
-- uses about 6GB of RAM in my tests


pgsql-bugs by date:

Previous
From: Martin Marques
Date:
Subject: Re: [PG_UPGRADE] 9.6 to 10.5
Next
From: Andrew Gierth
Date:
Subject: Re: BUG #15321: XMLTABLE leaks memory like crazy