From: Tomas Vondra <tv@fuzzy.cz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Frank van Vugt <ftm.van.vugt@foxi.nl>
Cc: Tomas Vondra <tv@fuzzy.cz>
Cc: pgsql-bugs@postgresql.org
Cc: Valentine Gogichashvili <valgog@gmail.com>
Subject: Re: array_agg() on a set larger than some arbitrary(?) limit causes runaway memory usage and eventually memory exhaustion
Date: Sat, 2 Nov 2013 01:16:09 +0100
Message-ID: <83f4b150295c82d1687562e59e569b4c.squirrel@sq.gransy.com> (raw)
In-Reply-To: <22340.1383228316@sss.pgh.pa.us>
References: <3839201.Nfa2RvcheX@techfox.foxi>
<1615181.fDHOPIPOzk@techfox.foxi>
<c1b68cb9c6007d7fd7bcdbce3e8a9983.squirrel@sq.gransy.com>
<3014614.ujIC87ofob@techfox.foxi>
<22340.1383228316@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 31 Říjen 2013, 15:05, Tom Lane wrote:
> Frank van Vugt <ftm.van.vugt@foxi.nl> writes:
>> Op zondag 20 oktober 2013 12:57:43 schreef Tomas Vondra:
>>> Attached is a quick patch removing the local memory context and using
>>> aggcontext instead.
>
>> It looks like this didn't go into git yet. Will it be in v9.2.6/v9.3.1?
>
> Certainly not. We can consider it for 9.4, if Tomas submits it to the
> commitfest process, but it needs review and testing. In particular
> I'm skeptical that it probably outright breaks some cases (look at
> makeMdArrayResult) and results in substantial added bloat, not savings,
> in others.
Yes, I'll submit it to the next commitfest. And you're right that the
makeMdArrayResult is faulty - it shouldn't really do the
MemoryContextDelete as I reused the context of the aggregation function.
Actually, I'm quite surprised it did not fail, even though my tests were
only really sketchy.
As for the 9.2 / 9.3 branches, I think we should discuss whether the
current state is actually correct. I'm inclined to say that a code that
manages to crash a server with 64GB of virtual memory, although with very
light tweaking can happily complete with ~3.5GB of RAM, is not exactly
right.
It seems to me that the code somehow assumes the accumulated arrays are
going to be quite large - in that case preallocating > 1kB per group is
probably fine. I'm fine with "reasonable" preallocation, but 1kB seems way
too aggressive to me. But it's not possible to use smaller preallocation
because this is determined by the block size check in aset.c.
So I see three options for <9.4 versions:
(a) keeping the current implementation, that crashes with cases like this
(and I don't really like this option, because the code seems broken to me)
(b) keep the local memory context but tune it somehow - this however means
changes in aset.c, which however impacts significant part of the codebase
(not sure how much internal / external code relies on this behavior)
(c) remove the local memory context (I'm really wondering what other
benefit it might have in this particular case) and maybe tune the other
parameters (e.g. the initial size / growth rate of the array etc.).
I'd certainly vote for (c) in this case.
Tomas
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: tv@fuzzy.cz, tgl@sss.pgh.pa.us, ftm.van.vugt@foxi.nl, valgog@gmail.com
Subject: Re: array_agg() on a set larger than some arbitrary(?) limit causes runaway memory usage and eventually memory exhaustion
In-Reply-To: <83f4b150295c82d1687562e59e569b4c.squirrel@sq.gransy.com>
References: <3839201.Nfa2RvcheX@techfox.foxi> <1615181.fDHOPIPOzk@techfox.foxi> <c1b68cb9c6007d7fd7bcdbce3e8a9983.squirrel@sq.gransy.com> <3014614.ujIC87ofob@techfox.foxi> <22340.1383228316@sss.pgh.pa.us> <83f4b150295c82d1687562e59e569b4c.squirrel@sq.gransy.com>
* 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