Skip to content

Commit 04bcf9e

Browse files
committed
Adjust tuplestore.c not to allocate BufFiles in generation context
590b045 made it so tuplestore.c would store tuples inside a generation.c memory context. After fixing a bug report in 97651b0, it seems that it's probably best not to allocate BufFile related allocations in that context. Let's keep it just for tuple data. This adjusts the code to switch to the Tuplestorestate.context's parent, which is the MemoryContext that tuplestore_begin_common() was called in. It does not seem worth adding a new field in Tuplestorestate to store this when we can access it by looking at the Tuplestorestate's context's parent. Discussion: https://postgr.es/m/CAApHDvqFt_CdJtSr+E9YLZb7jZAyRCy3hjQ+ktM+dcOFVq-xkg@mail.gmail.com
1 parent 97651b0 commit 04bcf9e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/backend/utils/sort/tuplestore.c

+10
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
799799
TSReadPointer *readptr;
800800
int i;
801801
ResourceOwner oldowner;
802+
MemoryContext oldcxt;
802803

803804
state->tuples++;
804805

@@ -850,8 +851,17 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
850851
oldowner = CurrentResourceOwner;
851852
CurrentResourceOwner = state->resowner;
852853

854+
/*
855+
* We switch out of the state->context as this is a generation
856+
* context, which isn't ideal for allocations relating to the
857+
* BufFile.
858+
*/
859+
oldcxt = MemoryContextSwitchTo(state->context->parent);
860+
853861
state->myfile = BufFileCreateTemp(state->interXact);
854862

863+
MemoryContextSwitchTo(oldcxt);
864+
855865
CurrentResourceOwner = oldowner;
856866

857867
/*

0 commit comments

Comments
 (0)