summaryrefslogtreecommitdiff
path: root/src/pl/plpgsql
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-12-15 16:17:59 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-12-15 16:17:59 +0000
commit5bab36e9f6c3f3a9e14a89e1124179a339d2c3a1 (patch)
treea05154b129808efc7882599d96a1132051c2403b /src/pl/plpgsql
parent90b3a0b6fd3bc74804c01156491635e5d95091d9 (diff)
downloadpostgresql-5bab36e9f6c3f3a9e14a89e1124179a339d2c3a1.tar.gz
Revise executor APIs so that all per-query state structure is built in
a per-query memory context created by CreateExecutorState --- and destroyed by FreeExecutorState. This provides a final solution to the longstanding problem of memory leaked by various ExecEndNode calls.
Diffstat (limited to 'src/pl/plpgsql')
-rw-r--r--src/pl/plpgsql/src/pl_exec.c29
-rw-r--r--src/pl/plpgsql/src/plpgsql.h3
2 files changed, 18 insertions, 14 deletions
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index 8908a43a78..a569d9ee9d 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -3,7 +3,7 @@
* procedural language
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.74 2002/12/13 19:46:01 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.75 2002/12/15 16:17:58 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -3227,7 +3227,6 @@ exec_eval_simple_expr(PLpgSQL_execstate * estate,
bool *isNull,
Oid *rettype)
{
- _SPI_plan *spi_plan = (_SPI_plan *) expr->plan;
Datum retval;
PLpgSQL_var *var;
PLpgSQL_rec *rec;
@@ -3242,14 +3241,11 @@ exec_eval_simple_expr(PLpgSQL_execstate * estate,
ParamListInfo paramLI;
/*
- * Create a simple expression context to hold the arguments.
- *
- * NOTE: we pass the SPI plan's context as the query-lifetime context for
- * function cache nodes and suchlike allocations. This is appropriate
- * because that's where the expression tree itself is, and the
- * function cache nodes must live as long as it does.
+ * Create an expression context to hold the arguments and the result
+ * of this expression evaluation. This must be a child of the EState
+ * we created in the SPI plan's context.
*/
- econtext = MakeExprContext(NULL, spi_plan->plancxt);
+ econtext = CreateExprContext(expr->plan_simple_estate);
/*
* Param list can live in econtext's temporary memory context.
@@ -3691,13 +3687,20 @@ exec_simple_check_plan(PLpgSQL_expr * expr)
return;
/*
- * Yes - this is a simple expression. Prepare to execute it, and
- * stash away the result type. Put the expression state tree in the
- * plan context so it will have appropriate lifespan.
+ * Yes - this is a simple expression. Prepare to execute it.
+ * We need an EState and an expression state tree, which we'll put
+ * into the plan context so they will have appropriate lifespan.
*/
oldcontext = MemoryContextSwitchTo(spi_plan->plancxt);
- expr->plan_simple_expr = ExecInitExpr(tle->expr, NULL);
+
+ expr->plan_simple_estate = CreateExecutorState();
+
+ expr->plan_simple_expr = ExecPrepareExpr(tle->expr,
+ expr->plan_simple_estate);
+
MemoryContextSwitchTo(oldcontext);
+
+ /* Also stash away the expression result type */
expr->plan_simple_type = exprType((Node *) tle->expr);
}
diff --git a/src/pl/plpgsql/src/plpgsql.h b/src/pl/plpgsql/src/plpgsql.h
index 945569b6f6..f051c01572 100644
--- a/src/pl/plpgsql/src/plpgsql.h
+++ b/src/pl/plpgsql/src/plpgsql.h
@@ -3,7 +3,7 @@
* procedural language
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.30 2002/12/13 19:46:01 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.31 2002/12/15 16:17:59 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -166,6 +166,7 @@ typedef struct
char *query;
void *plan;
ExprState *plan_simple_expr;
+ EState *plan_simple_estate;
Oid plan_simple_type;
Oid *plan_argtypes;
int nparams;