* Copyright (c) 2002, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.11 2002/12/15 16:17:42 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.12 2002/12/15 21:01:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* Make a permanent memory context for the hashtable entry */
entrycxt = AllocSetContextCreate(TopMemoryContext,
stmt_name,
- 1024,
- 1024,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_SMALL_MINSIZE,
+ ALLOCSET_SMALL_INITSIZE,
+ ALLOCSET_SMALL_MAXSIZE);
oldcxt = MemoryContextSwitchTo(entrycxt);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.141 2002/11/25 03:36:50 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.142 2002/12/15 21:01:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
void
DeferredTriggerInit(void)
{
- /*
- * Since this context will never be reset, give it a minsize of 0.
- * This avoids using any memory if the session never stores anything.
- */
deftrig_gcxt = AllocSetContextCreate(TopMemoryContext,
"DeferredTriggerSession",
- 0,
+ ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
}
/*
* Create the per transaction memory context and copy all states from
- * the per session context to here. Set the minsize to 0 to avoid
- * wasting memory if there is no deferred trigger data.
+ * the per session context to here.
*/
deftrig_cxt = AllocSetContextCreate(TopTransactionContext,
"DeferredTriggerXact",
- 0,
+ ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
oldcxt = MemoryContextSwitchTo(deftrig_cxt);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
ExecInitJunkFilter(List *targetList, TupleDesc tupType,
TupleTableSlot *slot)
{
- MemoryContext oldContext;
- MemoryContext junkContext;
JunkFilter *junkfilter;
List *cleanTargetList;
int len,
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
* of the Resdom nodes, because we have to change the 'resno's...
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
*
* Given a tuple (slot), the junk filter and a junk attribute's name,
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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
/*
* 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--)
/* 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++;
}
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
*/
foreach(l, estate->es_rowMark)
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
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 */
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.181 2002/11/15 17:18:49 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.182 2002/12/15 21:01:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
rulescxt = AllocSetContextCreate(CacheMemoryContext,
RelationGetRelationName(relation),
- 0, /* minsize */
- 1024, /* initsize */
- 1024); /* maxsize */
+ ALLOCSET_SMALL_MINSIZE,
+ ALLOCSET_SMALL_INITSIZE,
+ ALLOCSET_SMALL_MAXSIZE);
relation->rd_rulescxt = rulescxt;
/*
*/
indexcxt = AllocSetContextCreate(CacheMemoryContext,
RelationGetRelationName(relation),
- 0, /* minsize */
- 512, /* initsize */
- 1024); /* maxsize */
+ ALLOCSET_SMALL_MINSIZE,
+ ALLOCSET_SMALL_INITSIZE,
+ ALLOCSET_SMALL_MAXSIZE);
relation->rd_indexcxt = indexcxt;
/*
*/
indexcxt = AllocSetContextCreate(CacheMemoryContext,
RelationGetRelationName(rel),
- 0, /* minsize */
- 512, /* initsize */
- 1024); /* maxsize */
+ ALLOCSET_SMALL_MINSIZE,
+ ALLOCSET_SMALL_INITSIZE,
+ ALLOCSET_SMALL_MAXSIZE);
rel->rd_indexcxt = indexcxt;
/* next, read the index strategy map */
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.48 2002/09/04 20:31:33 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.49 2002/12/15 21:01:34 tgl Exp $
*
* NOTE:
* This is a new (Feb. 05, 1999) implementation of the allocation set
* Frees all memory which is allocated in the given set.
*
* Actually, this routine has some discretion about what to do.
- * It should mark all allocated chunks freed, but it need not
- * necessarily give back all the resources the set owns. Our
- * actual implementation is that we hang on to any "keeper"
- * block specified for the set.
+ * It should mark all allocated chunks freed, but it need not necessarily
+ * give back all the resources the set owns. Our actual implementation is
+ * that we hang onto any "keeper" block specified for the set. In this way,
+ * we don't thrash malloc() when a context is repeatedly reset after small
+ * allocations, which is typical behavior for per-tuple contexts.
*/
static void
AllocSetReset(MemoryContext context)
block->freeptr = ((char *) block) + ALLOC_BLOCKHDRSZ;
block->endptr = ((char *) block) + blksize;
+ /*
+ * If this is the first block of the set, make it the "keeper" block.
+ * Formerly, a keeper block could only be created during context
+ * creation, but allowing it to happen here lets us have fast reset
+ * cycling even for contexts created with minContextSize = 0; that
+ * way we don't have to force space to be allocated in contexts that
+ * might never need any space. Don't mark an oversize block as
+ * a keeper, however.
+ */
+ if (set->blocks == NULL && blksize == set->initBlockSize)
+ {
+ Assert(set->keeper == NULL);
+ set->keeper = block;
+ }
+
block->next = set->blocks;
set->blocks = block;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.36 2002/11/13 00:37:06 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.37 2002/12/15 21:01:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
TopMemoryContext = AllocSetContextCreate((MemoryContext) NULL,
"TopMemoryContext",
- 8 * 1024,
+ 0,
8 * 1024,
8 * 1024);
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: executor.h,v 1.84 2002/12/15 16:17:54 tgl Exp $
+ * $Id: executor.h,v 1.85 2002/12/15 21:01:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
extern JunkFilter *ExecInitJunkFilter(List *targetList, TupleDesc tupType,
TupleTableSlot *slot);
-extern void ExecFreeJunkFilter(JunkFilter *junkfilter);
extern bool ExecGetJunkAttribute(JunkFilter *junkfilter, TupleTableSlot *slot,
char *attrName, Datum *value, bool *isNull);
extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot);
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: execnodes.h,v 1.86 2002/12/15 16:17:56 tgl Exp $
+ * $Id: execnodes.h,v 1.87 2002/12/15 21:01:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* cleanMap: A map with the correspondence between the non-junk
* attribute numbers of the "original" tuple and the
* attribute numbers of the "clean" tuple.
- * junkContext: memory context holding the JunkFilter node and all
- * its subsidiary data structures.
* resultSlot: tuple slot that can be used to hold cleaned tuple.
- *
- * NOTE: the original targetList and tupType are passed to ExecInitJunkFilter,
- * as is the resultSlot. These items do not belong to the JunkFilter. All
- * the other subsidiary structures are created during ExecInitJunkFilter,
- * and all of them can be freed by deleting the memory context junkContext.
- * This would not be needed if we had a cleaner approach to managing
- * query-lifetime data structures...
* ----------------
*/
typedef struct JunkFilter
int jf_cleanLength;
TupleDesc jf_cleanTupType;
AttrNumber *jf_cleanMap;
- MemoryContext jf_junkContext;
TupleTableSlot *jf_resultSlot;
} JunkFilter;
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: memutils.h,v 1.48 2002/09/04 20:31:45 momjian Exp $
+ * $Id: memutils.h,v 1.49 2002/12/15 21:01:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Recommended default alloc parameters, suitable for "ordinary" contexts
* that might hold quite a lot of data.
*/
-#define ALLOCSET_DEFAULT_MINSIZE (8 * 1024)
+#define ALLOCSET_DEFAULT_MINSIZE 0
#define ALLOCSET_DEFAULT_INITSIZE (8 * 1024)
#define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024)
+/*
+ * Recommended alloc parameters for "small" contexts that are not expected
+ * to contain much data (for example, a context to contain a query plan).
+ */
+#define ALLOCSET_SMALL_MINSIZE 0
+#define ALLOCSET_SMALL_INITSIZE (1 * 1024)
+#define ALLOCSET_SMALL_MAXSIZE (8 * 1024)
+
#endif /* MEMUTILS_H */