diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-15 16:17:59 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-15 16:17:59 +0000 |
commit | 5bab36e9f6c3f3a9e14a89e1124179a339d2c3a1 (patch) | |
tree | a05154b129808efc7882599d96a1132051c2403b /src/backend/optimizer/path/indxpath.c | |
parent | 90b3a0b6fd3bc74804c01156491635e5d95091d9 (diff) |
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/backend/optimizer/path/indxpath.c')
-rw-r--r-- | src/backend/optimizer/path/indxpath.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index e4eedd11790..984c930e3a6 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.128 2002/12/13 19:45:56 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.129 2002/12/15 16:17:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1132,7 +1132,8 @@ pred_test_simple_clause(Expr *predicate, Node *clause) HeapTuple tuple; ScanKeyData entry[1]; Form_pg_amop aform; - ExprContext *econtext; + EState *estate; + MemoryContext oldcontext; /* First try the equal() test */ if (equal((Node *) predicate, clause)) @@ -1267,20 +1268,33 @@ pred_test_simple_clause(Expr *predicate, Node *clause) ReleaseSysCache(tuple); /* - * 5. Evaluate the test + * 5. Evaluate the test. For this we need an EState. */ + estate = CreateExecutorState(); + + /* We can use the estate's working context to avoid memory leaks. */ + oldcontext = MemoryContextSwitchTo(estate->es_query_cxt); + + /* Build expression tree */ test_expr = make_opclause(test_op, BOOLOID, false, (Expr *) clause_const, (Expr *) pred_const); - set_opfuncid((OpExpr *) test_expr); - test_exprstate = ExecInitExpr(test_expr, NULL); - econtext = MakeExprContext(NULL, CurrentMemoryContext); - test_result = ExecEvalExprSwitchContext(test_exprstate, econtext, + /* Prepare it for execution */ + test_exprstate = ExecPrepareExpr(test_expr, estate); + + /* And execute it. */ + test_result = ExecEvalExprSwitchContext(test_exprstate, + GetPerTupleExprContext(estate), &isNull, NULL); - FreeExprContext(econtext); + + /* Get back to outer memory context */ + MemoryContextSwitchTo(oldcontext); + + /* Release all the junk we just created */ + FreeExecutorState(estate); if (isNull) { |