diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-07-12 02:37:39 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-07-12 02:37:39 +0000 |
commit | badce86a2c327b40c6146242526d1523455d64a6 (patch) | |
tree | 6e0cb658889a2688e76d9ac19a56555c5eb0e738 /src/backend/executor/functions.c | |
parent | 46fb9c29e2990ba470bb741ff6dd60f2ae218e64 (diff) | |
download | postgresql-badce86a2c327b40c6146242526d1523455d64a6.tar.gz postgresql-badce86a2c327b40c6146242526d1523455d64a6.zip |
First stage of reclaiming memory in executor by resetting short-term
memory contexts. Currently, only leaks in expressions executed as
quals or projections are handled. Clean up some old dead cruft in
executor while at it --- unused fields in state nodes, that sort of thing.
Diffstat (limited to 'src/backend/executor/functions.c')
-rw-r--r-- | src/backend/executor/functions.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index 6d8d93a47f1..a92811d0342 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.35 2000/06/28 03:31:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.36 2000/07/12 02:37:03 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -57,20 +57,18 @@ ProjectAttribute(TupleDesc TD, HeapTuple tup, bool *isnullP) { - Datum val, - valueP; + Datum val; Var *attrVar = (Var *) tlist->expr; AttrNumber attrno = attrVar->varattno; val = heap_getattr(tup, attrno, TD, isnullP); + if (*isnullP) - return (Datum) NULL; + return (Datum) 0; - valueP = datumCopy(val, - TD->attrs[attrno - 1]->atttypid, - TD->attrs[attrno - 1]->attbyval, - (Size) TD->attrs[attrno - 1]->attlen); - return valueP; + return datumCopy(val, + TD->attrs[attrno - 1]->attbyval, + TD->attrs[attrno - 1]->attlen); } static execution_state * @@ -351,11 +349,19 @@ postquel_function(FunctionCallInfo fcinfo, List *func_tlist, bool *isDone) { + MemoryContext oldcontext; execution_state *es; Datum result = 0; CommandId savedId; /* + * Switch to context in which the fcache lives. This ensures that + * parsetrees, plans, etc, will have sufficient lifetime. The + * sub-executor is responsible for deleting per-tuple information. + */ + oldcontext = MemoryContextSwitchTo(fcache->fcacheCxt); + + /* * Before we start do anything we must save CurrentScanCommandId to * restore it before return to upper Executor. Also, we have to set * CurrentScanCommandId equal to CurrentCommandId. - vadim 08/29/97 @@ -416,6 +422,7 @@ postquel_function(FunctionCallInfo fcinfo, * Let caller know we're finished. */ *isDone = true; + MemoryContextSwitchTo(oldcontext); return (fcache->oneResult) ? result : (Datum) NULL; } @@ -426,5 +433,8 @@ postquel_function(FunctionCallInfo fcinfo, Assert(LAST_POSTQUEL_COMMAND(es)); *isDone = false; + + MemoryContextSwitchTo(oldcontext); + return result; } |