*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.120 2000/08/06 04:26:40 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.121 2000/08/22 04:06:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "executor/executor.h"
#include "libpq/libpq.h"
#include "miscadmin.h"
+#include "tcop/pquery.h"
#include "tcop/tcopprot.h"
#include "utils/acl.h"
#include "utils/builtins.h"
tuples_read = 0;
bool reading_to_eof = true;
RelationInfo *relationInfo;
- EState *estate = makeNode(EState); /* for ExecConstraints() */
+ EState *estate = CreateExecutorState(); /* for ExecConstraints() */
TupleTable tupleTable;
TupleTableSlot *slot;
Oid loaded_oid = InvalidOid;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.123 2000/08/06 04:26:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.124 2000/08/22 04:06:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
int ncheck = rel->rd_att->constr->num_check;
ConstrCheck *check = rel->rd_att->constr->check;
- MemoryContext oldContext;
ExprContext *econtext;
+ MemoryContext oldContext;
List *qual;
int i;
/*
- * Make sure econtext, expressions, etc are placed in appropriate context.
+ * We will use the EState's per-tuple context for evaluating constraint
+ * expressions. Create it if it's not already there; if it is, reset it
+ * to free previously-used storage.
*/
- oldContext = MemoryContextSwitchTo(TransactionCommandContext);
-
- /*
- * Create or reset the exprcontext for evaluating constraint expressions.
- */
- econtext = estate->es_constraint_exprcontext;
+ econtext = estate->es_per_tuple_exprcontext;
if (econtext == NULL)
- estate->es_constraint_exprcontext = econtext =
- MakeExprContext(NULL, TransactionCommandContext);
+ {
+ oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
+ estate->es_per_tuple_exprcontext = econtext =
+ MakeExprContext(NULL, estate->es_query_cxt);
+ MemoryContextSwitchTo(oldContext);
+ }
else
ResetExprContext(econtext);
/*
* If first time through for current result relation, set up econtext's
* range table to refer to result rel, and build expression nodetrees
- * for rel's constraint expressions. All this stuff is kept in
- * TransactionCommandContext so it will still be here next time through.
+ * for rel's constraint expressions. All this stuff is kept in the
+ * per-query memory context so it will still be here next time through.
*
* NOTE: if there are multiple result relations (eg, due to inheritance)
* then we leak storage for prior rel's expressions and rangetable.
if (econtext->ecxt_range_table == NIL ||
getrelid(1, econtext->ecxt_range_table) != RelationGetRelid(rel))
{
- RangeTblEntry *rte = makeNode(RangeTblEntry);
+ RangeTblEntry *rte;
+
+ /*
+ * Make sure expressions, etc are placed in appropriate context.
+ */
+ oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
+
+ rte = makeNode(RangeTblEntry);
rte->relname = RelationGetRelationName(rel);
rte->ref = makeNode(Attr);
qual = (List *) stringToNode(check[i].ccbin);
estate->es_result_relation_constraints[i] = qual;
}
- }
- /* Done with building long-lived items */
- MemoryContextSwitchTo(oldContext);
+ /* Done with building long-lived items */
+ MemoryContextSwitchTo(oldContext);
+ }
/* Arrange for econtext's scan tuple to be the tuple under test */
econtext->ecxt_scantuple = slot;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.64 2000/07/14 22:17:45 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.65 2000/08/22 04:06:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
heapTuple = slot->val;
- /* ----------------
- * get information from the result relation info structure.
- * ----------------
+ /*
+ * Get information from the result relation info structure.
*/
resultRelationInfo = estate->es_result_relation_info;
numIndices = resultRelationInfo->ri_NumIndices;
heapRelation = resultRelationInfo->ri_RelationDesc;
heapDescriptor = RelationGetDescr(heapRelation);
- /* ----------------
- * Make a temporary expr/memory context for evaluating predicates
- * and functional-index functions.
- * XXX should do this once per command not once per tuple, and
- * just reset it once per tuple.
- * ----------------
+ /*
+ * We will use the EState's per-tuple context for evaluating predicates
+ * and functional-index functions. Create it if it's not already there;
+ * if it is, reset it to free previously-used storage.
*/
- econtext = MakeExprContext(slot, TransactionCommandContext);
+ econtext = estate->es_per_tuple_exprcontext;
+ if (econtext == NULL)
+ {
+ MemoryContext oldContext;
+
+ oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
+ estate->es_per_tuple_exprcontext = econtext =
+ MakeExprContext(NULL, estate->es_query_cxt);
+ MemoryContextSwitchTo(oldContext);
+ }
+ else
+ ResetExprContext(econtext);
+
+ /* Arrange for econtext's scan tuple to be the tuple under test */
+ econtext->ecxt_scantuple = slot;
/* ----------------
* for each index, form and insert the index tuple
if (result)
pfree(result);
}
-
- FreeExprContext(econtext);
}
void
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $Id: nodeHash.c,v 1.50 2000/07/17 03:04:53 tgl Exp $
+ * $Id: nodeHash.c,v 1.51 2000/08/22 04:06:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* ----------------
* Initialize the hash table control block.
- * The hashtable control block is just palloc'd from executor memory.
+ * The hashtable control block is just palloc'd from the executor's
+ * per-query memory context.
* ----------------
*/
hashtable = (HashJoinTable) palloc(sizeof(HashTableData));
* working storage. See notes in executor/hashjoin.h.
* ----------------
*/
- hashtable->hashCxt = AllocSetContextCreate(TransactionCommandContext,
+ hashtable->hashCxt = AllocSetContextCreate(CurrentMemoryContext,
"HashTableContext",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.37 2000/07/17 03:05:15 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.38 2000/08/22 04:06:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
state->es_direction = ForwardScanDirection;
state->es_range_table = NIL;
- state->es_into_relation_descriptor = NULL;
state->es_result_relation_info = NULL;
+ state->es_into_relation_descriptor = NULL;
state->es_param_list_info = NULL;
state->es_param_exec_vals = NULL;
state->es_junkFilter = NULL;
+ state->es_query_cxt = CurrentMemoryContext;
+
+ state->es_per_tuple_exprcontext = NULL;
+
/* ----------------
* return the executor state structure
* ----------------
}
/* ----------------
- * Create the new portal and make its memory context active.
+ * Create the new portal.
* ----------------
*/
portal = CreatePortal(portalName);
- MemoryContextSwitchTo(PortalGetHeapMemory(portal));
-
return portal;
}
char *tag;
bool isRetrieveIntoPortal;
bool isRetrieveIntoRelation;
- Portal portal = NULL;
char *intoName = NULL;
+ Portal portal = NULL;
+ MemoryContext oldContext = NULL;
QueryDesc *queryDesc;
EState *state;
TupleDesc attinfo;
if (isRetrieveIntoPortal)
{
portal = PreparePortal(intoName);
- /* CurrentMemoryContext is now pointing to portal's context */
+ oldContext = MemoryContextSwitchTo(PortalGetHeapMemory(portal));
parsetree = copyObject(parsetree);
plan = copyObject(plan);
+ /*
+ * We stay in portal's memory context for now, so that query desc,
+ * EState, and plan startup info are also allocated in the portal
+ * context.
+ */
}
/* ----------------
- * Now we can create the QueryDesc object (this is also in
- * the portal context, if portal retrieve).
+ * Now we can create the QueryDesc object.
* ----------------
*/
queryDesc = CreateQueryDesc(parsetree, plan, dest);
queryDesc->dest = (int) None;
/* ----------------
- * create a default executor state..
+ * create a default executor state.
* ----------------
*/
state = CreateExecutorState();
state,
PortalCleanup);
- MemoryContextSwitchTo(TransactionCommandContext);
+ /* Now we can return to caller's memory context. */
+ MemoryContextSwitchTo(oldContext);
EndCommand(tag, dest);
+
return;
}
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: hashjoin.h,v 1.18 2000/07/12 02:37:30 tgl Exp $
+ * $Id: hashjoin.h,v 1.19 2000/08/22 04:06:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* This makes it easy and fast to release the storage when we don't need it
* anymore.
*
- * The contexts are made children of TransactionCommandContext, ensuring
+ * The hashtable contexts are made children of the per-query context, ensuring
* that they will be discarded at end of statement even if the join is
* aborted early by an error. (Likewise, any temporary files we make will
* be cleaned up by the virtual file manager in event of an error.)
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: execnodes.h,v 1.46 2000/08/13 02:50:24 tgl Exp $
+ * $Id: execnodes.h,v 1.47 2000/08/22 04:06:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
uint32 es_processed; /* # of tuples processed */
Oid es_lastoid; /* last oid processed (by INSERT) */
List *es_rowMark; /* not good place, but there is no other */
- /* these two fields are storage space for ExecConstraints(): */
+ MemoryContext es_query_cxt; /* per-query context in which EState lives */
+ /* this ExprContext is for per-output-tuple operations, such as
+ * constraint checks and index-value computations. It can be reset
+ * for each output tuple. Note that it will be created only if needed.
+ */
+ ExprContext *es_per_tuple_exprcontext;
+ /* this field is storage space for ExecConstraints(): */
List **es_result_relation_constraints;
- ExprContext *es_constraint_exprcontext;
/* Below is to re-evaluate plan qual in READ COMMITTED mode */
struct Plan *es_origPlan;
Pointer es_evalPlanQual;