summaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeGather.c
diff options
context:
space:
mode:
authorRobert Haas2017-12-04 15:33:09 +0000
committerRobert Haas2017-12-04 15:39:24 +0000
commit9f4992e2a9939a4c3d560c2ac58067861ee0029a (patch)
tree17585b681afb8a5b635c1b6f354c43a4c7a8bc4c /src/backend/executor/nodeGather.c
parenta852cfe96752b25c2deaa2653cffd60c0ec82ead (diff)
Remove memory leak protection from Gather and Gather Merge nodes.
Before commit 6b65a7fe62e129d5c2b85cd74d6a91d8f7564608, tqueue.c could perform tuple remapping and thus leak memory, which is why commit af33039317ddc4a0e38a02e2255c2bf453115fd2 made TupleQueueReaderNext run in a short-lived context. Now, however, tqueue.c has been reduced to a shadow of its former self, and there shouldn't be any chance of leaks any more. Accordingly, remove some tuple copying and memory context manipulation to speed up processing. Patch by me, reviewed by Amit Kapila. Some testing by Rafia Sabih. Discussion: http://postgr.es/m/CAA4eK1LSDydwrNjmYSNkfJ3ZivGSWH9SVswh6QpNzsMdj_oOQA@mail.gmail.com
Diffstat (limited to 'src/backend/executor/nodeGather.c')
-rw-r--r--src/backend/executor/nodeGather.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/src/backend/executor/nodeGather.c b/src/backend/executor/nodeGather.c
index 212612b5351..a44cf8409af 100644
--- a/src/backend/executor/nodeGather.c
+++ b/src/backend/executor/nodeGather.c
@@ -131,7 +131,6 @@ static TupleTableSlot *
ExecGather(PlanState *pstate)
{
GatherState *node = castNode(GatherState, pstate);
- TupleTableSlot *fslot = node->funnel_slot;
TupleTableSlot *slot;
ExprContext *econtext;
@@ -205,11 +204,8 @@ ExecGather(PlanState *pstate)
/*
* Reset per-tuple memory context to free any expression evaluation
- * storage allocated in the previous tuple cycle. This will also clear
- * any previous tuple returned by a TupleQueueReader; to make sure we
- * don't leave a dangling pointer around, clear the working slot first.
+ * storage allocated in the previous tuple cycle.
*/
- ExecClearTuple(fslot);
econtext = node->ps.ps_ExprContext;
ResetExprContext(econtext);
@@ -258,7 +254,6 @@ gather_getnext(GatherState *gatherstate)
PlanState *outerPlan = outerPlanState(gatherstate);
TupleTableSlot *outerTupleSlot;
TupleTableSlot *fslot = gatherstate->funnel_slot;
- MemoryContext tupleContext = gatherstate->ps.ps_ExprContext->ecxt_per_tuple_memory;
HeapTuple tup;
while (gatherstate->nreaders > 0 || gatherstate->need_to_scan_locally)
@@ -267,12 +262,7 @@ gather_getnext(GatherState *gatherstate)
if (gatherstate->nreaders > 0)
{
- MemoryContext oldContext;
-
- /* Run TupleQueueReaders in per-tuple context */
- oldContext = MemoryContextSwitchTo(tupleContext);
tup = gather_readnext(gatherstate);
- MemoryContextSwitchTo(oldContext);
if (HeapTupleIsValid(tup))
{
@@ -280,7 +270,7 @@ gather_getnext(GatherState *gatherstate)
fslot, /* slot in which to store the tuple */
InvalidBuffer, /* buffer associated with this
* tuple */
- false); /* slot should not pfree tuple */
+ true); /* pfree tuple when done with it */
return fslot;
}
}