Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e4d8d43

Browse files
committed
Fix (I hope) resource leakage in EvalPlanQual: open subplans must be
properly shut down in EndPlan, else we fail to free buffers and so forth that they hold.
1 parent 891039c commit e4d8d43

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/backend/executor/execMain.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
*
2929
* IDENTIFICATION
30-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.110 2000/03/09 05:15:33 tgl Exp $
30+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.111 2000/04/07 00:59:17 tgl Exp $
3131
*
3232
*-------------------------------------------------------------------------
3333
*/
@@ -73,6 +73,7 @@ static void ExecDelete(TupleTableSlot *slot, ItemPointer tupleid,
7373
static void ExecReplace(TupleTableSlot *slot, ItemPointer tupleid,
7474
EState *estate);
7575
static TupleTableSlot *EvalPlanQualNext(EState *estate);
76+
static void EndEvalPlanQual(EState *estate);
7677
static void ExecCheckQueryPerms(CmdType operation, Query *parseTree,
7778
Plan *plan);
7879
static void ExecCheckPlanPerms(Plan *plan, CmdType operation,
@@ -925,6 +926,12 @@ EndPlan(Plan *plan, EState *estate)
925926
resultRelationInfo = estate->es_result_relation_info;
926927
intoRelationDesc = estate->es_into_relation_descriptor;
927928

929+
/*
930+
* shut down any PlanQual processing we were doing
931+
*/
932+
if (estate->es_evalPlanQual != NULL)
933+
EndEvalPlanQual(estate);
934+
928935
/*
929936
* shut down the query
930937
*/
@@ -2007,3 +2014,36 @@ lpqnext:;
20072014

20082015
return (slot);
20092016
}
2017+
2018+
static void
2019+
EndEvalPlanQual(EState *estate)
2020+
{
2021+
evalPlanQual *epq = (evalPlanQual *) estate->es_evalPlanQual;
2022+
EState *epqstate = &(epq->estate);
2023+
evalPlanQual *oldepq;
2024+
2025+
if (epq->rti == 0) /* still live? */
2026+
return;
2027+
2028+
for (;;)
2029+
{
2030+
ExecEndNode(epq->plan, epq->plan);
2031+
epqstate->es_tupleTable->next = 0;
2032+
heap_freetuple(epqstate->es_evTuple[epq->rti - 1]);
2033+
epqstate->es_evTuple[epq->rti - 1] = NULL;
2034+
/* pop old PQ from the stack */
2035+
oldepq = (evalPlanQual *) epqstate->es_evalPlanQual;
2036+
if (oldepq == (evalPlanQual *) NULL)
2037+
{
2038+
epq->rti = 0; /* this is the first (oldest) */
2039+
estate->es_useEvalPlan = false; /* PQ - mark as free */
2040+
break;
2041+
}
2042+
Assert(oldepq->rti != 0);
2043+
/* push current PQ to freePQ stack */
2044+
oldepq->free = epq;
2045+
epq = oldepq;
2046+
epqstate = &(epq->estate);
2047+
estate->es_evalPlanQual = (Pointer) epq;
2048+
}
2049+
}

0 commit comments

Comments
 (0)