diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-05-13 07:29:22 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-05-13 07:29:22 +0000 |
commit | 507a0a2ab09144f524e3239b7fc201ad1ad1b78e (patch) | |
tree | 77c434943724f627e3c901f06443f02ae57d467b /src/backend/executor | |
parent | f80642137cc0d2dbdaea68b8e439de0d50a5c01f (diff) | |
download | postgresql-507a0a2ab09144f524e3239b7fc201ad1ad1b78e.tar.gz postgresql-507a0a2ab09144f524e3239b7fc201ad1ad1b78e.zip |
Rip out QueryTreeList structure, root and branch. Querytree
lists are now plain old garden-variety Lists, allocated with palloc,
rather than specialized expansible-array data allocated with malloc.
This substantially simplifies their handling and eliminates several
sources of memory leakage.
Several basic types of erroneous queries (syntax error, attempt to
insert a duplicate key into a unique index) now demonstrably leak
zero bytes per query.
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/functions.c | 23 | ||||
-rw-r--r-- | src/backend/executor/spi.c | 78 |
2 files changed, 41 insertions, 60 deletions
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index 1cb57d5651e..f9b729b8386 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.24 1999/02/13 23:15:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.25 1999/05/13 07:28:29 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -97,26 +97,23 @@ init_execution_state(FunctionCachePtr fcache, execution_state *newes; execution_state *nextes; execution_state *preves; - QueryTreeList *queryTree_list; - int i; - List *planTree_list; - int nargs; - - nargs = fcache->nargs; + List *queryTree_list, + *planTree_list, + *qtl_item; + int nargs = fcache->nargs; newes = (execution_state *) palloc(sizeof(execution_state)); nextes = newes; preves = (execution_state *) NULL; + planTree_list = pg_parse_and_plan(fcache->src, fcache->argOidVect, + nargs, &queryTree_list, None, FALSE); - planTree_list = (List *) - pg_parse_and_plan(fcache->src, fcache->argOidVect, nargs, &queryTree_list, None, FALSE); - - for (i = 0; i < queryTree_list->len; i++) + foreach (qtl_item, queryTree_list) { - EState *estate; - Query *queryTree = (Query *) (queryTree_list->qtrees[i]); + Query *queryTree = lfirst(qtl_item); Plan *planTree = lfirst(planTree_list); + EState *estate; if (!nextes) nextes = (execution_state *) palloc(sizeof(execution_state)); diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index d3064128a43..f6e5b8c585e 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -3,7 +3,7 @@ * spi.c * Server Programming Interface * - * $Id: spi.c,v 1.36 1999/03/30 01:37:23 momjian Exp $ + * $Id: spi.c,v 1.37 1999/05/13 07:28:30 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -602,18 +602,18 @@ spi_printtup(HeapTuple tuple, TupleDesc tupdesc, DestReceiver* self) static int _SPI_execute(char *src, int tcount, _SPI_plan *plan) { - QueryTreeList *queryTree_list; + List *queryTree_list; List *planTree_list; + List *queryTree_list_item; List *ptlist; QueryDesc *qdesc; Query *queryTree; Plan *planTree; EState *state; - int qlen; int nargs = 0; Oid *argtypes = NULL; - int res; - int i; + int res = 0; + bool islastquery; /* Increment CommandCounter to see changes made by now */ CommandCounterIncrement(); @@ -628,18 +628,17 @@ _SPI_execute(char *src, int tcount, _SPI_plan *plan) nargs = plan->nargs; argtypes = plan->argtypes; } - ptlist = planTree_list = (List *) + ptlist = planTree_list = pg_parse_and_plan(src, argtypes, nargs, &queryTree_list, None, FALSE); _SPI_current->qtlist = queryTree_list; - qlen = queryTree_list->len; - for (i = 0;; i++) + foreach (queryTree_list_item, queryTree_list) { - queryTree = (Query *) (queryTree_list->qtrees[i]); + queryTree = (Query *) lfirst(queryTree_list_item); planTree = lfirst(planTree_list); - planTree_list = lnext(planTree_list); + islastquery = (planTree_list == NIL); /* assume lists are same len */ if (queryTree->commandType == CMD_UTILITY) { @@ -659,32 +658,32 @@ _SPI_execute(char *src, int tcount, _SPI_plan *plan) if (plan == NULL) { ProcessUtility(queryTree->utilityStmt, None); - if (i < qlen - 1) + if (! islastquery) CommandCounterIncrement(); else return res; } - else if (i >= qlen - 1) + else if (islastquery) break; } else if (plan == NULL) { qdesc = CreateQueryDesc(queryTree, planTree, - (i < qlen - 1) ? None : SPI); + islastquery ? SPI : None); state = CreateExecutorState(); - res = _SPI_pquery(qdesc, state, (i < qlen - 1) ? 0 : tcount); - if (res < 0 || i >= qlen - 1) + res = _SPI_pquery(qdesc, state, islastquery ? tcount : 0); + if (res < 0 || islastquery) return res; CommandCounterIncrement(); } else { qdesc = CreateQueryDesc(queryTree, planTree, - (i < qlen - 1) ? None : SPI); - res = _SPI_pquery(qdesc, NULL, (i < qlen - 1) ? 0 : tcount); + islastquery ? SPI : None); + res = _SPI_pquery(qdesc, NULL, islastquery ? tcount : 0); if (res < 0) return res; - if (i >= qlen - 1) + if (islastquery) break; } } @@ -693,23 +692,22 @@ _SPI_execute(char *src, int tcount, _SPI_plan *plan) plan->ptlist = ptlist; return res; - } static int _SPI_execute_plan(_SPI_plan *plan, Datum *Values, char *Nulls, int tcount) { - QueryTreeList *queryTree_list = plan->qtlist; + List *queryTree_list = plan->qtlist; List *planTree_list = plan->ptlist; + List *queryTree_list_item; QueryDesc *qdesc; Query *queryTree; Plan *planTree; EState *state; int nargs = plan->nargs; - int qlen = queryTree_list->len; - int res; - int i, - k; + int res = 0; + bool islastquery; + int k; /* Increment CommandCounter to see changes made by now */ CommandCounterIncrement(); @@ -719,17 +717,17 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, char *Nulls, int tcount) _SPI_current->tuptable = NULL; _SPI_current->qtlist = NULL; - for (i = 0;; i++) + foreach (queryTree_list_item, queryTree_list) { - queryTree = (Query *) (queryTree_list->qtrees[i]); + queryTree = (Query *) lfirst(queryTree_list_item); planTree = lfirst(planTree_list); - planTree_list = lnext(planTree_list); + islastquery = (planTree_list == NIL); /* assume lists are same len */ if (queryTree->commandType == CMD_UTILITY) { ProcessUtility(queryTree->utilityStmt, None); - if (i < qlen - 1) + if (! islastquery) CommandCounterIncrement(); else return SPI_OK_UTILITY; @@ -737,7 +735,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, char *Nulls, int tcount) else { qdesc = CreateQueryDesc(queryTree, planTree, - (i < qlen - 1) ? None : SPI); + islastquery ? SPI : None); state = CreateExecutorState(); if (nargs > 0) { @@ -756,15 +754,14 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, char *Nulls, int tcount) } else state->es_param_list_info = NULL; - res = _SPI_pquery(qdesc, state, (i < qlen - 1) ? 0 : tcount); - if (res < 0 || i >= qlen - 1) + res = _SPI_pquery(qdesc, state, islastquery ? tcount : 0); + if (res < 0 || islastquery) return res; CommandCounterIncrement(); } } return res; - } static int @@ -955,12 +952,7 @@ _SPI_end_call(bool procmem) */ _SPI_curid--; - if (_SPI_current->qtlist) /* free _SPI_plan allocations */ - { - free(_SPI_current->qtlist->qtrees); - free(_SPI_current->qtlist); - _SPI_current->qtlist = NULL; - } + _SPI_current->qtlist = NULL; if (procmem) /* switch to the procedure memory context */ { /* but free Executor memory before */ @@ -1000,7 +992,6 @@ _SPI_copy_plan(_SPI_plan *plan, int location) { _SPI_plan *newplan; MemoryContext oldcxt = NULL; - int i; if (location == _SPI_CPLAN_PROCXT) oldcxt = MemoryContextSwitchTo((MemoryContext) @@ -1009,14 +1000,7 @@ _SPI_copy_plan(_SPI_plan *plan, int location) oldcxt = MemoryContextSwitchTo(TopMemoryContext); newplan = (_SPI_plan *) palloc(sizeof(_SPI_plan)); - newplan->qtlist = (QueryTreeList *) palloc(sizeof(QueryTreeList)); - newplan->qtlist->len = plan->qtlist->len; - newplan->qtlist->qtrees = (Query **) palloc(plan->qtlist->len * - sizeof(Query *)); - for (i = 0; i < plan->qtlist->len; i++) - newplan->qtlist->qtrees[i] = (Query *) - copyObject(plan->qtlist->qtrees[i]); - + newplan->qtlist = (List *) copyObject(plan->qtlist); newplan->ptlist = (List *) copyObject(plan->ptlist); newplan->nargs = plan->nargs; if (plan->nargs > 0) |