pgsql: In array_agg(), don't create a new context for every group.

From: Jeff Davis <jdavis(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: In array_agg(), don't create a new context for every group.
Date: 2015-02-22 01:30:34
Message-ID: E1YPLNS-0003kw-1T@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

In array_agg(), don't create a new context for every group.

Previously, each new array created a new memory context that started
out at 8kB. This is incredibly wasteful when there are lots of small
groups of just a few elements each.

Change initArrayResult() and friends to accept a "subcontext" argument
to indicate whether the caller wants the ArrayBuildState allocated in
a new subcontext or not. If not, it can no longer be released
separately from the rest of the memory context.

Fixes bug report by Frank van Vugt on 2013-10-19.

Tomas Vondra. Reviewed by Ali Akbar, Tom Lane, and me.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/b419865a814abbca12bdd6eef6a3d5ed67f432e1

Modified Files
--------------
src/backend/executor/nodeSubplan.c | 4 +-
src/backend/utils/adt/array_userfuncs.c | 14 +++-
src/backend/utils/adt/arrayfuncs.c | 106 +++++++++++++++++++++----------
src/backend/utils/adt/xml.c | 2 +-
src/include/utils/array.h | 8 ++-
src/pl/plperl/plperl.c | 2 +-
6 files changed, 92 insertions(+), 44 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2015-02-22 07:19:13 pgsql: Rename variable in AllocSetContextCreate to be consistent.
Previous Message Tom Lane 2015-02-21 22:15:18 pgsql: Try to fix busted gettimeofday() code.