Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VbmNM-0001hP-IV for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Oct 2013 07:09:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VbmNL-0004Qd-SP for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Oct 2013 07:09:03 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VbmNJ-0004QS-OW for pgsql-bugs@postgresql.org; Thu, 31 Oct 2013 07:09:01 +0000 Received: from d4b26f12.static.ziggozakelijk.nl ([212.178.111.18] helo=storagefox.foxi.nl) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VbmNG-0003yk-Fe for pgsql-bugs@postgresql.org; Thu, 31 Oct 2013 07:09:01 +0000 Received: from techfox.foxi (techfox.foxi [192.168.0.31]) by storagefox.foxi.nl (8.14.5/8.14.5) with ESMTP id r9V78q8p024164; Thu, 31 Oct 2013 08:08:52 +0100 From: Frank van Vugt To: Tomas Vondra Cc: pgsql-bugs@postgresql.org, Valentine Gogichashvili 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> Organization: Foxi Group User-Agent: KMail/4.10.5 (Linux/3.7.10-1.16-desktop; KDE/4.10.5; x86_64; ; ) In-Reply-To: References: <3839201.Nfa2RvcheX@techfox.foxi> <1615181.fDHOPIPOzk@techfox.foxi> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Pg-Spam-Score: 0.8 (/) 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 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: 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