In array_agg(), don't create a new context for every group.
Jeff Davis <jdavis@postgresql.org>
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.
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/executor/nodeSubplan.c | modified | +2 −2 |
| src/backend/utils/adt/arrayfuncs.c | modified | +71 −35 |
| src/backend/utils/adt/array_userfuncs.c | modified | +12 −2 |
| src/backend/utils/adt/xml.c | modified | +1 −1 |
| src/include/utils/array.h | modified | +5 −3 |
| src/pl/plperl/plperl.c | modified | +1 −1 |