Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5bab36e

Browse files
committed
Revise executor APIs so that all per-query state structure is built in
a per-query memory context created by CreateExecutorState --- and destroyedby FreeExecutorState. This provides a final solution to the longstandingproblem of memory leaked by various ExecEndNode calls.
1 parent90b3a0b commit5bab36e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+801
-542
lines changed

‎src/backend/bootstrap/bootstrap.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.146 2002/12/13 19:45:45 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.147 2002/12/15 16:17:38 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1143,8 +1143,7 @@ index_register(Oid heap,
11431143
/* predicate will likely be null, but may as well copy it */
11441144
newind->il_info->ii_Predicate= (List*)
11451145
copyObject(indexInfo->ii_Predicate);
1146-
newind->il_info->ii_PredicateState= (List*)
1147-
ExecInitExpr((Expr*)newind->il_info->ii_Predicate,NULL);
1146+
newind->il_info->ii_PredicateState=NIL;
11481147

11491148
newind->il_next=ILHead;
11501149
ILHead=newind;

‎src/backend/catalog/index.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.207 2002/12/13 19:45:47 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.208 2002/12/15 16:17:38 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -41,7 +41,6 @@
4141
#include"executor/executor.h"
4242
#include"miscadmin.h"
4343
#include"optimizer/clauses.h"
44-
#include"optimizer/planmain.h"
4544
#include"optimizer/prep.h"
4645
#include"parser/parse_func.h"
4746
#include"storage/sinval.h"
@@ -912,7 +911,6 @@ BuildIndexInfo(Form_pg_index indexStruct)
912911

913912
/*
914913
* If partial index, convert predicate into expression nodetree
915-
* and prepare an execution state nodetree for it
916914
*/
917915
if (VARSIZE(&indexStruct->indpred)>VARHDRSZ)
918916
{
@@ -921,9 +919,7 @@ BuildIndexInfo(Form_pg_index indexStruct)
921919
predString=DatumGetCString(DirectFunctionCall1(textout,
922920
PointerGetDatum(&indexStruct->indpred)));
923921
ii->ii_Predicate=stringToNode(predString);
924-
fix_opfuncids((Node*)ii->ii_Predicate);
925-
ii->ii_PredicateState= (List*)
926-
ExecInitExpr((Expr*)ii->ii_Predicate,NULL);
922+
ii->ii_PredicateState=NIL;
927923
pfree(predString);
928924
}
929925
else
@@ -1489,9 +1485,10 @@ IndexBuildHeapScan(Relation heapRelation,
14891485
Datumattdata[INDEX_MAX_KEYS];
14901486
charnulls[INDEX_MAX_KEYS];
14911487
doublereltuples;
1492-
List*predicate=indexInfo->ii_PredicateState;
1488+
List*predicate;
14931489
TupleTabletupleTable;
14941490
TupleTableSlot*slot;
1491+
EState*estate;
14951492
ExprContext*econtext;
14961493
Snapshotsnapshot;
14971494
TransactionIdOldestXmin;
@@ -1503,28 +1500,42 @@ IndexBuildHeapScan(Relation heapRelation,
15031500

15041501
heapDescriptor=RelationGetDescr(heapRelation);
15051502

1503+
/*
1504+
* Need an EState for evaluation of functional-index functions
1505+
* and partial-index predicates.
1506+
*/
1507+
estate=CreateExecutorState();
1508+
econtext=GetPerTupleExprContext(estate);
1509+
15061510
/*
15071511
* If this is a predicate (partial) index, we will need to evaluate
15081512
* the predicate using ExecQual, which requires the current tuple to
1509-
* be in a slot of a TupleTable. In addition, ExecQual must have an
1510-
* ExprContext referring to that slot.Here, we initialize dummy
1511-
* TupleTable and ExprContext objects for this purpose. --Nels, Feb 92
1512-
*
1513-
* We construct the ExprContext anyway since we need a per-tuple
1514-
* temporary memory context for function evaluation -- tgl July 00
1513+
* be in a slot of a TupleTable.
15151514
*/
1516-
if (predicate!=NIL)
1515+
if (indexInfo->ii_Predicate!=NIL)
15171516
{
15181517
tupleTable=ExecCreateTupleTable(1);
15191518
slot=ExecAllocTableSlot(tupleTable);
15201519
ExecSetSlotDescriptor(slot,heapDescriptor, false);
1520+
1521+
/* Arrange for econtext's scan tuple to be the tuple under test */
1522+
econtext->ecxt_scantuple=slot;
1523+
1524+
/*
1525+
* Set up execution state for predicate. Note: we mustn't attempt to
1526+
* cache this in the indexInfo, since we're building it in a transient
1527+
* EState.
1528+
*/
1529+
predicate= (List*)
1530+
ExecPrepareExpr((Expr*)indexInfo->ii_Predicate,
1531+
estate);
15211532
}
15221533
else
15231534
{
15241535
tupleTable=NULL;
15251536
slot=NULL;
1537+
predicate=NIL;
15261538
}
1527-
econtext=MakeExprContext(slot,TransactionCommandContext);
15281539

15291540
/*
15301541
* Ok, begin our scan of the base relation. We use SnapshotAny
@@ -1687,9 +1698,10 @@ IndexBuildHeapScan(Relation heapRelation,
16871698

16881699
heap_endscan(scan);
16891700

1690-
if (predicate!=NIL)
1701+
if (tupleTable)
16911702
ExecDropTupleTable(tupleTable, true);
1692-
FreeExprContext(econtext);
1703+
1704+
FreeExecutorState(estate);
16931705

16941706
returnreltuples;
16951707
}

‎src/backend/commands/copy.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.186 2002/12/13 19:45:48 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.187 2002/12/15 16:17:38 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -35,7 +35,6 @@
3535
#include"mb/pg_wchar.h"
3636
#include"miscadmin.h"
3737
#include"nodes/makefuncs.h"
38-
#include"optimizer/planmain.h"
3938
#include"parser/parse_coerce.h"
4039
#include"parser/parse_relation.h"
4140
#include"rewrite/rewriteHandler.h"
@@ -803,6 +802,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
803802
slot=ExecAllocTableSlot(tupleTable);
804803
ExecSetSlotDescriptor(slot,tupDesc, false);
805804

805+
econtext=GetPerTupleExprContext(estate);
806+
806807
/*
807808
* Pick up the required catalog information for each attribute in the
808809
* relation, including the input function, the element type (to pass
@@ -841,8 +842,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
841842

842843
if (defexpr!=NULL)
843844
{
844-
fix_opfuncids(defexpr);
845-
defexprs[num_defaults]=ExecInitExpr((Expr*)defexpr,NULL);
845+
defexprs[num_defaults]=ExecPrepareExpr((Expr*)defexpr,
846+
estate);
846847
defmap[num_defaults]=i;
847848
num_defaults++;
848849
}
@@ -873,8 +874,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
873874
/* check whether any constraints actually found */
874875
if (node!= (Node*)prm)
875876
{
876-
fix_opfuncids(node);
877-
constraintexprs[i]=ExecInitExpr((Expr*)node,NULL);
877+
constraintexprs[i]=ExecPrepareExpr((Expr*)node,
878+
estate);
878879
hasConstraints= true;
879880
}
880881
}
@@ -934,8 +935,6 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
934935
copy_lineno=0;
935936
fe_eof= false;
936937

937-
econtext=GetPerTupleExprContext(estate);
938-
939938
/* Make room for a PARAM_EXEC value for domain constraint checks */
940939
if (hasConstraints)
941940
econtext->ecxt_param_exec_vals= (ParamExecData*)
@@ -953,9 +952,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
953952
/* Reset the per-tuple exprcontext */
954953
ResetPerTupleExprContext(estate);
955954

956-
/* Switchto and reset per-tuplememory context, too */
955+
/* Switchinto itsmemory context */
957956
MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
958-
MemoryContextReset(CurrentMemoryContext);
959957

960958
/* Initialize all values for row to NULL */
961959
MemSet(values,0,num_phys_attrs*sizeof(Datum));
@@ -1268,6 +1266,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
12681266
ExecDropTupleTable(tupleTable, true);
12691267

12701268
ExecCloseIndices(resultRelInfo);
1269+
1270+
FreeExecutorState(estate);
12711271
}
12721272

12731273

‎src/backend/commands/explain.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994-5, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.98 2002/12/14 00:17:50 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.99 2002/12/15 16:17:38 tgl Exp $
99
*
1010
*/
1111

@@ -206,6 +206,8 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate)
206206
gettimeofday(&starttime,NULL);
207207

