In array_agg(), don't create a new context for every group.
authorJeff Davis <jdavis@postgresql.org>
Sun, 22 Feb 2015 01:24:48 +0000 (17:24 -0800)
committerJeff Davis <jdavis@postgresql.org>
Sun, 22 Feb 2015 01:24:48 +0000 (17:24 -0800)
commitb419865a814abbca12bdd6eef6a3d5ed67f432e1
treee1cce5a0394a5d83f8f42e1b33e265bd12b69613
parente9fd5545de3bb4efe163af4a9c957badac86ccd7
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.
src/backend/executor/nodeSubplan.c
src/backend/utils/adt/array_userfuncs.c
src/backend/utils/adt/arrayfuncs.c
src/backend/utils/adt/xml.c
src/include/utils/array.h
src/pl/plperl/plperl.c