Re: tuplesort memory usage: grow_memtuples

Peter Geoghegan <peter@2ndquadrant.com>

From: Peter Geoghegan <peter@2ndquadrant.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Simon Riggs <simon@2ndquadrant.com>, Jeff Janes <jeff.janes@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2012-11-15T17:29:19Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Incorporate a couple of recent tuplesort.c improvements into tuplestore.c.

On 15 November 2012 16:09, Robert Haas <robertmhaas@gmail.com> wrote:
> I'm still not too sure why this part is OK:
>
>         /* This may not be our first time through */
>         if (newmemtupsize <= memtupsize)
>             return false;
>
> Suppose we enlarge the memtuples array by something other than a
> multiple of 2, and then we kick out all of the tuples that are
> currently in memory and load a new group with a smaller average size.
> ISTM that it could now appear that the memtuples array can be useful
> further enlarged, perhaps by as little as one tuple, and that that
> this could happen repeatedly.  I think we should either refuse to grow
> the array unless we can increase it by at least, say, 10%, or else set
> a flag after the final enlargement that acts as a hard stop to any
> further growth.

I thought that the flag added to Tuplesortstate in earlier revisions
was a little bit ugly. I can see the concern though, and I suppose
that given the alternative is to add a heuristic, simply using a flag
may be the best way to proceed.

-- 
Peter Geoghegan       http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services