Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1foHm8-0006bz-N5 for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Aug 2018 00:29:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1foHm4-00066G-6e for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Aug 2018 00:28:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1foHm3-00065y-TX for pgsql-bugs@lists.postgresql.org; Sat, 11 Aug 2018 00:28:56 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1foHm0-0006fD-M2 for pgsql-bugs@lists.postgresql.org; Sat, 11 Aug 2018 00:28:54 +0000 Received: from [192.168.127.1] (port=21389 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1foHlx-0000Su-3W; Sat, 11 Aug 2018 00:28:49 +0000 Received: from [127.0.0.1] (port=34933 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1foHlw-000OeY-BQ; Sat, 11 Aug 2018 00:28:48 +0000 From: Andrew Gierth To: Alvaro Herrera Cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15321: XMLTABLE leaks memory like crazy In-Reply-To: <153394403528.10284.7530399040974170549@wrigleys.postgresql.org> (PG Bug reporting form's message of "Fri, 10 Aug 2018 23:33:55 +0000") Message-ID: <87va8h7nyl.fsf@news-spur.riddles.org.uk> References: <153394403528.10284.7530399040974170549@wrigleys.postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Sat, 11 Aug 2018 01:28:47 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "PG" == PG Bug reporting form writes: PG> From a report on IRC: PG> XMLTABLE runs a lot of setup code in the per-query memory context - PG> resulting in allocations of copies of namespace names, other PG> values, and _multiple copies of the passed-in XML document_, which PG> are not freed anywhere. Alvaro, I think this comment of yours from when you committed this work is relevant: >> I just pushed XMLTABLE, after some additional changes. Please test >> it thoroughly and report any problems. [...] >> Some changes I made: >> * I removed the "buildercxt" memory context. It seemed mostly >> pointless, and I was disturbed by the MemoryContextResetOnly(). >> Per-value memory still uses the per-value memory context, but the >> rest of the stuff is in the per-query context, which should be >> pretty much the same. A quick reading suggests that the per-value context should have been changed to not be a child of "buildercxt" (which would avoid the MemoryContextResetOnly issue - that's a good sign that you've put a child context under the wrong parent). But the use of the per-query context instead is exactly what causes this blowup; compare with what nodeFunctionscan does with its "argcontext" (and the corresponding comments in ExecMakeTableFunctionResult). -- Andrew (irc:RhodiumToad)