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