Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0dEx-00011L-EY for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 00:45:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0dEw-0005jB-Pu for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 00:45:14 +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.84_2) (envelope-from ) id 1e0dEE-0004QB-GI for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 00:44:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0dE7-0003d6-SP for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 00:44: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 v970iKHG003404; Fri, 6 Oct 2017 20:44:20 -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: <20171007003654.l7yzevzlcemczzlz@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> <2219.1507336101@sss.pgh.pa.us> <20171007003654.l7yzevzlcemczzlz@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Fri, 06 Oct 2017 17:36:54 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3402.1507337060.1@sss.pgh.pa.us> Date: Fri, 06 Oct 2017 20:44:20 -0400 Message-ID: <3403.1507337060@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: > Hm. We've a bunch of places where we free detoasted data, just out of > efficiency concerns. And since the jsonb functions are quite likely to > detoast a lot, it doesn't seem unreasonable to do so for the most likely > offenders. I mean if you've a bit more complex expression involving a > few fields accessed, freeing in the accesses will reduce maximum memory > usage by quite a bit. I'm not suggesting to work towards leak free, just > towards reducing the lifetime of a few potentially large allocations. Dunno, for the common case of not-so-large values, this would just be a net loss. pfree'ing a value we can afford to ignore till the next per-tuple context reset is not a win. Maybe we need some kind of PG_FREE_IF_LARGE_COPY macro? Where it would kick in for values over 8K or thereabouts? (You might argue that any value that got detoasted at all would be large enough to be worth worrying about; but I think that falls down because we folded short-header unshorting into the detoast mechanism.) 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