Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0d6y-0000XA-OP for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 00:37:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0d6y-0002Lx-Ax for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 00:37:00 +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 1e0d6x-0002J7-Kp for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 00:36:59 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0d6u-0003VV-Jn for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 00:36:58 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B606720B1F; Fri, 6 Oct 2017 20:36:55 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Fri, 06 Oct 2017 20:36:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=tVTGo1nmikjfMtbDFK n6rlku3ibM+S2nc8HyyomJ5hI=; b=YIIf1oXg9wdJML3KhDELE+72TTNgDNCURz TjiuEaJKZDXBHO7RYG25klc4N3ChimDxr1aIpqzG/987xThIuslzLfMm7W+429TN 18GGbHNezYhvXkuCYQn8i2qs3wMU+QueVXdZy2zvwLYC5cgnhQQnBnb4BDZsfuFB kliBmmooxP3dQg8mxHUpVJKuGUmd94OoT3FeWLu3X3HDdO9ds/TEfH8w4PSRLZQM +tyeUePshLiQfAGJtShqxOgS4Xge4RHKOOF6Fmm3YlpT50u6VmuEH8rz6Ju1/xUM 1qO3bVrUOs5lJ9iTudE6rypS76IN2hDTSS2gn4PZlv69T/kHUI2A== X-ME-Sender: X-Sasl-enc: 0Nsw/LW0V7fXtkthUPTKYCUjxb1HQHmWAX5q20BsoNvR 1507336615 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id 6FD2A7F066; Fri, 6 Oct 2017 20:36:55 -0400 (EDT) Date: Fri, 6 Oct 2017 17:36:54 -0700 From: Andres Freund To: Tom Lane 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 Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <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 On 2017-10-06 20:28:21 -0400, Tom Lane wrote: > 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). 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. Greetings, Andres Freund -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs