Commit 1aebc361 authored by Tom Lane's avatar Tom Lane

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.
parent b601c8d8
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/geqo.sgml,v 1.9 2000/03/31 03:27:40 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/geqo.sgml,v 1.10 2000/06/28 03:30:53 tgl Exp $
Genetic Optimizer
-->
......@@ -228,22 +228,6 @@ Improved cost size approximation of query plans since no longer
<Sect2>
<Title>Basic Improvements</Title>
<Sect3>
<Title>Improve freeing of memory when query is already processed</Title>
<Para>
With large <Command>join</Command> queries the computing time spent for the genetic query
optimization seems to be a mere <Emphasis>fraction</Emphasis> of the time
<ProductName>Postgres</ProductName>
needs for freeing memory via routine <Function>MemoryContextFree</Function>,
file <FileName>backend/utils/mmgr/mcxt.c</FileName>.
Debugging showed that it get stucked in a loop of routine
<Function>OrderedElemPop</Function>, file <FileName>backend/utils/mmgr/oset.c</FileName>.
The same problems arise with long queries when using the normal
<ProductName>Postgres</ProductName> query optimization algorithm.
</para>
</sect3>
<Sect3>
<Title>Improve genetic algorithm parameter settings</Title>
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/declare.sgml,v 1.8 1999/12/30 22:58:10 momjian Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/declare.sgml,v 1.9 2000/06/28 03:30:54 tgl Exp $
Postgres documentation
-->
......@@ -153,12 +153,13 @@ SELECT
<varlistentry>
<term><computeroutput>
NOTICE
BlankPortalAssignName: portal "<replaceable class="parameter">cursorname</replaceable>" already exists
NOTICE: Closing pre-existing portal "<replaceable class="parameter">cursorname</replaceable>"
</computeroutput></term>
<listitem>
<para>
This error occurs if <replaceable class="parameter">cursorname</replaceable> is already declared.
This message is reported if the same cursor name was already declared
in the current transaction block. The previous definition is
discarded.
</para>
</listitem>
</varlistentry>
......
......@@ -34,7 +34,7 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.55 2000/06/17 00:09:34 petere Exp $
# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.56 2000/06/28 03:30:57 tgl Exp $
#
#-------------------------------------------------------------------------
......@@ -237,8 +237,6 @@ install-headers: prebuildheaders $(SRCDIR)/include/config.h
$(HEADERDIR)/utils/fmgroids.h
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/utils/palloc.h \
$(HEADERDIR)/utils/palloc.h
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/utils/mcxt.h \
$(HEADERDIR)/utils/mcxt.h
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/access/attnum.h \
$(HEADERDIR)/access/attnum.h
$(INSTALL) $(INSTLOPTS) $(SRCDIR)/include/executor/spi.h \
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.71 2000/06/15 04:09:34 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.72 2000/06/28 03:31:04 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -1230,10 +1230,7 @@ heap_insert(Relation relation, HeapTuple tup)
* ----------------
*/
if (!OidIsValid(tup->t_data->t_oid))
{
tup->t_data->t_oid = newoid();
LastOidProcessed = tup->t_data->t_oid;
}
else
CheckMaxObjectId(tup->t_data->t_oid);
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.87 2000/06/22 22:31:17 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.88 2000/06/28 03:31:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -34,14 +34,14 @@
#include "miscadmin.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/exc.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/portal.h"
#define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t)))
extern void BaseInit(void);
extern void StartupXLOG(void);
extern void ShutdownXLOG(void);
extern void BootStrapXLOG(void);
......@@ -144,8 +144,8 @@ static Datum values[MAXATTR]; /* corresponding attribute values */
int numattr; /* number of attributes for cur. rel */
int DebugMode;
static GlobalMemory nogc = (GlobalMemory) NULL; /* special no-gc mem
* context */
static MemoryContext nogc = NULL; /* special no-gc mem context */
extern int optind;
extern char *optarg;
......@@ -240,6 +240,17 @@ BootstrapMain(int argc, char *argv[])
MyProcPid = getpid();
/*
* Fire up essential subsystems: error and memory management
*
* If we are running under the postmaster, this is done already.
*/
if (!IsUnderPostmaster)
{
EnableExceptionHandling(true);
MemoryContextInit();
}
/* ----------------
* process command arguments
* ----------------
......@@ -428,7 +439,6 @@ boot_openrel(char *relname)
if (Typ == (struct typmap **) NULL)
{
StartPortalAllocMode(DefaultAllocMode, 0);
rel = heap_openr(TypeRelationName, NoLock);
Assert(rel);
scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
......@@ -445,13 +455,13 @@ boot_openrel(char *relname)
while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
{
(*app)->am_oid = tup->t_data->t_oid;
memmove((char *) &(*app++)->am_typ,
(char *) GETSTRUCT(tup),
sizeof((*app)->am_typ));
memcpy((char *) &(*app)->am_typ,
(char *) GETSTRUCT(tup),
sizeof((*app)->am_typ));
app++;
}
heap_endscan(scan);
heap_close(rel, NoLock);
EndPortalAllocMode();
}
if (reldesc != NULL)
......@@ -1088,10 +1098,14 @@ index_register(char *heap,
* them later.
*/
if (nogc == (GlobalMemory) NULL)
nogc = CreateGlobalMemory("BootstrapNoGC");
if (nogc == NULL)
nogc = AllocSetContextCreate((MemoryContext) NULL,
"BootstrapNoGC",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
oldcxt = MemoryContextSwitchTo((MemoryContext) nogc);
oldcxt = MemoryContextSwitchTo(nogc);
newind = (IndexList *) palloc(sizeof(IndexList));
newind->il_heap = pstrdup(heap);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.133 2000/06/18 22:43:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.134 2000/06/28 03:31:22 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -188,38 +188,27 @@ heap_create(char *relname,
relname);
}
/* ----------------
* switch to the cache context so that we don't lose
* allocations at the end of this transaction, I guess.
* -cim 6/14/90
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
/* ----------------
* real ugly stuff to assign the proper relid in the relation
* descriptor follows.
* ----------------
*/
if (relname && !strcmp(RelationRelationName, relname))
if (relname && strcmp(RelationRelationName, relname) == 0)
{
relid = RelOid_pg_class;
nailme = true;
}
else if (relname && !strcmp(AttributeRelationName, relname))
else if (relname && strcmp(AttributeRelationName, relname) == 0)
{
relid = RelOid_pg_attribute;
nailme = true;
}
else if (relname && !strcmp(ProcedureRelationName, relname))
else if (relname && strcmp(ProcedureRelationName, relname) == 0)
{
relid = RelOid_pg_proc;
nailme = true;
}
else if (relname && !strcmp(TypeRelationName, relname))
else if (relname && strcmp(TypeRelationName, relname) == 0)
{
relid = RelOid_pg_type;
nailme = true;
......@@ -234,6 +223,15 @@ heap_create(char *relname,
(int) MyProcPid, uniqueId++);
}
/* ----------------
* switch to the cache context to create the relcache entry.
* ----------------
*/
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/* ----------------
* allocate a new relation descriptor.
* ----------------
......@@ -287,6 +285,8 @@ heap_create(char *relname,
/* ----------------
* have the storage manager create the relation.
*
* XXX shouldn't we switch out of CacheMemoryContext for that?
* ----------------
*/
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.119 2000/06/18 22:43:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.120 2000/06/28 03:31:23 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -442,10 +442,10 @@ ConstructIndexReldesc(Relation indexRelation, Oid amoid)
* context changes
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
indexRelation->rd_am = AccessMethodObjectIdGetForm(amoid);
......@@ -904,16 +904,16 @@ InitIndexStrategy(int numatts,
* it will be lost at the end of the transaction.
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
if (!CacheMemoryContext)
CreateCacheMemoryContext();
strategy = (IndexStrategy)
MemoryContextAlloc((MemoryContext) CacheCxt, strsize);
strategy = (IndexStrategy) MemoryContextAlloc(CacheMemoryContext,
strsize);
if (amsupport > 0)
{
strsize = numatts * (amsupport * sizeof(RegProcedure));
support = (RegProcedure *) MemoryContextAlloc((MemoryContext) CacheCxt,
support = (RegProcedure *) MemoryContextAlloc(CacheMemoryContext,
strsize);
}
else
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.44 2000/06/14 04:53:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.45 2000/06/28 03:31:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -217,8 +217,7 @@ ProcedureCreate(char *procedureName,
if (languageObjectId == SQLlanguageId)
{
querytree_list = pg_parse_and_rewrite(prosrc, typev, parameterCount,
FALSE);
querytree_list = pg_parse_and_rewrite(prosrc, typev, parameterCount);
/* typecheck return value */
pg_checkretval(typeObjectId, querytree_list);
}
......
......@@ -8,13 +8,9 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.80 2000/06/15 04:09:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.81 2000/06/28 03:31:28 tgl Exp $
*
* NOTES
* The PortalExecutorHeapMemory crap needs to be eliminated
* by designing a better executor / portal processing memory
* interface.
*
* The PerformAddAttribute() code, like most of the relation
* manipulating code in the commands/ directory, should go
* someplace closer to the lib/catalog code.
......@@ -40,13 +36,6 @@
#include "parser/parse.h"
#endif /* _DROP_COLUMN_HACK__ */
/* ----------------
* PortalExecutorHeapMemory stuff
*
* This is where the XXXSuperDuperHacky code was. -cim 3/15/90
* ----------------
*/
MemoryContext PortalExecutorHeapMemory = NULL;
/* --------------------------------
* PortalCleanup
......@@ -55,7 +44,7 @@ MemoryContext PortalExecutorHeapMemory = NULL;
void
PortalCleanup(Portal portal)
{
MemoryContext context;
MemoryContext oldcontext;
/* ----------------
* sanity checks
......@@ -68,8 +57,7 @@ PortalCleanup(Portal portal)
* set proper portal-executor context before calling ExecMain.
* ----------------
*/
context = MemoryContextSwitchTo((MemoryContext) PortalGetHeapMemory(portal));
PortalExecutorHeapMemory = (MemoryContext) PortalGetHeapMemory(portal);
oldcontext = MemoryContextSwitchTo(PortalGetHeapMemory(portal));
/* ----------------
* tell the executor to shutdown the query
......@@ -81,8 +69,7 @@ PortalCleanup(Portal portal)
* switch back to previous context
* ----------------
*/
MemoryContextSwitchTo(context);
PortalExecutorHeapMemory = (MemoryContext) NULL;
MemoryContextSwitchTo(oldcontext);
}
/* --------------------------------
......@@ -99,7 +86,7 @@ PerformPortalFetch(char *name,
Portal portal;
int feature;
QueryDesc *queryDesc;
MemoryContext context;
MemoryContext oldcontext;
Const limcount;
/* ----------------
......@@ -108,7 +95,7 @@ PerformPortalFetch(char *name,
*/
if (name == NULL)
{
elog(NOTICE, "PerformPortalFetch: blank portal unsupported");
elog(NOTICE, "PerformPortalFetch: missing portal name");
return;
}
......@@ -120,12 +107,11 @@ PerformPortalFetch(char *name,
limcount.type = T_Const;
limcount.consttype = INT4OID;
limcount.constlen = sizeof(int4);
limcount.constvalue = (Datum) count;
limcount.constisnull = FALSE;
limcount.constbyval = TRUE;
limcount.constisset = FALSE;
limcount.constiscast = FALSE;
limcount.constvalue = Int32GetDatum(count);
limcount.constisnull = false;
limcount.constbyval = true;
limcount.constisset = false;
limcount.constiscast = false;
/* ----------------
* get the portal from the portal name
......@@ -143,9 +129,7 @@ PerformPortalFetch(char *name,
* switch into the portal context
* ----------------
*/
context = MemoryContextSwitchTo((MemoryContext) PortalGetHeapMemory(portal));
AssertState(context == (MemoryContext) PortalGetHeapMemory(GetPortalByName(NULL)));
oldcontext = MemoryContextSwitchTo(PortalGetHeapMemory(portal));
/* ----------------
* setup "feature" to tell the executor what direction and
......@@ -174,8 +158,7 @@ PerformPortalFetch(char *name,
BeginCommand(name,
queryDesc->operation,
portal->attinfo, /* QueryDescGetTypeInfo(queryDesc),
* */
portal->attinfo, /* QueryDescGetTypeInfo(queryDesc) */
false, /* portal fetches don't end up in
* relations */
false, /* this is a portal fetch, not a "retrieve
......@@ -187,27 +170,23 @@ PerformPortalFetch(char *name,
* execute the portal fetch operation
* ----------------
*/
PortalExecutorHeapMemory = (MemoryContext) PortalGetHeapMemory(portal);
ExecutorRun(queryDesc, PortalGetState(portal), feature,
(Node *) NULL, (Node *) &limcount);
if (dest == None) /* MOVE */
pfree(queryDesc);
/* ----------------
* Switch back to old context.
* ----------------
*/
MemoryContextSwitchTo(oldcontext);
/* ----------------
* Note: the "end-of-command" tag is returned by higher-level
* utility code
*
* Return blank portal for now.
* Otherwise, this named portal will be cleaned.
* Note: portals will only be supported within a BEGIN...END
* block in the near future. Later, someone will fix it to
* do what is possible across transaction boundries.
* ----------------
*/
MemoryContextSwitchTo(
(MemoryContext) PortalGetHeapMemory(GetPortalByName(NULL)));
}
/* --------------------------------
......@@ -225,15 +204,10 @@ PerformPortalClose(char *name, CommandDest dest)
*/
if (name == NULL)
{
elog(NOTICE, "PerformPortalClose: blank portal unsupported");
elog(NOTICE, "PerformPortalClose: missing portal name");
return;
}
if (PortalNameIsSpecial(name))
elog(ERROR,
"The portal name \"%s\" is reserved for internal use",
name);
/* ----------------
* get the portal from the portal name
* ----------------
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.31 2000/06/17 23:41:36 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.32 2000/06/28 03:31:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -39,7 +39,6 @@
#include "utils/fmgroids.h"
#include "utils/syscache.h"
#include "miscadmin.h" /* ReindexDatabase() */
#include "utils/portal.h" /* ReindexDatabase() */
#include "catalog/catalog.h" /* ReindexDatabase() */
#define IsFuncIndex(ATTR_LIST) (((IndexElem*)lfirst(ATTR_LIST))->args != NIL)
......@@ -764,7 +763,6 @@ ReindexTable(const char *name, bool force)
* "ERROR" if table nonexistent.
* ...
*/
extern Oid MyDatabaseId;
void
ReindexDatabase(const char *dbname, bool force, bool all)
{
......@@ -780,7 +778,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
Oid db_id;
char *username;
ScanKeyData scankey;
PortalVariableMemory pmem;
MemoryContext private_context;
MemoryContext old;
int relcnt,
relalc,
......@@ -808,16 +806,34 @@ ReindexDatabase(const char *dbname, bool force, bool all)
db_id = dbtuple->t_data->t_oid;
db_owner = ((Form_pg_database) GETSTRUCT(dbtuple))->datdba;
heap_endscan(scan);
heap_close(relation, NoLock);
if (user_id != db_owner && !superuser)
elog(ERROR, "REINDEX DATABASE: Permission denied.");
if (db_id != MyDatabaseId)
elog(ERROR, "REINDEX DATABASE: Can be executed only on the currently open database.");
heap_close(relation, NoLock);
/*
* We cannot run inside a user transaction block; if we were
* inside a transaction, then our commit- and
* start-transaction-command calls would not have the intended effect!
*/
if (IsTransactionBlock())
elog(ERROR, "REINDEX DATABASE cannot run inside a BEGIN/END block");
/*
* Create a memory context that will survive forced transaction commits
* we do below. Since it is a child of QueryContext, it will go away
* eventually even if we suffer an error; there's no need for special
* abort cleanup logic.
*/
private_context = AllocSetContextCreate(QueryContext,
"ReindexDatabase",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
CommonSpecialPortalOpen();
pmem = CommonSpecialPortalGetMemory();
relationRelation = heap_openr(RelationRelationName, AccessShareLock);
scan = heap_beginscan(relationRelation, false, SnapshotNow, 0, NULL);
relcnt = relalc = 0;
......@@ -832,7 +848,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
}
if (((Form_pg_class) GETSTRUCT(tuple))->relkind == RELKIND_RELATION)
{
old = MemoryContextSwitchTo((MemoryContext) pmem);
old = MemoryContextSwitchTo(private_context);
if (relcnt == 0)
{
relalc = oncealc;
......@@ -859,6 +875,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
elog(NOTICE, "relation %d was reindexed", relids[i]);
CommitTransactionCommand();
}
CommonSpecialPortalClose();
StartTransactionCommand();
MemoryContextDelete(private_context);
}
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.69 2000/06/08 22:37:01 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.70 2000/06/28 03:31:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1029,8 +1029,8 @@ ltrmark:;
* end.
* ----------
*/
static GlobalMemory deftrig_gcxt = NULL;
static GlobalMemory deftrig_cxt = NULL;
static MemoryContext deftrig_gcxt = NULL;
static MemoryContext deftrig_cxt = NULL;
/* ----------
* Global data that tells which triggers are actually in
......@@ -1104,7 +1104,7 @@ deferredTriggerCheckState(Oid tgoid, int32 itemstate)
* as the current and return that.
* ----------
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) deftrig_cxt);
oldcxt = MemoryContextSwitchTo(deftrig_cxt);
trigstate = (DeferredTriggerStatus)
palloc(sizeof(DeferredTriggerStatusData));
......@@ -1366,7 +1366,12 @@ deferredTriggerInvokeEvents(bool immediate_only)
int
DeferredTriggerInit(void)
{
deftrig_gcxt = CreateGlobalMemory("DeferredTriggerSession");
deftrig_gcxt = AllocSetContextCreate(TopMemoryContext,
"DeferredTriggerSession",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
return 0;
}
......@@ -1395,8 +1400,12 @@ DeferredTriggerBeginXact(void)
* from the per session context to here.
* ----------
*/
deftrig_cxt = CreateGlobalMemory("DeferredTriggerXact");
oldcxt = MemoryContextSwitchTo((MemoryContext) deftrig_cxt);
deftrig_cxt = AllocSetContextCreate(TopTransactionContext,
"DeferredTriggerXact",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
oldcxt = MemoryContextSwitchTo(deftrig_cxt);
deftrig_all_isset = deftrig_dfl_all_isset;
deftrig_all_isdeferred = deftrig_dfl_all_isdeferred;
......@@ -1461,7 +1470,7 @@ DeferredTriggerEndXact(void)
deferredTriggerInvokeEvents(false);
GlobalMemoryDestroy(deftrig_cxt);
MemoryContextDelete(deftrig_cxt);
deftrig_cxt = NULL;
}
......@@ -1484,7 +1493,7 @@ DeferredTriggerAbortXact(void)
if (deftrig_cxt == NULL)
return;
GlobalMemoryDestroy(deftrig_cxt);
MemoryContextDelete(deftrig_cxt);
deftrig_cxt = NULL;
}
......@@ -1521,7 +1530,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
* ... outside of a transaction block
* ----------
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) deftrig_gcxt);
oldcxt = MemoryContextSwitchTo(deftrig_gcxt);
/* ----------
* Drop all information about individual trigger states per
......@@ -1555,7 +1564,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
* ... inside of a transaction block
* ----------
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) deftrig_cxt);
oldcxt = MemoryContextSwitchTo(deftrig_cxt);
/* ----------
* Drop all information about individual trigger states per
......@@ -1701,7 +1710,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
* states of individual triggers on session level.
* ----------
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) deftrig_gcxt);
oldcxt = MemoryContextSwitchTo(deftrig_gcxt);
foreach(l, loid)
{
......@@ -1739,7 +1748,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
* states of individual triggers on transaction level.
* ----------
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) deftrig_cxt);
oldcxt = MemoryContextSwitchTo(deftrig_cxt);
foreach(l, loid)
{
......@@ -1827,7 +1836,7 @@ DeferredTriggerSaveEvent(Relation rel, int event,
* Create a new event
* ----------
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) deftrig_cxt);
oldcxt = MemoryContextSwitchTo(deftrig_cxt);
ntriggers = rel->trigdesc->n_after_row[event];
triggers = rel->trigdesc->tg_after_row[event];
......@@ -2022,7 +2031,7 @@ DeferredTriggerSaveEvent(Relation rel, int event,
* Anything's fine up to here. Add the new event to the queue.
* ----------
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) deftrig_cxt);
oldcxt = MemoryContextSwitchTo(deftrig_cxt);
deferredTriggerAddEvent(new_event);
MemoryContextSwitchTo(oldcxt);
......
/*-------------------------------------------------------------------------
*
* user.c
* use pg_exec_query to create a new user in the catalog
* Commands for manipulating users and groups.
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.61 2000/06/25 14:24:59 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.62 2000/06/28 03:31:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.160 2000/06/17 21:48:43 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.161 2000/06/28 03:31:28 tgl Exp $
*
*-------------------------------------------------------------------------
......@@ -35,7 +35,6 @@
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/inval.h"
#include "utils/portal.h"
#include "utils/relcache.h"
#include "utils/syscache.h"
#include "utils/temprel.h"
......@@ -48,9 +47,7 @@
#endif
bool CommonSpecialPortalInUse = false;
static Portal vac_portal;
static MemoryContext vac_context = NULL;
static int MESSAGE_LEVEL; /* message level */
......@@ -82,14 +79,13 @@ static int vac_cmp_offno(const void *left, const void *right);
static int vac_cmp_vtlinks(const void *left, const void *right);
static bool enough_space(VacPage vacpage, Size len);
static char *show_rusage(struct rusage * ru0);
/* CommonSpecialPortal function at the bottom */
void
vacuum(char *vacrel, bool verbose, bool analyze, List *anal_cols)
{
NameData VacRel;
Name VacRelName;
PortalVariableMemory pmem;
MemoryContext old;
List *le;
List *anal_cols2 = NIL;
......@@ -114,8 +110,18 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *anal_cols)
else
MESSAGE_LEVEL = DEBUG;
/* Create special portal for cross-transaction storage */
CommonSpecialPortalOpen();
/*
* Create special memory context for cross-transaction storage.
*
* Since it is a child of QueryContext, it will go away eventually
* even if we suffer an error; there's no need for special abort
* cleanup logic.
*/
vac_context = AllocSetContextCreate(QueryContext,
"Vacuum",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
/* vacrel gets de-allocated on xact commit, so copy it to safe storage */
if (vacrel)
......@@ -127,8 +133,7 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *anal_cols)
VacRelName = NULL;
/* must also copy the column list, if any, to safe storage */
pmem = CommonSpecialPortalGetMemory();
old = MemoryContextSwitchTo((MemoryContext) pmem);
old = MemoryContextSwitchTo(vac_context);
foreach(le, anal_cols)
{
char *col = (char *) lfirst(le);
......@@ -198,11 +203,16 @@ vacuum_shutdown()
*/
unlink(RELCACHE_INIT_FILENAME);
/* Clean up working storage */
CommonSpecialPortalClose();
/* matches the CommitTransaction in PostgresMain() */
StartTransactionCommand();
/*
* Clean up working storage --- note we must do this after
* StartTransactionCommand, else we might be trying to delete
* the active context!
*/
MemoryContextDelete(vac_context);
vac_context = NULL;
}
/*
......@@ -239,8 +249,6 @@ getrels(NameData *VacRelP)
TupleDesc tupdesc;
HeapScanDesc scan;
HeapTuple tuple;
PortalVariableMemory portalmem;
MemoryContext old;
VRelList vrl,
cur;
Datum d;
......@@ -276,7 +284,6 @@ getrels(NameData *VacRelP)
F_CHAREQ, CharGetDatum('r'));
}
portalmem = CommonSpecialPortalGetMemory();
vrl = cur = (VRelList) NULL;
rel = heap_openr(RelationRelationName, AccessShareLock);
......@@ -302,25 +309,26 @@ getrels(NameData *VacRelP)
}
/* get a relation list entry for this guy */
old = MemoryContextSwitchTo((MemoryContext) portalmem);
if (vrl == (VRelList) NULL)
vrl = cur = (VRelList) palloc(sizeof(VRelListData));
vrl = cur = (VRelList)
MemoryContextAlloc(vac_context, sizeof(VRelListData));
else
{
cur->vrl_next = (VRelList) palloc(sizeof(VRelListData));
cur->vrl_next = (VRelList)
MemoryContextAlloc(vac_context, sizeof(VRelListData));
cur = cur->vrl_next;
}
MemoryContextSwitchTo(old);
cur->vrl_relid = tuple->t_data->t_oid;
cur->vrl_next = (VRelList) NULL;
}
if (found == false)
elog(NOTICE, "Vacuum: table not found");
heap_endscan(scan);
heap_close(rel, AccessShareLock);
if (!found)
elog(NOTICE, "Vacuum: table not found");
CommitTransactionCommand();
return vrl;
......@@ -2275,62 +2283,6 @@ vac_cmp_vtlinks(const void *left, const void *right)
}
/*
* This routines handle a special cross-transaction portal.
* However it is automatically closed in case of abort.
*/
void
CommonSpecialPortalOpen(void)
{
char *pname;
if (CommonSpecialPortalInUse)
elog(ERROR, "CommonSpecialPortal is in use");
/*
* Create a portal for safe memory across transactions. We need to
* palloc the name space for it because our hash function expects the
* name to be on a longword boundary. CreatePortal copies the name to
* safe storage for us.
*/
pname = pstrdup(VACPNAME);
vac_portal = CreatePortal(pname);
pfree(pname);
/*
* Set flag to indicate that vac_portal must be removed after an error.
* This global variable is checked in the transaction manager on xact
* abort, and the routine CommonSpecialPortalClose() is called if
* necessary.
*/
CommonSpecialPortalInUse = true;
}
void
CommonSpecialPortalClose(void)
{
/* Clear flag first, to avoid recursion if PortalDrop elog's */
CommonSpecialPortalInUse = false;
/*
* Release our portal for cross-transaction memory.
*/
PortalDrop(&vac_portal);
}
PortalVariableMemory
CommonSpecialPortalGetMemory(void)
{
return PortalGetVariableMemory(vac_portal);
}
bool
CommonSpecialPortalIsOpen(void)
{
return CommonSpecialPortalInUse;
}
static void
get_indices(Relation relation, int *nindices, Relation **Irel)
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.34 2000/05/28 17:55:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.35 2000/06/28 03:31:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -87,8 +87,8 @@ init_execution_state(FunctionCachePtr fcache)
nextes = newes;
preves = (execution_state *) NULL;
queryTree_list = pg_parse_and_rewrite(fcache->src, fcache->argOidVect,
nargs, FALSE);
queryTree_list = pg_parse_and_rewrite(fcache->src,
fcache->argOidVect, nargs);
foreach(qtl_item, queryTree_list)
{
......
......@@ -32,7 +32,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.67 2000/06/15 03:32:09 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.68 2000/06/28 03:31:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -265,7 +265,7 @@ advance_transition_functions(AggStatePerAgg peraggstate,
else
newVal = FunctionCallInvoke(&fcinfo);
if (!peraggstate->transtype1ByVal && !peraggstate->value1IsNull)
pfree(peraggstate->value1);
pfree(DatumGetPointer(peraggstate->value1));
peraggstate->value1 = newVal;
peraggstate->value1IsNull = fcinfo.isnull;
}
......@@ -288,7 +288,7 @@ advance_transition_functions(AggStatePerAgg peraggstate,
else
newVal = FunctionCallInvoke(&fcinfo);
if (!peraggstate->transtype2ByVal && !peraggstate->value2IsNull)
pfree(peraggstate->value2);
pfree(DatumGetPointer(peraggstate->value2));
peraggstate->value2 = newVal;
peraggstate->value2IsNull = fcinfo.isnull;
}
......@@ -424,12 +424,12 @@ finalize_aggregate(AggStatePerAgg peraggstate,
if (OidIsValid(peraggstate->xfn1_oid) &&
!peraggstate->value1IsNull &&
!peraggstate->transtype1ByVal)
pfree(peraggstate->value1);
pfree(DatumGetPointer(peraggstate->value1));
if (OidIsValid(peraggstate->xfn2_oid) &&
!peraggstate->value2IsNull &&
!peraggstate->transtype2ByVal)
pfree(peraggstate->value2);
pfree(DatumGetPointer(peraggstate->value2));
}
/* ---------------------------------------
......
......@@ -7,14 +7,14 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: nodeHash.c,v 1.47 2000/06/15 04:09:52 momjian Exp $
* $Id: nodeHash.c,v 1.48 2000/06/28 03:31:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* INTERFACE ROUTINES
* ExecHash - generate an in-memory hash table of the relation
* ExecInitHash - initialize node and subnodes..
* ExecInitHash - initialize node and subnodes
* ExecEndHash - shutdown node and subnodes
*
*/
......@@ -23,11 +23,12 @@
#include <math.h>
#include "postgres.h"
#include "executor/execdebug.h"
#include "executor/nodeHash.h"
#include "executor/nodeHashjoin.h"
#include "miscadmin.h"
#include "utils/portal.h"
static int hashFunc(Datum key, int len, bool byVal);
......@@ -235,8 +236,6 @@ ExecHashTableCreate(Hash *node)
int totalbuckets;
int bucketsize;
int i;
Portal myPortal;
char myPortalName[64];
MemoryContext oldcxt;
/* ----------------
......@@ -348,23 +347,21 @@ ExecHashTableCreate(Hash *node)
hashtable->outerBatchSize = NULL;
/* ----------------
* Create a named portal in which to keep the hashtable working storage.
* Each hashjoin must have its own portal, so be wary of name conflicts.
* Create temporary memory contexts in which to keep the hashtable
* working storage. See notes in executor/hashjoin.h.
* ----------------
*/
i = 0;
do
{
i++;
sprintf(myPortalName, "<hashtable %d>", i);
myPortal = GetPortalByName(myPortalName);
} while (PortalIsValid(myPortal));
myPortal = CreatePortal(myPortalName);
Assert(PortalIsValid(myPortal));
hashtable->myPortal = (void *) myPortal; /* kluge for circular
* includes */
hashtable->hashCxt = (MemoryContext) PortalGetVariableMemory(myPortal);
hashtable->batchCxt = (MemoryContext) PortalGetHeapMemory(myPortal);
hashtable->hashCxt = AllocSetContextCreate(TransactionCommandContext,
"HashTableContext",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
hashtable->batchCxt = AllocSetContextCreate(hashtable->hashCxt,
"HashBatchContext",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
/* Allocate data that will live for the life of the hashjoin */
......@@ -395,11 +392,10 @@ ExecHashTableCreate(Hash *node)
}
/*
* Prepare portal for the first-scan space allocations; allocate the
* Prepare context for the first-scan space allocations; allocate the
* hashbucket array therein, and set each bucket "empty".
*/
MemoryContextSwitchTo(hashtable->batchCxt);
StartPortalAllocMode(DefaultAllocMode, 0);
hashtable->buckets = (HashJoinTuple *)
palloc(nbuckets * sizeof(HashJoinTuple));
......@@ -435,9 +431,8 @@ ExecHashTableDestroy(HashJoinTable hashtable)
BufFileClose(hashtable->outerBatchFile[i]);
}
/* Destroy the portal to release all working memory */
/* cast here is a kluge for circular includes... */
PortalDrop((Portal *) &hashtable->myPortal);
/* Release working memory (batchCxt is a child, so it goes away too) */
MemoryContextDelete(hashtable->hashCxt);
/* And drop the control block */
pfree(hashtable);
......@@ -676,11 +671,10 @@ ExecHashTableReset(HashJoinTable hashtable, long ntuples)
/*
* Release all the hash buckets and tuples acquired in the prior pass,
* and reinitialize the portal for a new pass.
* and reinitialize the context for a new pass.
*/
MemoryContextReset(hashtable->batchCxt);
oldcxt = MemoryContextSwitchTo(hashtable->batchCxt);
EndPortalAllocMode();
StartPortalAllocMode(DefaultAllocMode, 0);
/*
* We still use the same number of physical buckets as in the first
......
......@@ -3,21 +3,20 @@
* spi.c
* Server Programming Interface
*
* $Id: spi.c,v 1.46 2000/05/30 04:24:45 tgl Exp $
* $Id: spi.c,v 1.47 2000/06/28 03:31:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "executor/spi_priv.h"
#include "access/printtup.h"
static Portal _SPI_portal = (Portal) NULL;
static _SPI_connection *_SPI_stack = NULL;
static _SPI_connection *_SPI_current = NULL;
static int _SPI_connected = -1;
static int _SPI_curid = -1;
DLLIMPORT uint32 SPI_processed = 0;
DLLIMPORT SPITupleTable *SPI_tuptable;
DLLIMPORT SPITupleTable *SPI_tuptable = NULL;
DLLIMPORT int SPI_result;
static int _SPI_execute(char *src, int tcount, _SPI_plan *plan);
......@@ -46,28 +45,6 @@ extern void ShowUsage(void);
int
SPI_connect()
{
char pname[64];
PortalVariableMemory pvmem;
/*
* It's possible on startup and after commit/abort. In future we'll
* catch commit/abort in some way...
*/
strcpy(pname, "<SPI manager>");
_SPI_portal = GetPortalByName(pname);
if (!PortalIsValid(_SPI_portal))
{
if (_SPI_stack != NULL) /* there was abort */
free(_SPI_stack);
_SPI_current = _SPI_stack = NULL;
_SPI_connected = _SPI_curid = -1;
SPI_processed = 0;
SPI_tuptable = NULL;
_SPI_portal = CreatePortal(pname);
if (!PortalIsValid(_SPI_portal))
elog(FATAL, "SPI_connect: global initialization failed");
}
/*
* When procedure called by Executor _SPI_curid expected to be equal
* to _SPI_connected
......@@ -99,15 +76,19 @@ SPI_connect()
_SPI_current->processed = 0;
_SPI_current->tuptable = NULL;
/* Create Portal for this procedure ... */
snprintf(pname, 64, "<SPI %d>", _SPI_connected);
_SPI_current->portal = CreatePortal(pname);
if (!PortalIsValid(_SPI_current->portal))
elog(FATAL, "SPI_connect: initialization failed");
/* ... and switch to Portal' Variable memory - procedure' context */
pvmem = PortalGetVariableMemory(_SPI_current->portal);
_SPI_current->savedcxt = MemoryContextSwitchTo((MemoryContext) pvmem);
/* Create memory contexts for this procedure */
_SPI_current->procCxt = AllocSetContextCreate(TopTransactionContext,
"SPI Proc",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
_SPI_current->execCxt = AllocSetContextCreate(TopTransactionContext,
"SPI Exec",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
/* ... and switch to procedure's context */
_SPI_current->savedcxt = MemoryContextSwitchTo(_SPI_current->procCxt);
_SPI_current->savedId = GetScanCommandId();
SetScanCommandId(GetCurrentCommandId());
......@@ -127,7 +108,10 @@ SPI_finish()
/* Restore memory context as it was before procedure call */
MemoryContextSwitchTo(_SPI_current->savedcxt);
PortalDrop(&(_SPI_current->portal));
/* Release memory used in procedure call */
MemoryContextDelete(_SPI_current->execCxt);
MemoryContextDelete(_SPI_current->procCxt);
SetScanCommandId(_SPI_current->savedId);
......@@ -142,6 +126,7 @@ SPI_finish()
{
free(_SPI_stack);
_SPI_stack = NULL;
_SPI_current = NULL;
}
else
{
......@@ -154,6 +139,25 @@ SPI_finish()
}
/*
* Clean up SPI state at transaction commit or abort (we don't care which).
*/
void
AtEOXact_SPI(void)
{
/*
* Note that memory contexts belonging to SPI stack entries will be
* freed automatically, so we can ignore them here. We just need to
* restore our static variables to initial state.
*/
if (_SPI_stack != NULL) /* there was abort */
free(_SPI_stack);
_SPI_current = _SPI_stack = NULL;
_SPI_connected = _SPI_curid = -1;
SPI_processed = 0;
SPI_tuptable = NULL;
}
void
SPI_push(void)
{
......@@ -508,61 +512,22 @@ SPI_palloc(Size size)
void *
SPI_repalloc(void *pointer, Size size)
{
MemoryContext oldcxt = NULL;
if (_SPI_curid + 1 == _SPI_connected) /* connected */
{
if (_SPI_current != &(_SPI_stack[_SPI_curid + 1]))
elog(FATAL, "SPI: stack corrupted");
oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt);
}
pointer = repalloc(pointer, size);
if (oldcxt)
MemoryContextSwitchTo(oldcxt);
return pointer;
/* No longer need to worry which context chunk was in... */
return repalloc(pointer, size);
}
void
SPI_pfree(void *pointer)
{
MemoryContext oldcxt = NULL;
if (_SPI_curid + 1 == _SPI_connected) /* connected */
{
if (_SPI_current != &(_SPI_stack[_SPI_curid + 1]))
elog(FATAL, "SPI: stack corrupted");
oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt);
}
/* No longer need to worry which context chunk was in... */
pfree(pointer);
if (oldcxt)
MemoryContextSwitchTo(oldcxt);
return;
}
void
SPI_freetuple(HeapTuple tuple)
{
MemoryContext oldcxt = NULL;
if (_SPI_curid + 1 == _SPI_connected) /* connected */
{
if (_SPI_current != &(_SPI_stack[_SPI_curid + 1]))
elog(FATAL, "SPI: stack corrupted");
oldcxt = MemoryContextSwitchTo(_SPI_current->savedcxt);
}
/* No longer need to worry which context tuple was in... */
heap_freetuple(tuple);
if (oldcxt)
MemoryContextSwitchTo(oldcxt);
return;
}
/* =================== private functions =================== */
......@@ -647,7 +612,7 @@ _SPI_execute(char *src, int tcount, _SPI_plan *plan)
argtypes = plan->argtypes;
}
queryTree_list = pg_parse_and_rewrite(src, argtypes, nargs, FALSE);
queryTree_list = pg_parse_and_rewrite(src, argtypes, nargs);
_SPI_current->qtlist = queryTree_list;
......@@ -790,7 +755,6 @@ static int
_SPI_pquery(QueryDesc *queryDesc, EState *state, int tcount)
{
Query *parseTree = queryDesc->parsetree;
Plan *plan = queryDesc->plantree;
int operation = queryDesc->operation;
CommandDest dest = queryDesc->dest;
TupleDesc tupdesc;
......@@ -875,16 +839,13 @@ _SPI_pquery(QueryDesc *queryDesc, EState *state, int tcount)
#endif
tupdesc = ExecutorStart(queryDesc, state);
/* Don't work currently */
/* Don't work currently --- need to rearrange callers so that
* we prepare the portal before doing CreateExecutorState() etc.
* See pquery.c for the correct order of operations.
*/
if (isRetrieveIntoPortal)
{
ProcessPortal(intoName,
parseTree,
plan,
state,
tupdesc,
None);
return SPI_OK_CURSOR;
elog(FATAL, "SPI_select: retrieve into portal not implemented");
}
ExecutorRun(queryDesc, state, EXEC_FOR, parseTree->limitOffset, count);
......@@ -920,27 +881,13 @@ _SPI_pquery(QueryDesc *queryDesc, EState *state, int tcount)
static MemoryContext
_SPI_execmem()
{
MemoryContext oldcxt;
PortalHeapMemory phmem;
phmem = PortalGetHeapMemory(_SPI_current->portal);
oldcxt = MemoryContextSwitchTo((MemoryContext) phmem);
return oldcxt;
return MemoryContextSwitchTo(_SPI_current->execCxt);
}
static MemoryContext
_SPI_procmem()
{
MemoryContext oldcxt;
PortalVariableMemory pvmem;
pvmem = PortalGetVariableMemory(_SPI_current->portal);
oldcxt = MemoryContextSwitchTo((MemoryContext) pvmem);
return oldcxt;
return MemoryContextSwitchTo(_SPI_current->procCxt);
}
/*
......@@ -959,7 +906,6 @@ _SPI_begin_call(bool execmem)
if (execmem) /* switch to the Executor memory context */
{
_SPI_execmem();
StartPortalAllocMode(DefaultAllocMode, 0);
}
return 0;
......@@ -977,9 +923,10 @@ _SPI_end_call(bool procmem)
_SPI_current->qtlist = NULL;
if (procmem) /* switch to the procedure memory context */
{ /* but free Executor memory before */
EndPortalAllocMode();
{
_SPI_procmem();
/* and free Executor memory */
MemoryContextResetAndDeleteChildren(_SPI_current->execCxt);
}
return 0;
......@@ -1016,8 +963,7 @@ _SPI_copy_plan(_SPI_plan *plan, int location)
MemoryContext oldcxt = NULL;
if (location == _SPI_CPLAN_PROCXT)
oldcxt = MemoryContextSwitchTo((MemoryContext)
PortalGetVariableMemory(_SPI_current->portal));
oldcxt = MemoryContextSwitchTo(_SPI_current->procCxt);
else if (location == _SPI_CPLAN_TOPCXT)
oldcxt = MemoryContextSwitchTo(TopMemoryContext);
......@@ -1033,7 +979,7 @@ _SPI_copy_plan(_SPI_plan *plan, int location)
else
newplan->argtypes = NULL;
if (location != _SPI_CPLAN_CURCXT)
if (oldcxt != NULL)
MemoryContextSwitchTo(oldcxt);
return newplan;
......
......@@ -4,14 +4,14 @@
# Makefile for lib (miscellaneous stuff)
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/lib/Makefile,v 1.13 2000/05/29 05:44:45 tgl Exp $
# $Header: /cvsroot/pgsql/src/backend/lib/Makefile,v 1.14 2000/06/28 03:31:34 tgl Exp $
#
#-------------------------------------------------------------------------
SRCDIR = ../..
include ../../Makefile.global
OBJS = bit.o fstack.o hasht.o lispsort.o stringinfo.o dllist.o
OBJS = bit.o hasht.o lispsort.o stringinfo.o dllist.o
all: SUBSYS.o
......
/*-------------------------------------------------------------------------
*
* fstack.c
* Fixed format stack definitions.
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/lib/Attic/fstack.c,v 1.14 2000/01/26 05:56:26 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "lib/fstack.h"
/*
* Internal function definitions
*/
/*
* FixedItemIsValid
* True iff item is valid.
*/
#define FixedItemIsValid(item) PointerIsValid(item)
/*
* FixedStackGetItemBase
* Returns base of enclosing structure.
*/
#define FixedStackGetItemBase(stack, item) \
((Pointer)((char *)(item) - (stack)->offset))
/*
* FixedStackGetItem
* Returns item of given pointer to enclosing structure.
*/
#define FixedStackGetItem(stack, pointer) \
((FixedItem)((char *)(pointer) + (stack)->offset))
#define FixedStackIsValid(stack) ((bool)PointerIsValid(stack))
/*
* External functions
*/
void
FixedStackInit(FixedStack stack, Offset offset)
{
AssertArg(PointerIsValid(stack));
stack->top = NULL;
stack->offset = offset;
}
Pointer
FixedStackPop(FixedStack stack)
{
Pointer pointer;
AssertArg(FixedStackIsValid(stack));
if (!PointerIsValid(stack->top))
return NULL;
pointer = FixedStackGetItemBase(stack, stack->top);
stack->top = stack->top->next;
return pointer;
}
void
FixedStackPush(FixedStack stack, Pointer pointer)
{
FixedItem item = FixedStackGetItem(stack, pointer);
AssertArg(FixedStackIsValid(stack));
AssertArg(PointerIsValid(pointer));
item->next = stack->top;
stack->top = item;
}
#ifdef USE_ASSERT_CHECKING
/*
* FixedStackContains
* True iff ordered stack contains given element.
*
* Note:
* This is inefficient. It is intended for debugging use only.
*
* Exceptions:
* BadArg if stack is invalid.
* BadArg if pointer is invalid.
*/
static bool
FixedStackContains(FixedStack stack, Pointer pointer)
{
FixedItem next;
FixedItem item;
AssertArg(FixedStackIsValid(stack));
AssertArg(PointerIsValid(pointer));
item = FixedStackGetItem(stack, pointer);
for (next = stack->top; FixedItemIsValid(next); next = next->next)
{
if (next == item)
return true;
}
return false;
}
#endif
Pointer
FixedStackGetTop(FixedStack stack)
{
AssertArg(FixedStackIsValid(stack));
if (!PointerIsValid(stack->top))
return NULL;
return FixedStackGetItemBase(stack, stack->top);
}
Pointer
FixedStackGetNext(FixedStack stack, Pointer pointer)
{
FixedItem item;
/* AssertArg(FixedStackIsValid(stack)); */
/* AssertArg(PointerIsValid(pointer)); */
AssertArg(FixedStackContains(stack, pointer));
item = FixedStackGetItem(stack, pointer)->next;
if (!PointerIsValid(item))
return NULL;
return FixedStackGetItemBase(stack, item);
}
......@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: stringinfo.c,v 1.25 2000/04/12 17:15:11 momjian Exp $
* $Id: stringinfo.c,v 1.26 2000/06/28 03:31:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -29,8 +29,6 @@ makeStringInfo(void)
StringInfo res;
res = (StringInfo) palloc(sizeof(StringInfoData));
if (res == NULL)
elog(ERROR, "makeStringInfo: Out of memory");
initStringInfo(res);
......@@ -49,9 +47,6 @@ initStringInfo(StringInfo str)
int size = 256; /* initial default buffer size */
str->data = (char *) palloc(size);
if (str->data == NULL)
elog(ERROR,
"initStringInfo: Out of memory (%d bytes requested)", size);
str->maxlen = size;
str->len = 0;
str->data[0] = '\0';
......@@ -62,6 +57,11 @@ initStringInfo(StringInfo str)
*
* Internal routine: make sure there is enough space for 'needed' more bytes
* ('needed' does not include the terminating null).
*
* NB: because we use repalloc() to enlarge the buffer, the string buffer
* will remain allocated in the same memory context that was current when
* initStringInfo was called, even if another context is now current.
* This is the desired and indeed critical behavior!
*/
static void
enlargeStringInfo(StringInfo str, int needed)
......@@ -83,9 +83,6 @@ enlargeStringInfo(StringInfo str, int needed)
newlen = 2 * newlen;
str->data = (char *) repalloc(str->data, newlen);
if (str->data == NULL)
elog(ERROR,
"enlargeStringInfo: Out of memory (%d bytes requested)", newlen);
str->maxlen = newlen;
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.46 2000/06/09 01:11:06 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.47 2000/06/28 03:31:41 tgl Exp $
*
* NOTES
* This should be moved to a more appropriate place. It is here
......@@ -16,7 +16,7 @@
*
* Builtin functions for open/close/read/write operations on large objects.
*
* These functions operate in a private GlobalMemoryContext, which means
* These functions operate in a private MemoryContext, which means
* that large object descriptors hang around until we destroy the context.
* That happens in lo_commit(). It'd be possible to prolong the lifetime
* of the context so that LO FDs are good across transactions (for example,
......@@ -24,8 +24,10 @@
* But we'd need additional state in order to do the right thing at the
* end of an aborted transaction. FDs opened during an aborted xact would
* still need to be closed, since they might not be pointing at valid
* relations at all. For now, we'll stick with the existing documented
* semantics of LO FDs: they're only good within a transaction.
* relations at all. Locking semantics are also an interesting problem
* if LOs stay open across transactions. For now, we'll stick with the
* existing documented semantics of LO FDs: they're only good within a
* transaction.
*
*-------------------------------------------------------------------------
*/
......@@ -56,7 +58,7 @@
*/
static LargeObjectDesc *cookies[MAX_LOBJ_FDS];
static GlobalMemory fscxt = NULL;
static MemoryContext fscxt = NULL;
static int newLOfd(LargeObjectDesc *lobjCookie);
......@@ -80,8 +82,13 @@ lo_open(PG_FUNCTION_ARGS)
#endif
if (fscxt == NULL)
fscxt = CreateGlobalMemory("Filesystem");
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
fscxt = AllocSetContextCreate(TopMemoryContext,
"Filesystem",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
currentContext = MemoryContextSwitchTo(fscxt);
lobjDesc = inv_open(lobjId, mode);
......@@ -128,7 +135,7 @@ lo_close(PG_FUNCTION_ARGS)
#endif
Assert(fscxt != NULL);
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
currentContext = MemoryContextSwitchTo(fscxt);
inv_close(cookies[fd]);
......@@ -166,7 +173,7 @@ lo_read(int fd, char *buf, int len)
}
Assert(fscxt != NULL);
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
currentContext = MemoryContextSwitchTo(fscxt);
status = inv_read(cookies[fd], buf, len);
......@@ -193,7 +200,7 @@ lo_write(int fd, char *buf, int len)
}
Assert(fscxt != NULL);
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
currentContext = MemoryContextSwitchTo(fscxt);
status = inv_write(cookies[fd], buf, len);
......@@ -224,7 +231,7 @@ lo_lseek(PG_FUNCTION_ARGS)
}
Assert(fscxt != NULL);
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
currentContext = MemoryContextSwitchTo(fscxt);
status = inv_seek(cookies[fd], offset, whence);
......@@ -242,9 +249,13 @@ lo_creat(PG_FUNCTION_ARGS)
Oid lobjId;
if (fscxt == NULL)
fscxt = CreateGlobalMemory("Filesystem");
fscxt = AllocSetContextCreate(TopMemoryContext,
"Filesystem",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
currentContext = MemoryContextSwitchTo(fscxt);
lobjDesc = inv_create(mode);
......@@ -493,7 +504,7 @@ lo_commit(bool isCommit)
if (fscxt == NULL)
return; /* no LO operations in this xact */
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
currentContext = MemoryContextSwitchTo(fscxt);
/*
* Clean out still-open index scans (not necessary if aborting) and
......@@ -512,7 +523,7 @@ lo_commit(bool isCommit)
MemoryContextSwitchTo(currentContext);
/* Release the LO memory context to prevent permanent memory leaks. */
GlobalMemoryDestroy(fscxt);
MemoryContextDelete(fscxt);
fscxt = NULL;
}
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.32 2000/05/28 17:55:56 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.33 2000/06/28 03:31:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -135,9 +135,11 @@ PQexec(char *query)
/* ----------------
* pg_exec_query_dest will put the query results in a portal which will
* end up on the top of the portal stack.
*
* XXX memory context manipulation needs thought here.
* ----------------
*/
pg_exec_query_dest(query, Local, FALSE);
pg_exec_query_dest(query, Local, CurrentMemoryContext);
/* ----------------
* pop the portal off the portal stack and return the
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.15 2000/06/11 11:39:50 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.16 2000/06/28 03:31:41 tgl Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
......@@ -44,6 +44,44 @@
#include "libpq/pqsignal.h"
/*
* Initialize BlockSig and UnBlockSig.
*
* BlockSig is the set of signals to block when we are trying to block
* signals. This includes all signals we normally expect to get, but NOT
* signals that should never be turned off.
*
* UnBlockSig is the set of signals to block when we don't want to block
* signals (is this ever nonzero??)
*/
void
pqinitmask(void)
{
#ifdef HAVE_SIGPROCMASK
sigemptyset(&UnBlockSig);
sigfillset(&BlockSig);
sigdelset(&BlockSig, SIGABRT);
sigdelset(&BlockSig, SIGILL);
sigdelset(&BlockSig, SIGSEGV);
sigdelset(&BlockSig, SIGBUS);
sigdelset(&BlockSig, SIGTRAP);
sigdelset(&BlockSig, SIGCONT);
sigdelset(&BlockSig, SIGSYS);
#else
UnBlockSig = 0;
BlockSig = sigmask(SIGHUP) | sigmask(SIGQUIT) |
sigmask(SIGTERM) | sigmask(SIGALRM) |
sigmask(SIGINT) | sigmask(SIGUSR1) |
sigmask(SIGUSR2) | sigmask(SIGCHLD) |
sigmask(SIGWINCH) | sigmask(SIGFPE);
#endif
}
/*
* Set up a signal handler
*/
pqsigfunc
pqsignal(int signo, pqsigfunc func)
{
......
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_eval.c,v 1.50 2000/05/30 00:49:46 momjian Exp $
* $Id: geqo_eval.c,v 1.51 2000/06/28 03:31:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -19,9 +19,9 @@
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
#include <math.h>
#include "postgres.h"
#include <math.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
......@@ -33,41 +33,8 @@
#include "optimizer/geqo.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "utils/portal.h"
/*
* Variables set by geqo_eval_startup for use within a single GEQO run
*/
static MemoryContext geqo_eval_context;
/*
* geqo_eval_startup:
* Must be called during geqo_main startup (before geqo_eval may be called)
*
* The main thing we need to do here is prepare a private memory context for
* allocation of temp storage used while constructing a path in geqo_eval().
* Since geqo_eval() will be called many times, we can't afford to let all
* that memory go unreclaimed until end of statement. We use a special
* named portal to hold the context, so that it will be freed even if
* we abort via elog(ERROR). The working data is allocated in the portal's
* heap memory context.
*/
void
geqo_eval_startup(void)
{
#define GEQO_PORTAL_NAME "<geqo workspace>"
Portal geqo_portal = GetPortalByName(GEQO_PORTAL_NAME);
if (!PortalIsValid(geqo_portal))
{
/* First time through (within current transaction, that is) */
geqo_portal = CreatePortal(GEQO_PORTAL_NAME);
Assert(PortalIsValid(geqo_portal));
}
#include "utils/memutils.h"
geqo_eval_context = (MemoryContext) PortalGetHeapMemory(geqo_portal);
}
/*
* geqo_eval
......@@ -77,20 +44,30 @@ geqo_eval_startup(void)
Cost
geqo_eval(Query *root, Gene *tour, int num_gene)
{
MemoryContext mycontext;
MemoryContext oldcxt;
RelOptInfo *joinrel;
Cost fitness;
List *savelist;
/* preserve root->join_rel_list, which gimme_tree changes */
savelist = root->join_rel_list;
/*
* create a temporary allocation context for the path construction
* work
* Create a private memory context that will hold all temp storage
* allocated inside gimme_tree().
*
* Since geqo_eval() will be called many times, we can't afford to let
* all that memory go unreclaimed until end of statement. Note we make
* the temp context a child of TransactionCommandContext, so that
* it will be freed even if we abort via elog(ERROR).
*/
oldcxt = MemoryContextSwitchTo(geqo_eval_context);
StartPortalAllocMode(DefaultAllocMode, 0);
mycontext = AllocSetContextCreate(TransactionCommandContext,
"GEQO",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
oldcxt = MemoryContextSwitchTo(mycontext);
/* preserve root->join_rel_list, which gimme_tree changes */
savelist = root->join_rel_list;
/* construct the best path for the given combination of relations */
joinrel = gimme_tree(root, tour, 0, num_gene, NULL);
......@@ -107,8 +84,8 @@ geqo_eval(Query *root, Gene *tour, int num_gene)
root->join_rel_list = savelist;
/* release all the memory acquired within gimme_tree */
EndPortalAllocMode();
MemoryContextSwitchTo(oldcxt);
MemoryContextDelete(mycontext);
return fitness;
}
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_main.c,v 1.21 2000/05/31 00:28:19 petere Exp $
* $Id: geqo_main.c,v 1.22 2000/06/28 03:31:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -110,9 +110,6 @@ geqo(Query *root)
else
srandom(time(NULL));
/* initialize plan evaluator */
geqo_eval_startup();
/* allocate genetic pool memory */
pool = alloc_pool(pool_size, number_of_rels);
......
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.149 2000/06/22 22:31:20 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.150 2000/06/28 03:31:52 tgl Exp $
*
* NOTES
*
......@@ -378,15 +378,38 @@ PostmasterMain(int argc, char *argv[])
*/
umask((mode_t) 0077);
ResetAllOptions();
MyProcPid = getpid();
/*
* Fire up essential subsystems: error and memory management
*/
EnableExceptionHandling(true);
MemoryContextInit();
/*
* By default, palloc() requests in the postmaster will be allocated
* in the PostmasterContext, which is space that can be recycled by
* backends. Allocated data that needs to be available to backends
* should be allocated in TopMemoryContext.
*/
PostmasterContext = AllocSetContextCreate(TopMemoryContext,
"Postmaster",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
MemoryContextSwitchTo(PostmasterContext);
/*
* Options setup
*/
if (getenv("PGDATA"))
DataDir = strdup(getenv("PGDATA")); /* default value */
if (getenv("PGPORT"))
PostPortName = atoi(getenv("PGPORT"));
ResetAllOptions();
/*
* First we must scan for a -D argument to get the data dir. Then
* read the config file. Finally, scan all the other arguments.
......@@ -600,7 +623,6 @@ PostmasterMain(int argc, char *argv[])
}
#endif
/* set up shared memory and semaphores */
EnableMemoryContext(TRUE);
reset_shared(PostPortName);
/*
......@@ -662,7 +684,7 @@ PostmasterMain(int argc, char *argv[])
/*
* Set up signal handlers for the postmaster process.
*/
PG_INITMASK();
pqinitmask();
PG_SETMASK(&BlockSig);
pqsignal(SIGHUP, SIGHUP_handler); /* reread config file and have children do same */
......@@ -1867,6 +1889,7 @@ DoBackend(Port *port)
/* Save port etc. for ps status */
MyProcPort = port;
/* Reset MyProcPid to new backend's pid */
MyProcPid = getpid();
/*
......@@ -1946,6 +1969,19 @@ DoBackend(Port *port)
av[ac] = (char *) NULL;
/*
* Release postmaster's working memory context so that backend can
* recycle the space. Note we couldn't do it earlier than here,
* because port pointer is pointing into that space! But now we
* have copied all the interesting info into safe local storage.
*/
MemoryContextSwitchTo(TopMemoryContext);
MemoryContextDelete(PostmasterContext);
PostmasterContext = NULL;
/*
* Debug: print arguments being passed to backend
*/
if (DebugLvl > 1)
{
fprintf(stderr, "%s child[%d]: starting with (",
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.46 2000/06/15 04:09:58 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.47 2000/06/28 03:31:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -16,51 +16,20 @@
#include "postgres.h"
#include "access/heapam.h"
#include "lib/stringinfo.h"
#include "utils/builtins.h"
#include "catalog/catname.h"
#include "catalog/indexing.h"
#include "catalog/pg_rewrite.h"
#include "parser/parse_relation.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteSupport.h"
#include "tcop/tcopprot.h"
Oid LastOidProcessed = InvalidOid;
/*
* Convert given string to a suitably quoted string constant,
* and append it to the StringInfo buffer.
* XXX Any MULTIBYTE considerations here?
*/
static void
quoteString(StringInfo buf, char *source)
{
char *current;
appendStringInfoChar(buf, '\'');
for (current = source; *current; current++)
{
char ch = *current;
if (ch == '\'' || ch == '\\')
{
appendStringInfoChar(buf, '\\');
appendStringInfoChar(buf, ch);
}
else if (ch >= 0 && ch < ' ')
appendStringInfo(buf, "\\%03o", (int) ch);
else
appendStringInfoChar(buf, ch);
}
appendStringInfoChar(buf, '\'');
}
/*
* InsertRule -
* takes the arguments and inserts them as attributes into the system
* relation "pg_rewrite"
*
* MODS : changes the value of LastOidProcessed as a side
* effect of inserting the rule tuple
*
* ARGS : rulname - name of the rule
* evtype - one of RETRIEVE,REPLACE,DELETE,APPEND
* evobj - name of relation
......@@ -78,11 +47,17 @@ InsertRule(char *rulname,
bool evinstead,
char *actiontree)
{
StringInfoData rulebuf;
Relation eventrel;
Oid eventrel_oid;
AttrNumber evslot_index;
char *is_instead = "f";
int i;
Datum values[Natts_pg_rewrite];
char nulls[Natts_pg_rewrite];
NameData rname;
Relation pg_rewrite_desc;
TupleDesc tupDesc;
HeapTuple tup;
Oid rewriteObjectId;
eventrel = heap_openr(evobj, AccessShareLock);
eventrel_oid = RelationGetRelid(eventrel);
......@@ -96,9 +71,6 @@ InsertRule(char *rulname,
evslot_index = attnameAttNum(eventrel, evslot);
heap_close(eventrel, AccessShareLock);
if (evinstead)
is_instead = "t";
if (evqual == NULL)
evqual = "<>";
......@@ -106,23 +78,54 @@ InsertRule(char *rulname,
elog(ERROR, "Attempt to insert rule '%s' failed: already exists",
rulname);
initStringInfo(&rulebuf);
appendStringInfo(&rulebuf,
"INSERT INTO pg_rewrite (rulename, ev_type, ev_class, ev_attr, ev_action, ev_qual, is_instead) VALUES (");
quoteString(&rulebuf, rulname);
appendStringInfo(&rulebuf, ", %d::char, %u::oid, %d::int2, ",
evtype, eventrel_oid, evslot_index);
quoteString(&rulebuf, actiontree);
appendStringInfo(&rulebuf, "::text, ");
quoteString(&rulebuf, evqual);
appendStringInfo(&rulebuf, "::text, '%s'::bool);",
is_instead);
/* ----------------
* Set up *nulls and *values arrays
* ----------------
*/
MemSet(nulls, ' ', sizeof(nulls));
i = 0;
namestrcpy(&rname, rulname);
values[i++] = NameGetDatum(&rname);
values[i++] = CharGetDatum(evtype + '0');
values[i++] = ObjectIdGetDatum(eventrel_oid);
values[i++] = Int16GetDatum(evslot_index);
values[i++] = BoolGetDatum(evinstead);
values[i++] = PointerGetDatum(lztextin(evqual));
values[i++] = PointerGetDatum(lztextin(actiontree));
/* ----------------
* create a new pg_rewrite tuple
* ----------------
*/
pg_rewrite_desc = heap_openr(RewriteRelationName, RowExclusiveLock);
tupDesc = pg_rewrite_desc->rd_att;
tup = heap_formtuple(tupDesc,
values,
nulls);
heap_insert(pg_rewrite_desc, tup);
rewriteObjectId = tup->t_data->t_oid;
if (RelationGetForm(pg_rewrite_desc)->relhasindex)
{
Relation idescs[Num_pg_rewrite_indices];
CatalogOpenIndices(Num_pg_rewrite_indices, Name_pg_rewrite_indices,
idescs);
CatalogIndexInsert(idescs, Num_pg_rewrite_indices, pg_rewrite_desc,
tup);
CatalogCloseIndices(Num_pg_rewrite_indices, idescs);
}
pg_exec_query_dest(rulebuf.data, None, true);
heap_freetuple(tup);
pfree(rulebuf.data);
heap_close(pg_rewrite_desc, RowExclusiveLock);
return LastOidProcessed;
return rewriteObjectId;
}
/*
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.41 2000/01/26 05:56:50 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.42 2000/06/28 03:31:56 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -136,7 +136,7 @@ prs2_addToRelation(Oid relid,
* create an in memory RewriteRule data structure which is cached by
* every Relation descriptor. (see utils/cache/relcache.c)
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
thisRule = (RewriteRule *) palloc(sizeof(RewriteRule));
if (qual != NULL)
qual = copyObject(qual);
......@@ -159,7 +159,7 @@ prs2_addToRelation(Oid relid,
if (relation->rd_rules == NULL)
{
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
rulelock = (RuleLock *) palloc(sizeof(RuleLock));
rulelock->numLocks = 1;
rulelock->rules = (RewriteRule **) palloc(sizeof(RewriteRule *));
......@@ -181,7 +181,7 @@ prs2_addToRelation(Oid relid,
rulelock = relation->rd_rules;
numlock = rulelock->numLocks;
/* expand, for safety reasons */
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
rulelock->rules = (RewriteRule **) repalloc(rulelock->rules,
sizeof(RewriteRule *) * (numlock + 1));
MemoryContextSwitchTo(oldcxt);
......@@ -212,7 +212,7 @@ prs2_deleteFromRelation(Oid relid, Oid ruleId)
break;
}
Assert(i < numlock);
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
pfree(rulelock->rules[i]);
MemoryContextSwitchTo(oldcxt);
if (numlock == 1)
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.51 2000/05/30 00:49:52 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.52 2000/06/28 03:31:57 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -262,29 +262,23 @@ InitShmem(unsigned int key, unsigned int size)
}
/*
* ShmemAlloc -- allocate word-aligned byte string from
* shared memory
* ShmemAlloc -- allocate max-aligned byte string from shared memory
*
* Assumes ShmemLock and ShmemFreeStart are initialized.
* Returns: real pointer to memory or NULL if we are out
* of space. Has to return a real pointer in order
* to be compatable with malloc().
* to be compatible with malloc().
*/
long *
ShmemAlloc(unsigned long size)
void *
ShmemAlloc(Size size)
{
unsigned long tmpFree;
long *newSpace;
void *newSpace;
/*
* ensure space is word aligned.
*
* Word-alignment is not good enough. We have to be more conservative:
* doubles need 8-byte alignment. (We probably only need this on RISC
* platforms but this is not a big waste of space.) - ay 12/94
* ensure all space is adequately aligned.
*/
if (size % sizeof(double))
size += sizeof(double) - (size % sizeof(double));
size = MAXALIGN(size);
Assert(*ShmemFreeStart);
......@@ -293,7 +287,7 @@ ShmemAlloc(unsigned long size)
tmpFree = *ShmemFreeStart + size;
if (tmpFree <= ShmemSize)
{
newSpace = (long *) MAKE_PTR(*ShmemFreeStart);
newSpace = (void *) MAKE_PTR(*ShmemFreeStart);
*ShmemFreeStart += size;
}
else
......@@ -302,7 +296,8 @@ ShmemAlloc(unsigned long size)
SpinRelease(ShmemLock);
if (!newSpace)
elog(NOTICE, "ShmemAlloc: out of memory ");
elog(NOTICE, "ShmemAlloc: out of memory");
return newSpace;
}
......@@ -336,7 +331,7 @@ ShmemInitHash(char *name, /* table string name for shmem index */
int hash_flags) /* info about infoP */
{
bool found;
long *location;
void *location;
/*
* Hash tables allocated in shared memory have a fixed directory; it
......@@ -478,12 +473,12 @@ ShmemPIDDestroy(int pid)
* the object is already in the shmem index (hence, already
* initialized).
*/
long *
ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
void *
ShmemInitStruct(char *name, Size size, bool *foundPtr)
{
ShmemIndexEnt *result,
item;
long *structPtr;
void *structPtr;
strncpy(item.key, name, SHMEM_INDEX_KEYSIZE);
item.location = BAD_LOCATION;
......@@ -498,27 +493,27 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
#endif
/*
* If the shmem index doesnt exist, we fake it.
* If the shmem index doesn't exist, we fake it.
*
* If we are creating the first shmem index, then let shmemalloc()
* allocate the space for a new HTAB. Otherwise, find the old one
* and return that. Notice that the ShmemIndexLock is held until
* the shmem index has been completely initialized.
*/
Assert(!strcmp(name, strname));
Assert(strcmp(name, strname) == 0);
if (ShmemBootstrap)
{
/* in POSTMASTER/Single process */
*foundPtr = FALSE;
return (long *) ShmemAlloc(size);
return ShmemAlloc(size);
}
else
{
Assert(ShmemIndexOffset);
*foundPtr = TRUE;
return (long *) MAKE_PTR(*ShmemIndexOffset);
return (void *) MAKE_PTR(*ShmemIndexOffset);
}
......@@ -554,12 +549,12 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
/* let caller print its message too */
return NULL;
}
structPtr = (long *) MAKE_PTR(result->location);
structPtr = (void *) MAKE_PTR(result->location);
}
else
{
/* It isn't in the table yet. allocate and initialize it */
structPtr = ShmemAlloc((long) size);
structPtr = ShmemAlloc(size);
if (!structPtr)
{
/* out of memory */
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.71 2000/06/17 23:41:39 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.72 2000/06/28 03:32:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1090,7 +1090,7 @@ inv_newtuple(LargeObjectDesc *obj_desc,
ntup->t_len = tupsize;
ItemPointerSet(&ntup->t_self, BufferGetBlockNumber(buffer), off);
LastOidProcessed = ntup->t_data->t_oid = newoid();
ntup->t_data->t_oid = newoid();
TransactionIdStore(GetCurrentTransactionId(), &(ntup->t_data->t_xmin));
ntup->t_data->t_cmin = GetCurrentCommandId();
StoreInvalidTransactionId(&(ntup->t_data->t_xmax));
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.69 2000/06/04 01:44:32 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.70 2000/06/28 03:32:07 tgl Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
......@@ -225,6 +225,11 @@ LockMethodInit(LOCKMETHODTABLE *lockMethodTable,
* has its name stored in the shmem index at its creation. It
* is wasteful, in this case, but not much space is involved.
*
* NOTE: data structures allocated here are allocated permanently, using
* TopMemoryContext and shared memory. We don't ever release them anyway,
* and in normal multi-backend operation the lock table structures set up
* by the postmaster are inherited by each backend, so they must be in
* TopMemoryContext.
*/
LOCKMETHOD
LockMethodTableInit(char *tabName,
......@@ -246,22 +251,13 @@ LockMethodTableInit(char *tabName,
return INVALID_LOCKMETHOD;
}
/* allocate a string for the shmem index table lookup */
shmemName = (char *) palloc((unsigned) (strlen(tabName) + 32));
if (!shmemName)
{
elog(NOTICE, "LockMethodTableInit: couldn't malloc string %s \n", tabName);
return INVALID_LOCKMETHOD;
}
/* Allocate a string for the shmem index table lookups. */
/* This is just temp space in this routine, so palloc is OK. */
shmemName = (char *) palloc(strlen(tabName) + 32);
/* each lock table has a non-shared header */
lockMethodTable = (LOCKMETHODTABLE *) palloc((unsigned) sizeof(LOCKMETHODTABLE));
if (!lockMethodTable)
{
elog(NOTICE, "LockMethodTableInit: couldn't malloc lock table %s\n", tabName);
pfree(shmemName);
return INVALID_LOCKMETHOD;
}
/* each lock table has a non-shared, permanent header */
lockMethodTable = (LOCKMETHODTABLE *)
MemoryContextAlloc(TopMemoryContext, sizeof(LOCKMETHODTABLE));
/* ------------------------
* find/acquire the spinlock for the table
......@@ -269,7 +265,6 @@ LockMethodTableInit(char *tabName,
*/
SpinAcquire(LockMgrLock);
/* -----------------------
* allocate a control structure from shared memory or attach to it
* if it already exists.
......@@ -277,7 +272,7 @@ LockMethodTableInit(char *tabName,
*/
sprintf(shmemName, "%s (ctl)", tabName);
lockMethodTable->ctl = (LOCKMETHODCTL *)
ShmemInitStruct(shmemName, (unsigned) sizeof(LOCKMETHODCTL), &found);
ShmemInitStruct(shmemName, sizeof(LOCKMETHODCTL), &found);
if (!lockMethodTable->ctl)
{
......@@ -910,7 +905,7 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCK *lock, LOCKMODE lockmode)
LOCK_PRINT("WaitOnLock: sleeping on lock", lock, lockmode);
old_status = pstrdup(get_ps_display());
new_status = palloc(strlen(get_ps_display()) + 10);
new_status = (char *) palloc(strlen(get_ps_display()) + 10);
strcpy(new_status, get_ps_display());
strcat(new_status, " waiting");
set_ps_display(new_status);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.75 2000/06/15 04:10:07 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.76 2000/06/28 03:32:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -47,7 +47,7 @@
* This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95
*
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.75 2000/06/15 04:10:07 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.76 2000/06/28 03:32:07 tgl Exp $
*/
#include <sys/time.h>
#include <unistd.h>
......@@ -119,7 +119,7 @@ InitProcGlobal(IPCKey key, int maxBackends)
/* attach to the free list */
ProcGlobal = (PROC_HDR *)
ShmemInitStruct("Proc Header", (unsigned) sizeof(PROC_HDR), &found);
ShmemInitStruct("Proc Header", sizeof(PROC_HDR), &found);
/* --------------------
* We're the first - initialize.
......@@ -185,7 +185,7 @@ InitProcess(IPCKey key)
/* attach to the free list */
ProcGlobal = (PROC_HDR *)
ShmemInitStruct("Proc Header", (unsigned) sizeof(PROC_HDR), &found);
ShmemInitStruct("Proc Header", sizeof(PROC_HDR), &found);
if (!found)
{
/* this should not happen. InitProcGlobal() is called before this. */
......@@ -218,7 +218,7 @@ InitProcess(IPCKey key)
* cleanup dead processes).
*/
MyProc = (PROC *) ShmemAlloc((unsigned) sizeof(PROC));
MyProc = (PROC *) ShmemAlloc(sizeof(PROC));
if (!MyProc)
{
SpinRelease(ProcStructLock);
......@@ -458,7 +458,7 @@ ProcQueueAlloc(char *name)
{
bool found;
PROC_QUEUE *queue = (PROC_QUEUE *)
ShmemInitStruct(name, (unsigned) sizeof(PROC_QUEUE), &found);
ShmemInitStruct(name, sizeof(PROC_QUEUE), &found);
if (!queue)
return NULL;
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.71 2000/06/19 23:37:08 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.72 2000/06/28 03:32:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -94,19 +94,15 @@ static BlockNumber _mdnblocks(File file, Size blcksz);
int
mdinit()
{
MemoryContext oldcxt;
int i;
MdCxt = (MemoryContext) CreateGlobalMemory("MdSmgr");
if (MdCxt == (MemoryContext) NULL)
return SM_FAIL;
oldcxt = MemoryContextSwitchTo(MdCxt);
Md_fdvec = (MdfdVec *) palloc(Nfds * sizeof(MdfdVec));
MemoryContextSwitchTo(oldcxt);
MdCxt = AllocSetContextCreate(TopMemoryContext,
"MdSmgr",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
if (Md_fdvec == (MdfdVec *) NULL)
return SM_FAIL;
Md_fdvec = (MdfdVec *) MemoryContextAlloc(MdCxt, Nfds * sizeof(MdfdVec));
MemSet(Md_fdvec, 0, Nfds * sizeof(MdfdVec));
......@@ -208,7 +204,6 @@ mdunlink(Relation reln)
int nblocks;
int fd;
MdfdVec *v;
MemoryContext oldcxt;
/*
* If the relation is already unlinked,we have nothing to do any more.
......@@ -238,7 +233,6 @@ mdunlink(Relation reln)
Md_fdvec[fd].mdfd_flags = (uint16) 0;
oldcxt = MemoryContextSwitchTo(MdCxt);
#ifndef LET_OS_MANAGE_FILESIZE
for (v = &Md_fdvec[fd]; v != (MdfdVec *) NULL;)
{
......@@ -256,7 +250,6 @@ mdunlink(Relation reln)
FileTruncate(v->mdfd_vfd, 0);
FileUnlink(v->mdfd_vfd);
#endif
MemoryContextSwitchTo(oldcxt);
_fdvec_free(fd);
......@@ -400,9 +393,7 @@ static void
mdclose_fd(int fd)
{
MdfdVec *v;
MemoryContext oldcxt;
oldcxt = MemoryContextSwitchTo(MdCxt);
#ifndef LET_OS_MANAGE_FILESIZE
for (v = &Md_fdvec[fd]; v != (MdfdVec *) NULL;)
{
......@@ -446,7 +437,6 @@ mdclose_fd(int fd)
}
}
#endif
MemoryContextSwitchTo(oldcxt);
_fdvec_free(fd);
}
......@@ -751,11 +741,8 @@ mdtruncate(Relation reln, int nblocks)
int curnblk;
int fd;
MdfdVec *v;
#ifndef LET_OS_MANAGE_FILESIZE
MemoryContext oldcxt;
int priorblocks;
#endif
/*
......@@ -772,7 +759,6 @@ mdtruncate(Relation reln, int nblocks)
v = &Md_fdvec[fd];
#ifndef LET_OS_MANAGE_FILESIZE
oldcxt = MemoryContextSwitchTo(MdCxt);
priorblocks = 0;
while (v != (MdfdVec *) NULL)
{
......@@ -825,7 +811,6 @@ mdtruncate(Relation reln, int nblocks)
}
priorblocks += RELSEG_SIZE;
}
MemoryContextSwitchTo(oldcxt);
#else
if (FileTruncate(v->mdfd_vfd, nblocks * BLCKSZ) < 0)
return -1;
......@@ -833,8 +818,7 @@ mdtruncate(Relation reln, int nblocks)
#endif
return nblocks;
} /* mdtruncate */
}
/*
* mdcommit() -- Commit a transaction.
......@@ -907,7 +891,6 @@ _fdvec_alloc()
MdfdVec *nvec;
int fdvec,
i;
MemoryContext oldcxt;
if (Md_Free >= 0) /* get from free list */
{
......@@ -930,15 +913,11 @@ _fdvec_alloc()
Nfds *= 2;
oldcxt = MemoryContextSwitchTo(MdCxt);
nvec = (MdfdVec *) palloc(Nfds * sizeof(MdfdVec));
nvec = (MdfdVec *) MemoryContextAlloc(MdCxt, Nfds * sizeof(MdfdVec));
MemSet(nvec, 0, Nfds * sizeof(MdfdVec));
memmove(nvec, (char *) Md_fdvec, CurFd * sizeof(MdfdVec));
memcpy(nvec, (char *) Md_fdvec, CurFd * sizeof(MdfdVec));
pfree(Md_fdvec);
MemoryContextSwitchTo(oldcxt);
Md_fdvec = nvec;
/* Set new free list */
......@@ -976,7 +955,6 @@ _fdvec_free(int fdvec)
static MdfdVec *
_mdfd_openseg(Relation reln, int segno, int oflags)
{
MemoryContext oldcxt;
MdfdVec *v;
int fd;
char *path,
......@@ -1003,9 +981,7 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
return (MdfdVec *) NULL;
/* allocate an mdfdvec entry for it */
oldcxt = MemoryContextSwitchTo(MdCxt);
v = (MdfdVec *) palloc(sizeof(MdfdVec));
MemoryContextSwitchTo(oldcxt);
v = (MdfdVec *) MemoryContextAlloc(MdCxt, sizeof(MdfdVec));
/* fill the entry */
v->mdfd_vfd = fd;
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.34 2000/06/12 03:40:40 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.35 2000/06/28 03:32:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -22,8 +22,6 @@
#include "utils/ps_status.h"
static char *CreateOperationTag(int operationType);
static void ProcessQueryDesc(QueryDesc *queryDesc, Node *limoffset,
Node *limcount);
/* ----------------------------------------------------------------
......@@ -115,7 +113,7 @@ CreateOperationTag(int operationType)
default:
elog(DEBUG, "CreateOperationTag: unknown operation type %d",
operationType);
tag = NULL;
tag = "???";
break;
}
......@@ -123,31 +121,18 @@ CreateOperationTag(int operationType)
}
/* ----------------
* ProcessPortal
* PreparePortal
* ----------------
*/
void
ProcessPortal(char *portalName,
Query *parseTree,
Plan *plan,
EState *state,
TupleDesc attinfo,
CommandDest dest)
Portal
PreparePortal(char *portalName)
{
Portal portal;
MemoryContext portalContext;
/* ----------------
* Check for reserved or already-in-use portal name.
* Check for already-in-use portal name.
* ----------------
*/
if (PortalNameIsSpecial(portalName))
elog(ERROR,
"The portal name \"%s\" is reserved for internal use",
portalName);
portal = GetPortalByName(portalName);
if (PortalIsValid(portal))
{
......@@ -158,70 +143,39 @@ ProcessPortal(char *portalName,
}
/* ----------------
* Convert the current blank portal into the user-specified
* portal and initialize the state and query descriptor.
*
* Since the parsetree has been created in the current blank portal,
* we don't have to do any work to copy it into the user-named portal.
* Create the new portal and make its memory context active.
* ----------------
*/
portal = CreatePortal(portalName);
portal = BlankPortalAssignName(portalName);
PortalSetQuery(portal,
CreateQueryDesc(parseTree, plan, dest),
attinfo,
state,
PortalCleanup);
MemoryContextSwitchTo(PortalGetHeapMemory(portal));
/* ----------------
* Now create a new blank portal and switch to it.
* Otherwise, the new named portal will be cleaned at statement end.
*
* Note: portals will only be supported within a BEGIN...END
* block in the near future. Later, someone will fix it to
* do what is possible across transaction boundries. -hirohama
* ----------------
*/
portalContext = (MemoryContext) PortalGetHeapMemory(GetPortalByName(NULL));
MemoryContextSwitchTo(portalContext);
StartPortalAllocMode(DefaultAllocMode, 0);
return portal;
}
/* ----------------------------------------------------------------
* ProcessQueryDesc
* ProcessQuery
*
* Read the comments for ProcessQuery() below...
* Execute a plan, the non-parallel version
* ----------------------------------------------------------------
*/
static void
ProcessQueryDesc(QueryDesc *queryDesc, Node *limoffset, Node *limcount)
void
ProcessQuery(Query *parsetree,
Plan *plan,
CommandDest dest)
{
Query *parseTree;
Plan *plan;
int operation;
char *tag = NULL;
EState *state;
TupleDesc attinfo;
int operation = parsetree->commandType;
char *tag;
bool isRetrieveIntoPortal;
bool isRetrieveIntoRelation;
Portal portal = NULL;
char *intoName = NULL;
CommandDest dest;
/* ----------------
* get info from the query desc
* ----------------
*/
parseTree = queryDesc->parsetree;
plan = queryDesc->plantree;
QueryDesc *queryDesc;
EState *state;
TupleDesc attinfo;
operation = queryDesc->operation;
set_ps_display(tag = CreateOperationTag(operation));
dest = queryDesc->dest;
/* ----------------
* initialize portal/into relation status
......@@ -232,11 +186,11 @@ ProcessQueryDesc(QueryDesc *queryDesc, Node *limoffset, Node *limcount)
if (operation == CMD_SELECT)
{
if (parseTree->isPortal)
if (parsetree->isPortal)
{
isRetrieveIntoPortal = true;
intoName = parseTree->into;
if (parseTree->isBinary)
intoName = parsetree->into;
if (parsetree->isBinary)
{
/*
......@@ -244,19 +198,38 @@ ProcessQueryDesc(QueryDesc *queryDesc, Node *limoffset, Node *limcount)
* (externalized form) to RemoteInternal (internalized
* form)
*/
dest = queryDesc->dest = RemoteInternal;
dest = RemoteInternal;
}
}
else if (parseTree->into != NULL)
else if (parsetree->into != NULL)
{
/* select into table */
isRetrieveIntoRelation = true;
}
}
/* ----------------
* If retrieving into a portal, set up the portal and copy
* the parsetree and plan into its memory context.
* ----------------
*/
if (isRetrieveIntoPortal)
{
portal = PreparePortal(intoName);
/* CurrentMemoryContext is now pointing to portal's context */
parsetree = copyObject(parsetree);
plan = copyObject(plan);
}
/* ----------------
* when performing a retrieve into, we override the normal
* Now we can create the QueryDesc object (this is also in
* the portal context, if portal retrieve).
* ----------------
*/
queryDesc = CreateQueryDesc(parsetree, plan, dest);
/* ----------------
* When performing a retrieve into, we override the normal
* communication destination during the processing of the
* the query. This only affects the tuple-output function
* - the correct destination will still see BeginCommand()
......@@ -293,26 +266,19 @@ ProcessQueryDesc(QueryDesc *queryDesc, Node *limoffset, Node *limcount)
dest);
/* ----------------
* Named portals do not do a "fetch all" initially, so now
* we return since ExecMain has been called with EXEC_START
* to initialize the query plan.
*
* Note: ProcessPortal transforms the current "blank" portal
* into a named portal and creates a new blank portal so
* everything we allocated in the current "blank" memory
* context will be preserved across queries. -cim 2/22/91
* If retrieve into portal, stop now; we do not run the plan
* until a FETCH command is received.
* ----------------
*/
if (isRetrieveIntoPortal)
{
PortalExecutorHeapMemory = NULL;
PortalSetQuery(portal,
queryDesc,
attinfo,
state,
PortalCleanup);
ProcessPortal(intoName,
parseTree,
plan,
state,
attinfo,
dest);
MemoryContextSwitchTo(TransactionCommandContext);
EndCommand(tag, dest);
return;
......@@ -323,14 +289,14 @@ ProcessQueryDesc(QueryDesc *queryDesc, Node *limoffset, Node *limcount)
* actually run the plan..
* ----------------
*/
ExecutorRun(queryDesc, state, EXEC_RUN, limoffset, limcount);
ExecutorRun(queryDesc, state, EXEC_RUN,
parsetree->limitOffset, parsetree->limitCount);
/* save infos for EndCommand */
UpdateCommandInfo(operation, state->es_lastoid, state->es_processed);
/* ----------------
* now, we close down all the scans and free allocated resources...
* with ExecutorEnd()
* Now, we close down all the scans and free allocated resources.
* ----------------
*/
ExecutorEnd(queryDesc, state);
......@@ -341,31 +307,3 @@ ProcessQueryDesc(QueryDesc *queryDesc, Node *limoffset, Node *limcount)
*/
EndCommand(tag, dest);
}
/* ----------------------------------------------------------------
* ProcessQuery
*
* Execute a plan, the non-parallel version
* ----------------------------------------------------------------
*/
void
ProcessQuery(Query *parsetree,
Plan *plan,
CommandDest dest)
{
QueryDesc *queryDesc;
extern int dontExecute; /* from postgres.c */
extern void print_plan(Plan *p, Query *parsetree); /* from print.c */
queryDesc = CreateQueryDesc(parsetree, plan, dest);
if (dontExecute)
{
/* don't execute it, just show the query plan */
print_plan(plan, parsetree);
}
else
ProcessQueryDesc(queryDesc, parsetree->limitOffset,
parsetree->limitCount);
}
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.67 2000/06/19 03:54:31 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.68 2000/06/28 03:32:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -60,10 +60,6 @@ static Datum cc_hashname(PG_FUNCTION_ARGS);
static CatCache *Caches = NULL; /* head of list of caches */
GlobalMemory CacheCxt; /* context in which caches are allocated */
/* CacheCxt is global because relcache uses it too. */
/* ----------------
* EQPROC is used in CatalogCacheInitializeCache to find the equality
......@@ -135,6 +131,28 @@ cc_hashname(PG_FUNCTION_ARGS)
}
/*
* Standard routine for creating cache context if it doesn't exist yet
*
* There are a lot of places (probably far more than necessary) that check
* whether CacheMemoryContext exists yet and want to create it if not.
* We centralize knowledge of exactly how to create it here.
*/
void
CreateCacheMemoryContext(void)
{
/* Purely for paranoia, check that context doesn't exist;
* caller probably did so already.
*/
if (!CacheMemoryContext)
CacheMemoryContext = AllocSetContextCreate(TopMemoryContext,
"CacheMemoryContext",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
}
/* --------------------------------
* CatalogCacheInitializeCache
* --------------------------------
......@@ -183,9 +201,10 @@ CatalogCacheInitializeCache(CatCache * cache,
* do not vanish at the end of a transaction
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/* ----------------
* If no relation was passed we must open it to get access to
......@@ -415,7 +434,7 @@ CatalogCacheComputeTupleHashIndex(CatCache * cacheInOutP,
/* --------------------------------
* CatCacheRemoveCTup
*
* NB: assumes caller has switched to CacheCxt
* NB: assumes caller has switched to CacheMemoryContext
* --------------------------------
*/
static void
......@@ -477,9 +496,10 @@ CatalogCacheIdInvalidate(int cacheId, /* XXX */
* switch to the cache context for our memory allocations
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/* ----------------
* inspect every cache that could contain the tuple
......@@ -552,10 +572,10 @@ ResetSystemCache()
* do not vanish at the end of a transaction
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/* ----------------
* here we purge the contents of all the caches
......@@ -681,10 +701,10 @@ InitSysCache(char *relname,
* do not vanish at the end of a transaction
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/* ----------------
* allocate a new cache structure
......@@ -839,14 +859,14 @@ SearchSelfReferences(CatCache * cache)
HeapScanDesc sd;
MemoryContext oldcxt;
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
rel = heap_open(cache->relationId, AccessShareLock);
sd = heap_beginscan(rel, false, SnapshotNow, 1, cache->cc_skey);
ntp = heap_getnext(sd, 0);
if (!HeapTupleIsValid(ntp))
elog(ERROR, "SearchSelfReferences: tuple not found");
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
indexSelfTuple = heap_copytuple(ntp);
MemoryContextSwitchTo(oldcxt);
heap_endscan(sd);
......@@ -868,14 +888,14 @@ SearchSelfReferences(CatCache * cache)
HeapScanDesc sd;
MemoryContext oldcxt;
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
rel = heap_open(cache->relationId, AccessShareLock);
sd = heap_beginscan(rel, false, SnapshotNow, 1, cache->cc_skey);
ntp = heap_getnext(sd, 0);
if (!HeapTupleIsValid(ntp))
elog(ERROR, "SearchSelfReferences: tuple not found");
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
operatorSelfTuple[lookup_oid - MIN_OIDCMP] = heap_copytuple(ntp);
MemoryContextSwitchTo(oldcxt);
heap_endscan(sd);
......@@ -908,7 +928,6 @@ SearchSysCache(CatCache * cache,
CatCTup *nct2;
Dlelem *elt;
HeapTuple ntp = NULL;
Relation relation;
MemoryContext oldcxt;
......@@ -1020,10 +1039,10 @@ SearchSysCache(CatCache * cache,
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/* ----------------
* Scan the relation to find the tuple. If there's an index, and
......@@ -1060,12 +1079,13 @@ SearchSysCache(CatCache * cache,
*/
if (HeapTupleIsValid(indextp))
{
MemoryContextSwitchTo((MemoryContext) CacheCxt);
MemoryContextSwitchTo(CacheMemoryContext);
ntp = heap_copytuple(indextp);
/* this switch is probably not needed anymore: */
MemoryContextSwitchTo(oldcxt);
heap_freetuple(indextp);
}
MemoryContextSwitchTo((MemoryContext) CacheCxt);
MemoryContextSwitchTo(CacheMemoryContext);
}
else
{
......@@ -1084,7 +1104,7 @@ SearchSysCache(CatCache * cache,
ntp = heap_getnext(sd, 0);
MemoryContextSwitchTo((MemoryContext) CacheCxt);
MemoryContextSwitchTo(CacheMemoryContext);
if (HeapTupleIsValid(ntp))
{
......@@ -1097,7 +1117,7 @@ SearchSysCache(CatCache * cache,
heap_endscan(sd);
MemoryContextSwitchTo((MemoryContext) CacheCxt);
MemoryContextSwitchTo(CacheMemoryContext);
}
cache->busy = false;
......@@ -1205,9 +1225,10 @@ RelationInvalidateCatalogCacheTuple(Relation relation,
* switch to the cache memory context
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/* ----------------
* for each cache
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.103 2000/06/19 23:40:48 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.104 2000/06/28 03:32:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -917,10 +917,10 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
/* ----------------
* allocate storage for the relation descriptor,
* initialize relation->rd_rel and get the access method id.
* The storage is allocated in memory context CacheCxt.
* The storage is allocated in memory context CacheMemoryContext.
* ----------------
*/
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
relation = AllocateRelationDesc(oldrelation, natts, relp);
relam = relation->rd_rel->relam;
......@@ -1383,7 +1383,7 @@ RelationClearRelation(Relation relation, bool rebuildIt)
if (relation->rd_isnailed)
return;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/*
* Remove relation from hash tables
......@@ -1574,7 +1574,7 @@ RelationForgetRelation(Oid rid)
List *curr;
List *prev = NIL;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
foreach(curr, newlyCreatedRelns)
{
......@@ -1731,10 +1731,7 @@ RelationRegisterRelation(Relation relation)
{
MemoryContext oldcxt;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
if (oldcxt != (MemoryContext) CacheCxt)
elog(NOIND, "RelationRegisterRelation: WARNING: Context != CacheCxt");
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
RelationInitLockInfo(relation);
......@@ -1769,7 +1766,7 @@ RelationPurgeLocalRelation(bool xactCommitted)
if (newlyCreatedRelns == NULL)
return;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
while (newlyCreatedRelns)
{
......@@ -1822,10 +1819,10 @@ RelationInitialize(void)
* switch to cache memory context
* ----------------
*/
if (!CacheCxt)
CacheCxt = CreateGlobalMemory("Cache");
if (!CacheMemoryContext)
CreateCacheMemoryContext();
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
/* ----------------
* create global caches
......@@ -2186,7 +2183,7 @@ RelationGetIndexList(Relation relation)
heap_close(indrel, AccessShareLock);
/* Now save a copy of the completed list in the relcache entry. */
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
relation->rd_indexlist = listCopy(result);
relation->rd_indexfound = true;
MemoryContextSwitchTo(oldcxt);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.24 2000/06/20 06:41:12 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.25 2000/06/28 03:32:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -67,7 +67,7 @@ create_temp_relation(const char *relname, HeapTuple pg_class_tuple)
MemoryContext oldcxt;
TempTable *temp_rel;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
temp_rel = (TempTable *) palloc(sizeof(TempTable));
temp_rel->user_relname = (char *) palloc(NAMEDATALEN);
......@@ -135,7 +135,7 @@ remove_temp_relation(Oid relid)
List *l,
*prev;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
prev = NIL;
l = temp_rels;
......@@ -185,7 +185,7 @@ invalidate_temp_relations(void)
List *l,
*prev;
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
prev = NIL;
l = temp_rels;
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.60 2000/06/04 15:06:29 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.61 2000/06/28 03:32:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -27,7 +27,7 @@
#include <sys/time.h>
#include <ctype.h>
#ifdef ENABLE_SYSLOG
# include <syslog.h>
#include <syslog.h>
#endif
#include "libpq/libpq.h"
......@@ -89,10 +89,9 @@ static int ElogDebugIndentLevel = 0;
*--------------------
*/
void
elog(int lev, const char *fmt,...)
elog(int lev, const char *fmt, ...)
{
va_list ap;
/*
* The expanded format and final output message are dynamically
* allocated if necessary, but not if they fit in the "reasonable
......@@ -101,12 +100,21 @@ elog(int lev, const char *fmt,...)
* working (since memory-clobber errors often take out malloc first).
* Don't make these buffers unreasonably large though, on pain of
* having to chase a bug with no error message.
*
* Note that we use malloc() not palloc() because we want to retain
* control if we run out of memory. palloc() would recursively call
* elog(ERROR), which would be all right except if we are working on a
* FATAL or REALLYFATAL error. We'd lose track of the fatal condition
* and report a mere ERROR to outer loop, which would be a Bad Thing.
* So, we substitute an appropriate message in-place, without downgrading
* the level if it's above ERROR.
*/
char fmt_fixedbuf[128];
char msg_fixedbuf[256];
char *fmt_buf = fmt_fixedbuf;
char *msg_buf = msg_fixedbuf;
/* this buffer is only used for strange values of lev: */
char prefix_buf[32];
/* this buffer is only used if errno has a bogus value: */
char errorstr_buf[32];
const char *errorstr;
......@@ -115,7 +123,6 @@ elog(int lev, const char *fmt,...)
char *bp;
int indent = 0;
int space_needed;
int len;
/* size of the prefix needed for timestamp and pid, if enabled */
size_t timestamp_size;
......@@ -123,6 +130,15 @@ elog(int lev, const char *fmt,...)
if (lev <= DEBUG && Debugfile < 0)
return; /* ignore debug msgs if noplace to send */
/* save errno string for %m */
if (errno < sys_nerr && errno >= 0)
errorstr = strerror(errno);
else
{
sprintf(errorstr_buf, "error %d", errno);
errorstr = errorstr_buf;
}
if (lev == ERROR || lev == FATAL)
{
/* this is probably redundant... */
......@@ -156,21 +172,11 @@ elog(int lev, const char *fmt,...)
prefix = "ERROR: ";
break;
default:
/* temporarily use msg buf for prefix */
sprintf(msg_fixedbuf, "FATAL %d: ", lev);
prefix = msg_fixedbuf;
sprintf(prefix_buf, "FATAL %d: ", lev);
prefix = prefix_buf;
break;
}
/* get errno string for %m */
if (errno < sys_nerr && errno >= 0)
errorstr = strerror(errno);
else
{
sprintf(errorstr_buf, "error %d", errno);
errorstr = errorstr_buf;
}
timestamp_size = 0;
if (Log_timestamp)
timestamp_size += TIMESTAMP_SIZE;
......@@ -190,9 +196,13 @@ elog(int lev, const char *fmt,...)
fmt_buf = (char *) malloc(space_needed);
if (fmt_buf == NULL)
{
/* We're up against it, convert to fatal out-of-memory error */
/* We're up against it, convert to out-of-memory error */
fmt_buf = fmt_fixedbuf;
lev = REALLYFATAL;
if (lev < FATAL)
{
lev = ERROR;
prefix = "ERROR: ";
}
fmt = "elog: out of memory"; /* this must fit in
* fmt_fixedbuf! */
}
......@@ -281,15 +291,20 @@ elog(int lev, const char *fmt,...)
msg_buf = (char *) malloc(space_needed);
if (msg_buf == NULL)
{
/* We're up against it, convert to fatal out-of-memory error */
/* We're up against it, convert to out-of-memory error */
msg_buf = msg_fixedbuf;
lev = REALLYFATAL;
if (lev < FATAL)
{
lev = ERROR;
prefix = "ERROR: ";
}
msg_buf[0] = '\0';
if (Log_timestamp)
strcat(msg_buf, print_timestamp());
if (Log_pid)
strcat(msg_buf, print_pid());
strcat(msg_buf, "FATAL: elog: out of memory");
strcat(msg_buf, prefix);
strcat(msg_buf, "elog: out of memory");
break;
}
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.42 2000/06/15 04:10:29 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.43 2000/06/28 03:32:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -134,7 +134,7 @@ load_external_function(char *filename, char *funcname)
file_scanner = (DynamicFileList *)
malloc(sizeof(DynamicFileList) + strlen(filename));
if (file_scanner == NULL)
elog(FATAL, "Out of memory in load_external_function");
elog(ERROR, "Out of memory in load_external_function");
MemSet((char *) file_scanner, 0, sizeof(DynamicFileList));
strcpy(file_scanner->filename, filename);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.31 2000/04/12 17:16:00 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.32 2000/06/28 03:32:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -56,8 +56,7 @@
/*
* Private function prototypes
*/
static long *DynaHashAlloc(unsigned int size);
static void DynaHashFree(Pointer ptr);
static void *DynaHashAlloc(Size size);
static uint32 call_hash(HTAB *hashp, char *k);
static SEG_OFFSET seg_alloc(HTAB *hashp);
static int bucket_alloc(HTAB *hashp);
......@@ -66,9 +65,7 @@ static int expand_table(HTAB *hashp);
static int hdefault(HTAB *hashp);
static int init_htab(HTAB *hashp, int nelem);
typedef long *((*dhalloc_ptr) ());
#ifndef FRONTEND
/* ----------------
* memory allocation routines
*
......@@ -84,34 +81,24 @@ typedef long *((*dhalloc_ptr) ());
* do the latter -cim 1/19/91
* ----------------
*/
GlobalMemory DynaHashCxt = (GlobalMemory) NULL;
static MemoryContext DynaHashCxt = NULL;
static long *
DynaHashAlloc(unsigned int size)
static void *
DynaHashAlloc(Size size)
{
if (!DynaHashCxt)
DynaHashCxt = CreateGlobalMemory("DynaHash");
DynaHashCxt = AllocSetContextCreate(TopMemoryContext,
"DynaHash",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
return (long *)
MemoryContextAlloc((MemoryContext) DynaHashCxt, size);
}
static void
DynaHashFree(Pointer ptr)
{
MemoryContextFree((MemoryContext) DynaHashCxt, ptr);
return MemoryContextAlloc(DynaHashCxt, size);
}
#define MEM_ALLOC DynaHashAlloc
#define MEM_FREE DynaHashFree
#else /* FRONTEND */
#define MEM_ALLOC palloc
#define MEM_FREE pfree
#endif /* FRONTEND */
/*
* pointer access macros. Shared memory implementation cannot
......@@ -147,7 +134,7 @@ hash_create(int nelem, HASHCTL *info, int flags)
HTAB *hashp;
hashp = (HTAB *) MEM_ALLOC((unsigned long) sizeof(HTAB));
hashp = (HTAB *) MEM_ALLOC(sizeof(HTAB));
MemSet(hashp, 0, sizeof(HTAB));
if (flags & HASH_FUNCTION)
......@@ -181,7 +168,7 @@ hash_create(int nelem, HASHCTL *info, int flags)
/* setup hash table defaults */
hashp->hctl = NULL;
hashp->alloc = (dhalloc_ptr) MEM_ALLOC;
hashp->alloc = MEM_ALLOC;
hashp->dir = NULL;
hashp->segbase = NULL;
......@@ -189,7 +176,7 @@ hash_create(int nelem, HASHCTL *info, int flags)
if (!hashp->hctl)
{
hashp->hctl = (HHDR *) hashp->alloc((unsigned long) sizeof(HHDR));
hashp->hctl = (HHDR *) hashp->alloc(sizeof(HHDR));
if (!hashp->hctl)
return 0;
}
......@@ -318,7 +305,8 @@ init_htab(HTAB *hashp, int nelem)
/* Allocate a directory */
if (!(hashp->dir))
{
hashp->dir = (SEG_OFFSET *) hashp->alloc(hctl->dsize * sizeof(SEG_OFFSET));
hashp->dir = (SEG_OFFSET *)
hashp->alloc(hctl->dsize * sizeof(SEG_OFFSET));
if (!hashp->dir)
return -1;
}
......@@ -445,7 +433,7 @@ hash_destroy(HTAB *hashp)
/* cannot destroy a shared memory hash table */
Assert(!hashp->segbase);
/* allocation method must be one we know how to free, too */
Assert(hashp->alloc == (dhalloc_ptr) MEM_ALLOC);
Assert(hashp->alloc == MEM_ALLOC);
hash_stats("destroy", hashp);
......@@ -885,7 +873,7 @@ dir_realloc(HTAB *hashp)
new_dirsize = new_dsize * sizeof(SEG_OFFSET);
old_p = (char *) hashp->dir;
p = (char *) hashp->alloc((unsigned long) new_dirsize);
p = (char *) hashp->alloc((Size) new_dirsize);
if (p != NULL)
{
......@@ -906,8 +894,7 @@ seg_alloc(HTAB *hashp)
SEGMENT segp;
SEG_OFFSET segOffset;
segp = (SEGMENT) hashp->alloc((unsigned long)
sizeof(BUCKET_INDEX) * hashp->hctl->ssize);
segp = (SEGMENT) hashp->alloc(sizeof(BUCKET_INDEX) * hashp->hctl->ssize);
if (!segp)
return 0;
......@@ -937,8 +924,7 @@ bucket_alloc(HTAB *hashp)
/* make sure its aligned correctly */
bucketSize = MAXALIGN(bucketSize);
tmpBucket = (ELEMENT *)
hashp->alloc((unsigned long) BUCKET_ALLOC_INCR * bucketSize);
tmpBucket = (ELEMENT *) hashp->alloc(BUCKET_ALLOC_INCR * bucketSize);
if (!tmpBucket)
return 0;
......
......@@ -4,14 +4,14 @@
# Makefile for utils/init
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/init/Makefile,v 1.13 2000/05/29 05:45:32 tgl Exp $
# $Header: /cvsroot/pgsql/src/backend/utils/init/Makefile,v 1.14 2000/06/28 03:32:43 tgl Exp $
#
#-------------------------------------------------------------------------
SRCDIR = ../../..
include ../../../Makefile.global
OBJS = enbl.o findbe.o globals.o miscinit.o postinit.o
OBJS = findbe.o globals.o miscinit.o postinit.o
all: SUBSYS.o
......@@ -27,4 +27,3 @@ clean:
ifeq (depend,$(wildcard depend))
include depend
endif
/*-------------------------------------------------------------------------
*
* enbl.c
* POSTGRES module enable and disable support code.
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/enbl.c,v 1.10 2000/01/26 05:57:26 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "utils/module.h"
/*
* BypassEnable
* False iff enable/disable processing is required given on and "*countP."
*
* Note:
* As a side-effect, *countP is modified. It should be 0 initially.
*
* Exceptions:
* BadState if called with pointer to value 0 and false.
* BadArg if "countP" is invalid pointer.
* BadArg if on is invalid.
*/
bool
BypassEnable(int *enableCountInOutP, bool on)
{
AssertArg(PointerIsValid(enableCountInOutP));
AssertArg(BoolIsValid(on));
if (on)
{
*enableCountInOutP += 1;
return (bool) (*enableCountInOutP >= 2);
}
Assert(*enableCountInOutP >= 1);
*enableCountInOutP -= 1;
return (bool) (*enableCountInOutP >= 1);
}
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.59 2000/05/30 00:49:56 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.60 2000/06/28 03:32:43 tgl Exp $
*
*
*-------------------------------------------------------------------------
......@@ -40,8 +40,6 @@
#include "mb/pg_wchar.h"
#endif
void BaseInit(void);
static void ReverifyMyDatabase(const char *name);
static void InitCommunication(void);
......@@ -222,8 +220,6 @@ InitCommunication()
* Be very careful with the order of calls in the InitPostgres function.
* --------------------------------
*/
extern int NBuffers;
int lockingOff = 0; /* backend -L switch */
/*
......@@ -405,21 +401,6 @@ InitPostgres(const char *dbname)
void
BaseInit(void)
{
/*
* Turn on the exception handler. Note: we cannot use elog, Assert,
* AssertState, etc. until after exception handling is on.
*/
EnableExceptionHandling(true);
/*
* Memory system initialization - we may call palloc after
* EnableMemoryContext()). Note that EnableMemoryContext() must
* happen before EnablePortalManager().
*/
EnableMemoryContext(true); /* initializes the "top context" */
EnablePortalManager(true); /* memory for portal/transaction stuff */
/*
* Attach to shared memory and semaphores, and initialize our
* input/output/debugging file descriptors.
......@@ -427,4 +408,6 @@ BaseInit(void)
InitCommunication();
DebugFileOpen();
smgrinit();
EnablePortalManager(); /* memory for portal/transaction stuff */
}
......@@ -6,7 +6,7 @@
* WIN1250 client encoding support contributed by Pavel Behal
* SJIS UDC (NEC selection IBM kanji) support contributed by Eiji Tokuya
*
* $Id: conv.c,v 1.15 2000/05/20 13:12:26 ishii Exp $
* $Id: conv.c,v 1.16 2000/06/28 03:32:45 tgl Exp $
*
*
*/
......@@ -1521,7 +1521,8 @@ pg_encoding_conv_tbl pg_conv_tbl[] = {
};
#ifdef DEBUGMAIN
#include "utils/mcxt.h"
#include "postgres.h"
#include "utils/memutils.h"
/*
* testing for sjis2mic() and mic2sjis()
*/
......@@ -1565,21 +1566,23 @@ main()
void
elog(int lev, const char *fmt,...)
{
};
}
MemoryContext CurrentMemoryContext;
Pointer
void *
MemoryContextAlloc(MemoryContext context, Size size)
{
};
Pointer
MemoryContextRealloc(MemoryContext context,
Pointer pointer,
Size size)
{
};
}
void
MemoryContextFree(MemoryContext context, Pointer pointer)
pfree(void *pointer)
{
};
}
void *
repalloc(void *pointer, Size size)
{
}
#endif
......@@ -4,14 +4,14 @@
# Makefile for utils/mmgr
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Makefile,v 1.8 2000/05/29 05:45:40 tgl Exp $
# $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Makefile,v 1.9 2000/06/28 03:32:50 tgl Exp $
#
#-------------------------------------------------------------------------
SRCDIR = ../../..
include ../../../Makefile.global
OBJS = aset.o mcxt.o palloc.o portalmem.o oset.o
OBJS = aset.o mcxt.o portalmem.o
all: SUBSYS.o
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*-------------------------------------------------------------------------
*
* palloc.c
* POSTGRES memory allocator code.
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/palloc.c,v 1.18 2000/05/30 00:49:57 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
/* ----------------------------------------------------------------
* User library functions
* ----------------------------------------------------------------
*/
/* ----------
* palloc(), pfree() and repalloc() are now macros in palloc.h
* ----------
*/
char *
pstrdup(const char *string)
{
char *nstr;
int len;
nstr = palloc(len = strlen(string) + 1);
memcpy(nstr, string, len);
return nstr;
}
This diff is collapsed.
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: command.h,v 1.18 2000/04/12 17:16:31 momjian Exp $
* $Id: command.h,v 1.19 2000/06/28 03:32:57 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -16,7 +16,6 @@
#include "utils/portal.h"
extern MemoryContext PortalExecutorHeapMemory;
/*
* PerformPortalFetch
......
This diff is collapsed.
......@@ -28,7 +28,6 @@
#include "utils/fcache.h"
#include "utils/datum.h"
#include "utils/syscache.h"
#include "utils/portal.h"
#include "utils/builtins.h"
#include "catalog/pg_language.h"
#include "access/heapam.h"
......@@ -95,4 +94,6 @@ extern void *SPI_repalloc(void *pointer, Size size);
extern void SPI_pfree(void *pointer);
extern void SPI_freetuple(HeapTuple pointer);
extern void AtEOXact_SPI(void);
#endif /* SPI_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment