diff options
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/execMain.c | 42 | ||||
-rw-r--r-- | src/backend/executor/execUtils.c | 35 | ||||
-rw-r--r-- | src/backend/executor/nodeHash.c | 7 |
3 files changed, 51 insertions, 33 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index e66107ce7d1..2db826144dc 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -27,7 +27,7 @@ * * * 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 $ * *------------------------------------------------------------------------- */ @@ -1574,31 +1574,32 @@ ExecRelCheck(Relation rel, TupleTableSlot *slot, EState *estate) { 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. @@ -1608,7 +1609,14 @@ ExecRelCheck(Relation rel, TupleTableSlot *slot, EState *estate) 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); @@ -1627,10 +1635,10 @@ ExecRelCheck(Relation rel, TupleTableSlot *slot, EState *estate) 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; diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 39e3d5cd48b..63c1e9e157f 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -8,7 +8,7 @@ * * * 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 $ * *------------------------------------------------------------------------- */ @@ -866,9 +866,8 @@ ExecInsertIndexTuples(TupleTableSlot *slot, 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; @@ -877,14 +876,26 @@ ExecInsertIndexTuples(TupleTableSlot *slot, 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 @@ -935,8 +946,6 @@ ExecInsertIndexTuples(TupleTableSlot *slot, if (result) pfree(result); } - - FreeExprContext(econtext); } void diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index f63ffe49435..682afdba4af 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -7,7 +7,7 @@ * 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 $ * *------------------------------------------------------------------------- */ @@ -334,7 +334,8 @@ ExecHashTableCreate(Hash *node) /* ---------------- * 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)); @@ -361,7 +362,7 @@ ExecHashTableCreate(Hash *node) * working storage. See notes in executor/hashjoin.h. * ---------------- */ - hashtable->hashCxt = AllocSetContextCreate(TransactionCommandContext, + hashtable->hashCxt = AllocSetContextCreate(CurrentMemoryContext, "HashTableContext", ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, |