aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/sort/tuplestore.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c
index 00eeb135d3e..444c8e25c21 100644
--- a/src/backend/utils/sort/tuplestore.c
+++ b/src/backend/utils/sort/tuplestore.c
@@ -799,6 +799,7 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
TSReadPointer *readptr;
int i;
ResourceOwner oldowner;
+ MemoryContext oldcxt;
state->tuples++;
@@ -850,8 +851,17 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
oldowner = CurrentResourceOwner;
CurrentResourceOwner = state->resowner;
+ /*
+ * We switch out of the state->context as this is a generation
+ * context, which isn't ideal for allocations relating to the
+ * BufFile.
+ */
+ oldcxt = MemoryContextSwitchTo(state->context->parent);
+
state->myfile = BufFileCreateTemp(state->interXact);
+ MemoryContextSwitchTo(oldcxt);
+
CurrentResourceOwner = oldowner;
/*