pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Lucas Fairchild-Madar <lucas.madar@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: json(b)_array_elements use causes very large memory usage when also referencing entire json document
Date: Fri, 6 Oct 2017 17:49:59 -0700
Message-ID: <20171007004959.3xd5a4uvxbtfg3nz@alap3.anarazel.de> (raw)
In-Reply-To: <3403.1507337060@sss.pgh.pa.us>
References: <CAJmoq7OJ=ntoLRE0R8h+_Dt8KoNifDhQQua_w2y_d1e7T6nL-w@mail.gmail.com>
	<1546.1507314635@sss.pgh.pa.us>
	<CAJmoq7OmXJ_G87D_He5j9kRSraANsuV7Oatxg3bhMsuawvOJ3Q@mail.gmail.com>
	<2376.1507315734@sss.pgh.pa.us>
	<CAJmoq7MKcfk2+X8A5OeQqedg9rypGoesOOg2pJQ3SzfNBE22TA@mail.gmail.com>
	<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>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 2017-10-06 20:44:20 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> 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



view thread (23+ messages)  latest in thread

Message-ID: <20171007004959.3xd5a4uvxbtfg3nz@alap3.anarazel.de>
Permalink:  ../20171007004959.3xd5a4uvxbtfg3nz@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20171007004959.3xd5a4uvxbtfg3nz@alap3.anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andres@anarazel.de, tgl@sss.pgh.pa.us, lucas.madar@gmail.com
  Subject: Re: json(b)_array_elements use causes very large memory usage when also referencing entire json document
  In-Reply-To: <20171007004959.3xd5a4uvxbtfg3nz@alap3.anarazel.de>
  References: <CAJmoq7OJ=ntoLRE0R8h+_Dt8KoNifDhQQua_w2y_d1e7T6nL-w@mail.gmail.com> <1546.1507314635@sss.pgh.pa.us> <CAJmoq7OmXJ_G87D_He5j9kRSraANsuV7Oatxg3bhMsuawvOJ3Q@mail.gmail.com> <2376.1507315734@sss.pgh.pa.us> <CAJmoq7MKcfk2+X8A5OeQqedg9rypGoesOOg2pJQ3SzfNBE22TA@mail.gmail.com> <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> <20171007004959.3xd5a4uvxbtfg3nz@alap3.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox