Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0cyk-0008IO-VP for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 00:28:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0cyk-0008Ey-Bs for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 00:28:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0cyj-0008EI-JP for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 00:28:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0cyg-0003qI-ED for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 00:28:29 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v970SLMe002220; Fri, 6 Oct 2017 20:28:21 -0400 From: Tom Lane To: Andres Freund cc: Lucas Fairchild-Madar , pgsql-bugs@postgresql.org Subject: Re: json(b)_array_elements use causes very large memory usage when also referencing entire json document In-reply-to: <20171007002116.2fqr6z26byhsjwoe@alap3.anarazel.de> References: <1546.1507314635@sss.pgh.pa.us> <2376.1507315734@sss.pgh.pa.us> <4514.1507318623@sss.pgh.pa.us> <20171007002116.2fqr6z26byhsjwoe@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Fri, 06 Oct 2017 17:21:16 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2218.1507336101.1@sss.pgh.pa.us> Date: Fri, 06 Oct 2017 20:28:21 -0400 Message-ID: <2219.1507336101@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Andres Freund writes: > On 2017-10-06 15:37:03 -0400, Tom Lane wrote: >> So a leak would occur in any case ... but it's particularly awful in >> this case, because data->'id' involves detoasting the rather wide >> value of "data", which is then promptly leaked. > While not tackling the problem in a systematic manner, it seems like > it'd be a good idea to free the detoasted column in this and related > functions? I think that's basically a dead-end solution. It amounts to saying that no functions can leak memory, which is not a place we're ever likely to get to, especially given that there's been no policy favoring that in the past (with the narrow exception of btree comparison functions). >> As of v10, it might be possible to fix this for the tlist case >> as well, by doing something like using a separate short-lived >> context for the non-SRF tlist items. > Yea, that should be quite doable, slightly annoying to need more than > one expr context, but that seems unavoidable. Should even be doable for > SFRM_ValuePerCall? SFRM_Materialize isn't a "central" problem, given it > properly manages memory for the tuplestore and filling the tuplestore is > an internal matter. I'm not really convinced whether there's an issue for ValuePerCall SRFs. We've not had complaints about them, and I would think we would if that feature alone would create an issue. But I've not thought about it hard, nor tested. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs