Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0dJd-0001KA-1R for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 00:50:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0dJc-000632-IR for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 00:50:04 +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 1e0dJb-00062g-S5 for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 00:50:04 +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 1e0dJZ-0003lL-AZ for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 00:50:02 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 6F1F120CD9; Fri, 6 Oct 2017 20:50:00 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Fri, 06 Oct 2017 20:50:00 -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=CbFlo6DghZmkf1yhUr Aky/Qi5gOSEBFo24bXXT33URM=; b=kJNYPjTRHrTAJLRw/hGFEaMqupjhjTuYgE LevvRtzi4zQcXdjTYES+n2wJYqH3coZ1qbCqW4Cn2KahATPhsUAebz86OIF6t5uj jsX/FgTK6JShpW8GzfYeZaeh9Iqhp6FvZeD52sE29t/sX3iPIqHKWUceb57jSf77 rFsOs3qTurBig4nFOhpZhEg10QyRtUdkR+eKIT09Q+Qz+WC5pyWtozccJEJ3zIcY YWHDQl5wxTvVRhEhVPxcJq614cFnwnUDoXX4VlJybWs2GnkIXITK9DMcOyw+nHhU Ioj/VtBHJA7oFPTQe4fWhFHQHuArbzucCkQ5SDPHhK59kC/TXF3A== X-ME-Sender: X-Sasl-enc: R0SLz+gVm5DIVr0SYJE37hW/iLON5VLEEVgszppqChaN 1507337400 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id 13A717F066; Fri, 6 Oct 2017 20:50:00 -0400 (EDT) Date: Fri, 6 Oct 2017 17:49:59 -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: <20171007004959.3xd5a4uvxbtfg3nz@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> <3403.1507337060@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <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 On 2017-10-06 20:44:20 -0400, Tom Lane wrote: > 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? Yea, that might be worthwhile. > (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.) Hm. Unrelated to the topic at hand, but I wonder how much it'd take to make some of the hot-path jsonb functionality tolerant of unaligned datums. 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