From e64c7feb2fd80c89d2220cbe9e026a031f34509c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 15 Dec 2002 21:01:34 +0000 Subject: Tweak default memory context allocation policy so that a context is not given any malloc block until something is first allocated in it; but thereafter, MemoryContextReset won't release that first malloc block. This preserves the quick-reset property of the original policy, without forcing 8K to be allocated to every context whether any of it is ever used or not. Also, remove some more no-longer-needed explicit freeing during ExecEndPlan. --- src/backend/executor/execJunk.c | 36 +----------------------------------- src/backend/executor/execMain.c | 23 ++++++++--------------- src/backend/executor/spi.c | 8 ++++---- 3 files changed, 13 insertions(+), 54 deletions(-) (limited to 'src/backend/executor') diff --git a/src/backend/executor/execJunk.c b/src/backend/executor/execJunk.c index edaf7aa40cd..0f8b82d4f47 100644 --- a/src/backend/executor/execJunk.c +++ b/src/backend/executor/execJunk.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.33 2002/12/12 15:49:28 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.34 2002/12/15 21:01:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -63,8 +63,6 @@ JunkFilter * ExecInitJunkFilter(List *targetList, TupleDesc tupType, TupleTableSlot *slot) { - MemoryContext oldContext; - MemoryContext junkContext; JunkFilter *junkfilter; List *cleanTargetList; int len, @@ -79,19 +77,6 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType, AttrNumber *cleanMap; Expr *expr; - /* - * Make a memory context that will hold the JunkFilter as well as all - * the subsidiary structures we are about to create. We use smaller- - * than-default sizing parameters since we don't expect a very large - * volume of stuff here. - */ - junkContext = AllocSetContextCreate(CurrentMemoryContext, - "JunkFilterContext", - 1024, - 1024, - ALLOCSET_DEFAULT_MAXSIZE); - oldContext = MemoryContextSwitchTo(junkContext); - /* * First find the "clean" target list, i.e. all the entries in the * original target list which have a false 'resjunk' NOTE: make copy @@ -174,33 +159,14 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType, junkfilter->jf_cleanLength = cleanLength; junkfilter->jf_cleanTupType = cleanTupType; junkfilter->jf_cleanMap = cleanMap; - junkfilter->jf_junkContext = junkContext; junkfilter->jf_resultSlot = slot; if (slot) ExecSetSlotDescriptor(slot, cleanTupType, false); - MemoryContextSwitchTo(oldContext); - return junkfilter; } -/*------------------------------------------------------------------------- - * ExecFreeJunkFilter - * - * Release the data structures created by ExecInitJunkFilter. - *------------------------------------------------------------------------- - */ -void -ExecFreeJunkFilter(JunkFilter *junkfilter) -{ - /* - * Since the junkfilter is inside its own context, we just have to - * delete the context and we're set. - */ - MemoryContextDelete(junkfilter->jf_junkContext); -} - /*------------------------------------------------------------------------- * ExecGetJunkAttribute * diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index a25f2f2e296..f17fbcbb466 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.193 2002/12/15 16:17:45 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.194 2002/12/15 21:01:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -775,6 +775,12 @@ initResultRelInfo(ResultRelInfo *resultRelInfo, * ExecEndPlan * * Cleans up the query plan -- closes files and frees up storage + * + * NOTE: we are no longer very worried about freeing storage per se + * in this code; FreeExecutorState should be guaranteed to release all + * memory that needs to be released. What we are worried about doing + * is closing relations and dropping buffer pins. Thus, for example, + * tuple tables must be cleared or dropped to ensure pins are released. * ---------------------------------------------------------------- */ void @@ -803,7 +809,7 @@ ExecEndPlan(PlanState *planstate, EState *estate) /* * close the result relation(s) if any, but hold locks until xact - * commit. Also clean up junkfilters if present. + * commit. */ resultRelInfo = estate->es_result_relations; for (i = estate->es_num_result_relations; i > 0; i--) @@ -811,9 +817,6 @@ ExecEndPlan(PlanState *planstate, EState *estate) /* Close indices and then the relation itself */ ExecCloseIndices(resultRelInfo); heap_close(resultRelInfo->ri_RelationDesc, NoLock); - /* Delete the junkfilter if any */ - if (resultRelInfo->ri_junkFilter != NULL) - ExecFreeJunkFilter(resultRelInfo->ri_junkFilter); resultRelInfo++; } @@ -823,16 +826,6 @@ ExecEndPlan(PlanState *planstate, EState *estate) if (estate->es_into_relation_descriptor != NULL) heap_close(estate->es_into_relation_descriptor, NoLock); - /* - * There might be a junkfilter without a result relation. - */ - if (estate->es_num_result_relations == 0 && - estate->es_junkFilter != NULL) - { - ExecFreeJunkFilter(estate->es_junkFilter); - estate->es_junkFilter = NULL; - } - /* * close any relations selected FOR UPDATE, again keeping locks */ diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index cde9ab6ff6e..f39c481db93 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.80 2002/12/15 16:17:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.81 2002/12/15 21:01:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1489,9 +1489,9 @@ _SPI_copy_plan(_SPI_plan *plan, int location) */ plancxt = AllocSetContextCreate(parentcxt, "SPI Plan", - 1024, - 1024, - ALLOCSET_DEFAULT_MAXSIZE); + ALLOCSET_SMALL_MINSIZE, + ALLOCSET_SMALL_INITSIZE, + ALLOCSET_SMALL_MAXSIZE); oldcxt = MemoryContextSwitchTo(plancxt); /* Copy the SPI plan into its own context */ -- cgit v1.2.3