I looked into Chris Spotts' recent report of massive memory leakage in
8.4, in a case involving array_agg() executed in a GROUP BY query:
http://archives.postgresql.org/pgsql-general/2009-07/msg00858.php
The reason for that turns out to be that we deliberately lobotomized
array_agg that way, just last month:
http://archives.postgresql.org/pgsql-committers/2009-06/msg00259.php
in response to this problem:
http://archives.postgresql.org/pgsql-hackers/2009-06/msg01186.php

We need a better idea.

One possibility is to have nodeAgg.c reset the "aggcontext" between
groups when in group mode.  I think this would be more than a one-liner
fix because it probably has pointers to transvalues that are in that
context, but it's surely doable.

Another possibility is to modify array_agg (and other aggregates that
try to use aggcontext) so that they distinguish hash- and group-mode
aggregation.  If we had array_agg attach its working context to the Agg
node's per-output-tuple context instead of aggcontext when in group
mode, I think everything would work as desired.  The main disadvantage
of this is modifying a coding convention that third-party code probably
is using.  (But OTOH, we have already required any such code to change
for 8.4.)

I haven't tested either of the above ideas --- just brainstorming
at this point.

Comments, better ideas?

                        regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to