208208
ExecutorEnd(queryDesc);
209+
FreeQueryDesc(queryDesc);
210+
209211
CommandCounterIncrement();
210212

211213
totaltime+=elapsed_time(&starttime);

‎src/backend/commands/indexcmds.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.94 2002/12/13 19:45:50 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.95 2002/12/15 16:17:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -27,7 +27,6 @@
2727
#include"executor/executor.h"
2828
#include"miscadmin.h"
2929
#include"optimizer/clauses.h"
30-
#include"optimizer/planmain.h"
3130
#include"optimizer/prep.h"
3231
#include"parser/parsetree.h"
3332
#include"parser/parse_coerce.h"
@@ -163,7 +162,6 @@ DefineIndex(RangeVar *heapRelation,
163162
if (predicate)
164163
{
165164
cnfPred=canonicalize_qual((Expr*)copyObject(predicate), true);
166-
fix_opfuncids((Node*)cnfPred);
167165
CheckPredicate(cnfPred,rangetable,relationId);
168166
}
169167

@@ -173,8 +171,7 @@ DefineIndex(RangeVar *heapRelation,
173171
*/
174172
indexInfo=makeNode(IndexInfo);
175173
indexInfo->ii_Predicate=cnfPred;
176-
indexInfo->ii_PredicateState= (List*)
177-
ExecInitExpr((Expr*)cnfPred,NULL);
174+
indexInfo->ii_PredicateState=NIL;
178175
indexInfo->ii_FuncOid=InvalidOid;
179176
indexInfo->ii_Unique=unique;
180177

‎src/backend/commands/portalcmds.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.5 2002/12/05 15:50:30 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.6 2002/12/15 16:17:42 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,28 +31,22 @@
3131
void
3232
PortalCleanup(Portalportal)
3333
{
34-
MemoryContextoldcontext;
35-
3634
/*
3735
* sanity checks
3836
*/
3937
AssertArg(PortalIsValid(portal));
4038
AssertArg(portal->cleanup==PortalCleanup);
4139

42-
/*
43-
* set proper portal-executor context before calling ExecMain.
44-
*/
45-
oldcontext=MemoryContextSwitchTo(PortalGetHeapMemory(portal));
46-
4740
/*
4841
* tell the executor to shutdown the query
4942
*/
5043
ExecutorEnd(PortalGetQueryDesc(portal));
5144

5245
/*
53-
* switch back to previous context
46+
* This should be unnecessary since the querydesc should be in the
47+
* portal's memory context, but do it anyway for symmetry.
5448
*/
55-
MemoryContextSwitchTo(oldcontext);
49+
FreeQueryDesc(PortalGetQueryDesc(portal));
5650
}
5751

5852

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp