summaryrefslogtreecommitdiff
path: root/src/include/utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-06-28 03:33:33 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-06-28 03:33:33 +0000
commit1aebc3618a0be13451918581ad390ad9a3518702 (patch)
treee8ab228245c43ff086bd8e9d65baf3d1d9a5f96a /src/include/utils
parentb601c8d8828ee02ffb195dead82b233b9572fe32 (diff)
downloadpostgresql-1aebc3618a0be13451918581ad390ad9a3518702.tar.gz
First phase of memory management rewrite (see backend/utils/mmgr/README
for details). It doesn't really do that much yet, since there are no short-term memory contexts in the executor, but the infrastructure is in place and long-term contexts are handled reasonably. A few long- standing bugs have been fixed, such as 'VACUUM; anything' in a single query string crashing. Also, out-of-memory is now considered a recoverable ERROR, not FATAL. Eliminate a large amount of crufty, now-dead code in and around memory management. Fix problem with holding off SIGTRAP, SIGSEGV, etc in postmaster and backend startup.
Diffstat (limited to 'src/include/utils')
-rw-r--r--src/include/utils/catcache.h6
-rw-r--r--src/include/utils/hsearch.h7
-rw-r--r--src/include/utils/mcxt.h60
-rw-r--r--src/include/utils/memutils.h252
-rw-r--r--src/include/utils/module.h26
-rw-r--r--src/include/utils/palloc.h79
-rw-r--r--src/include/utils/portal.h55
7 files changed, 153 insertions, 332 deletions
diff --git a/src/include/utils/catcache.h b/src/include/utils/catcache.h
index b8e4ce71d7..cba400bc00 100644
--- a/src/include/utils/catcache.h
+++ b/src/include/utils/catcache.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: catcache.h,v 1.24 2000/06/17 04:56:29 tgl Exp $
+ * $Id: catcache.h,v 1.25 2000/06/28 03:33:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -75,8 +75,10 @@ typedef struct catcache
#define InvalidCatalogCacheId (-1)
-extern GlobalMemory CacheCxt;
+/* this extern duplicates utils/memutils.h... */
+extern MemoryContext CacheMemoryContext;
+extern void CreateCacheMemoryContext(void);
extern void CatalogCacheIdInvalidate(int cacheId, Index hashIndex,
ItemPointer pointer);
extern void ResetSystemCache(void);
diff --git a/src/include/utils/hsearch.h b/src/include/utils/hsearch.h
index ef243da145..6d857175c9 100644
--- a/src/include/utils/hsearch.h
+++ b/src/include/utils/hsearch.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: hsearch.h,v 1.15 2000/04/12 17:16:55 momjian Exp $
+ * $Id: hsearch.h,v 1.16 2000/06/28 03:33:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -84,8 +84,7 @@ typedef struct htab
char *segbase; /* segment base address for calculating
* pointer values */
SEG_OFFSET *dir; /* 'directory' of segm starts */
- long *(*alloc) (); /* memory allocator (long * for alignment
- * reasons) */
+ void *(*alloc) (Size); /* memory allocator */
} HTAB;
typedef struct hashctl
@@ -99,7 +98,7 @@ typedef struct hashctl
long max_dsize; /* limit to dsize if directory size is
* limited */
long *segbase; /* base for calculating bucket + seg ptrs */
- long *(*alloc) (); /* memory allocation function */
+ void *(*alloc) (Size); /* memory allocation function */
long *dir; /* directory if allocated already */
long *hctl; /* location of header information in shd
* mem */
diff --git a/src/include/utils/mcxt.h b/src/include/utils/mcxt.h
deleted file mode 100644
index 7b867d8664..0000000000
--- a/src/include/utils/mcxt.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * mcxt.h
- * POSTGRES memory context definitions.
- *
- *
- * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * $Id: mcxt.h,v 1.17 2000/05/21 02:23:28 tgl Exp $
- *
- *-------------------------------------------------------------------------
- */
-#ifndef MCXT_H
-#define MCXT_H
-
-/* These types are declared in nodes/memnodes.h, but most users of memory
- * allocation should just treat them as abstract types, so we do not provide
- * the struct contents here.
- */
-
-typedef struct MemoryContextData *MemoryContext;
-typedef struct GlobalMemoryData *GlobalMemory;
-
-
-extern DLLIMPORT MemoryContext CurrentMemoryContext;
-extern MemoryContext TopMemoryContext;
-
-
-/*
- * MaxAllocSize
- * Arbitrary limit on size of allocations.
- *
- * Note:
- * There is no guarantee that allocations smaller than MaxAllocSize
- * will succeed. Allocation requests larger than MaxAllocSize will
- * be summarily denied.
- *
- * This value should not be referenced except in one place in the code.
- *
- * XXX This should be defined in a file of tunable constants.
- */
-#define MaxAllocSize (0xfffffff) /* 16G - 1 */
-
-/*
- * prototypes for functions in mcxt.c
- */
-extern void EnableMemoryContext(bool on);
-extern Pointer MemoryContextAlloc(MemoryContext context, Size size);
-extern Pointer MemoryContextRealloc(MemoryContext context,
- Pointer pointer,
- Size size);
-extern void MemoryContextFree(MemoryContext context, Pointer pointer);
-extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
-extern GlobalMemory CreateGlobalMemory(char *name);
-extern void GlobalMemoryDestroy(GlobalMemory context);
-extern void GlobalMemoryStats(void);
-
-
-#endif /* MCXT_H */
diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h
index 3e6ad2e53d..cbabdbf275 100644
--- a/src/include/utils/memutils.h
+++ b/src/include/utils/memutils.h
@@ -1,230 +1,114 @@
/*-------------------------------------------------------------------------
*
* memutils.h
- * this file contains general memory alignment, allocation
- * and manipulation stuff that used to be spread out
- * between the following files:
- *
- * align.h alignment macros
- * aset.h memory allocation set stuff
- * oset.h (used by aset.h)
+ * This file contains declarations for memory allocation utility
+ * functions. These are functions that are not quite widely used
+ * enough to justify going in utils/palloc.h, but are still part
+ * of the API of the memory management subsystem.
*
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: memutils.h,v 1.35 2000/05/21 02:23:28 tgl Exp $
+ * $Id: memutils.h,v 1.36 2000/06/28 03:33:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef MEMUTILS_H
#define MEMUTILS_H
-/* ----------------
- * Alignment macros: align a length or address appropriately for a given type.
- *
- * There used to be some incredibly crufty platform-dependent hackery here,
- * but now we rely on the configure script to get the info for us. Much nicer.
- *
- * NOTE: TYPEALIGN will not work if ALIGNVAL is not a power of 2.
- * That case seems extremely unlikely to occur in practice, however.
- * ----------------
- */
+#include "nodes/memnodes.h"
-#define TYPEALIGN(ALIGNVAL,LEN) (((long)(LEN) + (ALIGNVAL-1)) & ~(ALIGNVAL-1))
-
-#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
-#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
-#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
-#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
-#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
-
-/*****************************************************************************
- * oset.h -- Fixed format ordered set definitions. *
- *****************************************************************************/
-/* Note:
- * Fixed format ordered sets are <EXPLAIN>.
- * XXX This is a preliminary version. Work is needed to explain
- * XXX semantics of the external definitions. Otherwise, the
- * XXX functional interface should not change.
- *
- */
-
-typedef struct OrderedElemData OrderedElemData;
-typedef OrderedElemData *OrderedElem;
-typedef struct OrderedSetData OrderedSetData;
-typedef OrderedSetData *OrderedSet;
-
-struct OrderedElemData
-{
- OrderedElem next; /* Next elem or &this->set->dummy */
- OrderedElem prev; /* Previous elem or &this->set->head */
- OrderedSet set; /* Parent set */
-};
-
-struct OrderedSetData
-{
- OrderedElem head; /* First elem or &this->dummy */
- OrderedElem dummy; /* (hack) Terminator == NULL */
- OrderedElem tail; /* Last elem or &this->head */
- Offset offset; /* Offset from struct base to elem */
- /* this could be signed short int! */
-};
-
-extern void OrderedSetInit(OrderedSet set, Offset offset);
-extern Pointer OrderedSetGetHead(OrderedSet set);
-extern Pointer OrderedElemGetPredecessor(OrderedElem elem);
-extern Pointer OrderedElemGetSuccessor(OrderedElem elem);
-extern void OrderedElemPop(OrderedElem elem);
-extern void OrderedElemPushInto(OrderedElem elem, OrderedSet Set);
-
-/*****************************************************************************
- * aset.h -- Allocation set definitions. *
- *****************************************************************************/
/*
- * Description:
- * An allocation set is a set containing allocated elements. When
- * an allocation is requested for a set, memory is allocated and a
- * pointer is returned. Subsequently, this memory may be freed or
- * reallocated. In addition, an allocation set may be reset which
- * will cause all memory allocated within it to be freed.
- *
- * XXX The following material about allocation modes is all OUT OF DATE.
- * aset.c currently implements only one allocation strategy,
- * DynamicAllocMode, and that's the only one anyone ever requests anyway.
- * If we ever did have more strategies, the new ones might or might
- * not look like what is described here...
- *
- * Allocations may occur in four different modes. The mode of
- * allocation does not affect the behavior of allocations except in
- * terms of performance. The allocation mode is set at the time of
- * set initialization. Once the mode is chosen, it cannot be changed
- * unless the set is reinitialized.
- *
- * "Dynamic" mode forces all allocations to occur in a heap. This
- * is a good mode to use when small memory segments are allocated
- * and freed very frequently. This is a good choice when allocation
- * characteristics are unknown. This is the default mode.
- *
- * "Static" mode attempts to allocate space as efficiently as possible
- * without regard to freeing memory. This mode should be chosen only
- * when it is known that many allocations will occur but that very
- * little of the allocated memory will be explicitly freed.
- *
- * "Tunable" mode is a hybrid of dynamic and static modes. The
- * tunable mode will use static mode allocation except when the
- * allocation request exceeds a size limit supplied at the time of set
- * initialization. "Big" objects are allocated using dynamic mode.
- *
- * "Bounded" mode attempts to allocate space efficiently given a limit
- * on space consumed by the allocation set. This restriction can be
- * considered a "soft" restriction, because memory segments will
- * continue to be returned after the limit is exceeded. The limit is
- * specified at the time of set initialization like for tunable mode.
+ * MaxAllocSize
+ * Arbitrary limit on size of allocations.
*
* Note:
- * Allocation sets are not automatically reset on a system reset.
- * Higher level code is responsible for cleaning up.
+ * There is no guarantee that allocations smaller than MaxAllocSize
+ * will succeed. Allocation requests larger than MaxAllocSize will
+ * be summarily denied.
*
- * There may be other modes in the future.
+ * XXX This should be defined in a file of tunable constants.
*/
+#define MaxAllocSize ((Size) 0xfffffff) /* 16G - 1 */
-/*
- * AllocPointer
- * Aligned pointer which may be a member of an allocation set.
- */
-typedef Pointer AllocPointer;
+#define AllocSizeIsValid(size) (0 < (size) && (size) <= MaxAllocSize)
/*
- * AllocMode
- * Mode of allocation for an allocation set.
- *
- * Note:
- * See above for a description of the various modes.
+ * All chunks allocated by any memory context manager are required to be
+ * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE.
+ * A currently-allocated chunk must contain a backpointer to its owning
+ * context as well as the allocated size of the chunk. The backpointer is
+ * used by pfree() and repalloc() to find the context to call. The allocated
+ * size is not absolutely essential, but it's expected to be needed by any
+ * reasonable implementation.
*/
-typedef enum AllocMode
+typedef struct StandardChunkHeader
{
- DynamicAllocMode, /* always dynamically allocate */
- StaticAllocMode, /* always "statically" allocate */
- TunableAllocMode, /* allocations are "tuned" */
- BoundedAllocMode /* allocations bounded to fixed usage */
-} AllocMode;
+ MemoryContext context; /* owning context */
+ Size size; /* size of data space allocated in chunk */
+} StandardChunkHeader;
-#define DefaultAllocMode DynamicAllocMode
+#define STANDARDCHUNKHEADERSIZE MAXALIGN(sizeof(StandardChunkHeader))
-typedef struct AllocSetData *AllocSet;
-typedef struct AllocBlockData *AllocBlock;
-typedef struct AllocChunkData *AllocChunk;
-
-/*
- * AllocSet
- * Allocation set.
- */
-typedef struct AllocSetData
-{
- AllocBlock blocks; /* head of list of blocks in this set */
-#define ALLOCSET_NUM_FREELISTS 8
- AllocChunk freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */
- /* Note: this will change in the future to support other modes */
-} AllocSetData;
/*
- * AllocBlock
- * An AllocBlock is the unit of memory that is obtained by aset.c
- * from malloc(). It contains one or more AllocChunks, which are
- * the units requested by palloc() and freed by pfree(). AllocChunks
- * cannot be returned to malloc() individually, instead they are put
- * on freelists by pfree() and re-used by the next palloc() that has
- * a matching request size.
+ * Standard top-level memory contexts.
*
- * AllocBlockData is the header data for a block --- the usable space
- * within the block begins at the next alignment boundary.
+ * Only TopMemoryContext and ErrorContext are initialized by
+ * MemoryContextInit() itself.
*/
-typedef struct AllocBlockData
-{
- AllocSet aset; /* aset that owns this block */
- AllocBlock next; /* next block in aset's blocks list */
- char *freeptr; /* start of free space in this block */
- char *endptr; /* end of space in this block */
-} AllocBlockData;
+extern MemoryContext TopMemoryContext;
+extern MemoryContext ErrorContext;
+extern MemoryContext PostmasterContext;
+extern MemoryContext CacheMemoryContext;
+extern MemoryContext QueryContext;
+extern MemoryContext TopTransactionContext;
+extern MemoryContext TransactionCommandContext;
-/*
- * AllocChunk
- * The prefix of each piece of memory in an AllocBlock
- */
-typedef struct AllocChunkData
-{
- /* aset is the owning aset if allocated, or the freelist link if free */
- void *aset;
- /* size is always the size of the usable space in the chunk */
- Size size;
-} AllocChunkData;
/*
- * AllocPointerIsValid
- * True iff pointer is valid allocation pointer.
+ * Memory-context-type-independent functions in mcxt.c
*/
-#define AllocPointerIsValid(pointer) PointerIsValid(pointer)
+extern void MemoryContextInit(void);
+extern void MemoryContextReset(MemoryContext context);
+extern void MemoryContextDelete(MemoryContext context);
+extern void MemoryContextResetChildren(MemoryContext context);
+extern void MemoryContextDeleteChildren(MemoryContext context);
+extern void MemoryContextResetAndDeleteChildren(MemoryContext context);
+extern void MemoryContextStats(MemoryContext context);
+extern bool MemoryContextContains(MemoryContext context, void *pointer);
/*
- * AllocSetIsValid
- * True iff set is valid allocation set.
+ * This routine handles the context-type-independent part of memory
+ * context creation. It's intended to be called from context-type-
+ * specific creation routines, and noplace else.
*/
-#define AllocSetIsValid(set) PointerIsValid(set)
+extern MemoryContext MemoryContextCreate(NodeTag tag, Size size,
+ MemoryContextMethods *methods,
+ MemoryContext parent,
+ const char *name);
-extern void AllocSetInit(AllocSet set, AllocMode mode, Size limit);
-extern void AllocSetReset(AllocSet set);
+/*
+ * Memory-context-type-specific functions
+ */
-extern bool AllocSetContains(AllocSet set, AllocPointer pointer);
-extern AllocPointer AllocSetAlloc(AllocSet set, Size size);
-extern void AllocSetFree(AllocSet set, AllocPointer pointer);
-extern AllocPointer AllocSetRealloc(AllocSet set, AllocPointer pointer,
- Size size);
+/* aset.c */
+extern MemoryContext AllocSetContextCreate(MemoryContext parent,
+ const char *name,
+ Size minContextSize,
+ Size initBlockSize,
+ Size maxBlockSize);
-extern void AllocSetDump(AllocSet set);
-extern void AllocSetStats(AllocSet set, const char *ident);
+/*
+ * 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_INITSIZE (8 * 1024)
+#define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024)
#endif /* MEMUTILS_H */
diff --git a/src/include/utils/module.h b/src/include/utils/module.h
deleted file mode 100644
index e7e45580ac..0000000000
--- a/src/include/utils/module.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * module.h
- * this file contains general "module" stuff that used to be
- * spread out between the following files:
- *
- * enbl.h module enable stuff
- * trace.h module trace stuff (now gone)
- *
- *
- * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * $Id: module.h,v 1.6 2000/01/26 05:58:38 momjian Exp $
- *
- *-------------------------------------------------------------------------
- */
-#ifndef MODULE_H
-#define MODULE_H
-
-/*
- * prototypes for functions in init/enbl.c
- */
-extern bool BypassEnable(int *enableCountInOutP, bool on);
-
-#endif /* MODULE_H */
diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h
index 0ec6caabbb..4bfdedff7e 100644
--- a/src/include/utils/palloc.h
+++ b/src/include/utils/palloc.h
@@ -3,36 +3,85 @@
* palloc.h
* POSTGRES memory allocator definitions.
*
+ * This file contains the basic memory allocation interface that is
+ * needed by almost every backend module. It is included directly by
+ * postgres.h, so the definitions here are automatically available
+ * everywhere. Keep it lean!
+ *
+ * Memory allocation occurs within "contexts". Every chunk obtained from
+ * palloc()/MemoryContextAlloc() is allocated within a specific context.
+ * The entire contents of a context can be freed easily and quickly by
+ * resetting or deleting the context --- this is both faster and less
+ * prone to memory-leakage bugs than releasing chunks individually.
+ * We organize contexts into context trees to allow fine-grain control
+ * over chunk lifetime while preserving the certainty that we will free
+ * everything that should be freed. See utils/mmgr/README for more info.
+ *
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: palloc.h,v 1.12 2000/01/26 05:58:38 momjian Exp $
+ * $Id: palloc.h,v 1.13 2000/06/28 03:33:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PALLOC_H
#define PALLOC_H
-#ifdef PALLOC_IS_MALLOC
+/*
+ * Type MemoryContextData is declared in nodes/memnodes.h. Most users
+ * of memory allocation should just treat it as an abstract type, so we
+ * do not provide the struct contents here.
+ */
+typedef struct MemoryContextData *MemoryContext;
+
+/*
+ * CurrentMemoryContext is the default allocation context for palloc().
+ * We declare it here so that palloc() can be a macro. Avoid accessing it
+ * directly! Instead, use MemoryContextSwitchTo() to change the setting.
+ */
+extern DLLIMPORT MemoryContext CurrentMemoryContext;
+
+/*
+ * Fundamental memory-allocation operations (more are in utils/memutils.h)
+ */
+extern void *MemoryContextAlloc(MemoryContext context, Size size);
+
+#define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz))
-#define palloc(s) malloc(s)
-#define pfree(p) free(p)
-#define repalloc(p,s) realloc((p),(s))
+extern void pfree(void *pointer);
-#else /* ! PALLOC_IS_MALLOC */
+extern void *repalloc(void *pointer, Size size);
-/* ----------
- * In the case we use memory contexts, use macro's for palloc() etc.
- * ----------
+extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
+
+/*
+ * These are like standard strdup() except the copied string is
+ * allocated in a context, not with malloc().
+ */
+extern char *MemoryContextStrdup(MemoryContext context, const char *string);
+
+#define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str))
+
+
+/* ----------------
+ * Alignment macros: align a length or address appropriately for a given type.
+ *
+ * There used to be some incredibly crufty platform-dependent hackery here,
+ * but now we rely on the configure script to get the info for us. Much nicer.
+ *
+ * NOTE: TYPEALIGN will not work if ALIGNVAL is not a power of 2.
+ * That case seems extremely unlikely to occur in practice, however.
+ * ----------------
*/
-#define palloc(s) ((void *)MemoryContextAlloc(CurrentMemoryContext,(Size)(s)))
-#define pfree(p) MemoryContextFree(CurrentMemoryContext,(Pointer)(p))
-#define repalloc(p,s) ((void *)MemoryContextRealloc(CurrentMemoryContext,(Pointer)(p),(Size)(s)))
-#endif /* PALLOC_IS_MALLOC */
+#define TYPEALIGN(ALIGNVAL,LEN) (((long)(LEN) + (ALIGNVAL-1)) & ~(ALIGNVAL-1))
+
+#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
+#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
+#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
+#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
+#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
-/* like strdup except uses palloc */
-extern char *pstrdup(const char *pointer);
#endif /* PALLOC_H */
diff --git a/src/include/utils/portal.h b/src/include/utils/portal.h
index 406fcc6af2..bb240fe599 100644
--- a/src/include/utils/portal.h
+++ b/src/include/utils/portal.h
@@ -7,16 +7,14 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: portal.h,v 1.23 2000/04/12 17:16:55 momjian Exp $
+ * $Id: portal.h,v 1.24 2000/06/28 03:33:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Note:
* A portal is an abstraction which represents the execution state of
- * a running query (or a fixed sequence of queries). The "blank portal" is
- * a portal with an InvalidName. This blank portal is in existance except
- * between calls to BlankPortalAssignName and GetPortalByName(NULL).
+ * a running query (or a fixed sequence of queries).
*
* Note:
* now that PQ calls can be made from within a backend, a portal
@@ -29,27 +27,18 @@
#include "executor/execdesc.h"
#include "nodes/memnodes.h"
-typedef struct PortalBlockData
-{
- AllocSetData setData;
- FixedItemData itemData;
-} PortalBlockData;
-
-typedef PortalBlockData *PortalBlock;
-typedef struct PortalD PortalD;
-typedef PortalD *Portal;
+typedef struct PortalD *Portal;
-struct PortalD
+typedef struct PortalD
{
- char *name; /* XXX PortalName */
- struct PortalVariableMemoryData variable;
- struct PortalHeapMemoryData heap;
- QueryDesc *queryDesc;
+ char *name; /* Portal's name */
+ MemoryContext heap; /* subsidiary memory */
+ QueryDesc *queryDesc; /* Info about query associated with portal */
TupleDesc attinfo;
EState *state;
- void (*cleanup) (Portal);
-};
+ void (*cleanup) (Portal); /* Cleanup routine (optional) */
+} PortalD;
/*
* PortalIsValid
@@ -57,36 +46,20 @@ struct PortalD
*/
#define PortalIsValid(p) PointerIsValid(p)
-/*
- * Special portals (well, their names anyway)
- */
-#define VACPNAME "<vacuum>"
-#define TRUNCPNAME "<truncate>"
-
-extern bool PortalNameIsSpecial(char *pname);
+extern void EnablePortalManager(void);
extern void AtEOXact_portals(void);
-extern void EnablePortalManager(bool on);
+extern Portal CreatePortal(char *name);
+extern void PortalDrop(Portal *portalP);
extern Portal GetPortalByName(char *name);
-extern Portal BlankPortalAssignName(char *name);
extern void PortalSetQuery(Portal portal, QueryDesc *queryDesc,
TupleDesc attinfo, EState *state,
void (*cleanup) (Portal portal));
extern QueryDesc *PortalGetQueryDesc(Portal portal);
extern EState *PortalGetState(Portal portal);
-extern Portal CreatePortal(char *name);
-extern void PortalDrop(Portal *portalP);
-extern void StartPortalAllocMode(AllocMode mode, Size limit);
-extern void EndPortalAllocMode(void);
-extern void PortalResetHeapMemory(Portal portal);
-extern PortalVariableMemory PortalGetVariableMemory(Portal portal);
-extern PortalHeapMemory PortalGetHeapMemory(Portal portal);
-extern void CommonSpecialPortalOpen(void);
-extern void CommonSpecialPortalClose(void);
-extern PortalVariableMemory CommonSpecialPortalGetMemory(void);
-extern bool CommonSpecialPortalIsOpen(void);
+extern MemoryContext PortalGetHeapMemory(Portal portal);
/* estimate of the maximum number of open portals a user would have,
- * used in initially sizing the PortalHashTable in EnablePortalManager()
+ * used in initially sizing the PortalHashTable in EnablePortalManager()
*/
#define PORTALS_PER_USER 10