postgresql/src/backend/access/common
David Rowley 0229106afa Overload index_form_tuple to allow the memory context to be supplied
40af10b57 changed things so we make use of a generation memory context for
storing tuples to be sorted by tuplesort.c. That change does not play
nicely with the changes made in 9f03ca915 (back in 2014). That commit
changed things so that index_form_tuple() is called while switched into
the tuplestore's tuplecontext. In order to fetch the tuple from the index,
index_form_tuple() must do various memory allocations which are unrelated
to the storage of the final returned tuple. Although all of these
allocations are pfree'd, the fact that we now use a generation context
means that the memory for these pfree'd allocations won't be used again by
any other allocation due to generation.c's lack of freelists.  This could
result in sorts used for building indexes exceeding maintenance_work_mem
by a very large amount.

Here we fix it so we no longer allocate anything apart from the tuple
itself into the generation context by adding a new version of
index_form_tuple named index_form_tuple_context, which can be called to
specify the MemoryContext to allocate the tuple into.

Discussion: https://postgr.es/m/CAApHDvrHQkiFRHiGiAS-LMOvJN-eK-s762=tVzBz8ZqUea-a_A@mail.gmail.com
Backpatch-through: 15, where 40af10b57 was added.
2022-07-07 08:14:00 +12:00
..
Makefile Allow configurable LZ4 TOAST compression. 2021-03-19 15:10:38 -04:00
attmap.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
bufmask.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
detoast.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
heaptuple.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
indextuple.c Overload index_form_tuple to allow the memory context to be supplied 2022-07-07 08:14:00 +12:00
printsimple.c Refactor sending of DataRow messages in replication protocol 2022-07-06 08:42:56 +02:00
printtup.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
relation.c pgstat: normalize function naming. 2022-04-06 21:29:46 -07:00
reloptions.c Add construct_array_builtin, deconstruct_array_builtin 2022-07-01 11:23:15 +02:00
scankey.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
session.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
syncscan.c Change internal RelFileNode references to RelFileNumber or RelFileLocator. 2022-07-06 11:39:09 -04:00
toast_compression.c Remove error message hints mentioning configure options 2022-04-08 07:41:55 +02:00
toast_internals.c Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
tupconvert.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
tupdesc.c Refactor sending of RowDescription messages in replication protocol 2022-07-04 19:43:58 +02:00