pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frank van Vugt <ftm.van.vugt@foxi.nl>
To: 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: Thu, 31 Oct 2013 08:08:52 +0100
Message-ID: <3014614.ujIC87ofob@techfox.foxi> (raw)
In-Reply-To: <c1b68cb9c6007d7fd7bcdbce3e8a9983.squirrel@sq.gransy.com>
References: <3839201.Nfa2RvcheX@techfox.foxi>
	<1615181.fDHOPIPOzk@techfox.foxi>
	<c1b68cb9c6007d7fd7bcdbce3e8a9983.squirrel@sq.gransy.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hi,

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. I've also tuned down the preallocation. It's against
> 9.2 stable, so it should apply fine against your 9.2.4. But be careful,
> it's not really tested.

I applied the patch and ran my queries again with the following results:



> with g as (select * from f limit 1e5)
>         select array_agg(id), min(value)

used to be:
	Time: 361,242 ms
now:
	Time: 363,767 ms



> with g as (select * from f limit 1e6)
>         select array_agg(id), min(value)

used to be:
	Time: 3310,347 ms
now:
	Time: 2134,688 ms



> with g as (select * from f limit 1e7)
>         select array_agg(id), min(value)

used to be:
	Time: <none, fails>
now:
	Time: 23234,045 ms

The last query now uses up ~3.5GB of memory.





and as for the comcat() / string_agg() comparison:

> with g as (select * from f limit 1e7)
>         select comcat(id::text), min(value)

used to be / still is:
	Time: ~18.5 seconds
	Mem: ~6,5 GB


> with g as (select * from f limit 1e7)
>         select string_agg(id::text, ', '), min(value)

used to be:
	Time: ~28.5 seconds
	Mem: ~16 GB
now:
	Time: ~28.5 seconds
	Mem: ~12 GB



So, the patch seems to have the desired effect ;)

It looks like this didn't go into git yet. Will it be in v9.2.6/v9.3.1? Since 
it's still a 'rough' patch, I reversed it on our development server for now.





-- 

Best,




Frank.



-- 
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 (15+ messages)  latest in thread

Message-ID: <3014614.ujIC87ofob@techfox.foxi>
Permalink:  ../3014614.ujIC87ofob@techfox.foxi/
Also on:    postgresql.org/message-id/3014614.ujIC87ofob@techfox.foxi

 · 

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: ftm.van.vugt@foxi.nl, tv@fuzzy.cz, 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: <3014614.ujIC87ofob@techfox.foxi>
  References: <3839201.Nfa2RvcheX@techfox.foxi> <1615181.fDHOPIPOzk@techfox.foxi> <c1b68cb9c6007d7fd7bcdbce3e8a9983.squirrel@sq.gransy.com> <3014614.ujIC87ofob@techfox.foxi>

* 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