diff options
author | Neil Conway <neilc@samurai.com> | 2004-05-26 04:41:50 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2004-05-26 04:41:50 +0000 |
commit | d0b4399d81f39decccb23fa38f772b71b51bf96a (patch) | |
tree | 71d3b737f5d93f6c3984412a4910b5810156c5ca /src/backend/executor/spi.c | |
parent | 18d0d105635fbc7e476063e662b449f296953a04 (diff) | |
download | postgresql-d0b4399d81f39decccb23fa38f772b71b51bf96a.tar.gz postgresql-d0b4399d81f39decccb23fa38f772b71b51bf96a.zip |
Reimplement the linked list data structure used throughout the backend.
In the past, we used a 'Lispy' linked list implementation: a "list" was
merely a pointer to the head node of the list. The problem with that
design is that it makes lappend() and length() linear time. This patch
fixes that problem (and others) by maintaining a count of the list
length and a pointer to the tail node along with each head node pointer.
A "list" is now a pointer to a structure containing some meta-data
about the list; the head and tail pointers in that structure refer
to ListCell structures that maintain the actual linked list of nodes.
The function names of the list API have also been changed to, I hope,
be more logically consistent. By default, the old function names are
still available; they will be disabled-by-default once the rest of
the tree has been updated to use the new API names.
Diffstat (limited to 'src/backend/executor/spi.c')
-rw-r--r-- | src/backend/executor/spi.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index bcf7f8d52b6..4d8fade3d64 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.113 2004/04/01 21:28:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.114 2004/05/26 04:41:16 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -744,8 +744,8 @@ SPI_cursor_open(const char *name, void *plan, Datum *Values, const char *Nulls) ereport(ERROR, (errcode(ERRCODE_INVALID_CURSOR_DEFINITION), errmsg("cannot open multi-query plan as cursor"))); - queryTree = (Query *) lfirst((List *) lfirst(qtlist)); - planTree = (Plan *) lfirst(ptlist); + queryTree = (Query *) linitial((List *) linitial(qtlist)); + planTree = (Plan *) linitial(ptlist); if (queryTree->commandType != CMD_SELECT) ereport(ERROR, @@ -953,7 +953,7 @@ SPI_is_cursor_plan(void *plan) qtlist = spiplan->qtlist; if (length(spiplan->ptlist) == 1 && length(qtlist) == 1) { - Query *queryTree = (Query *) lfirst((List *) lfirst(qtlist)); + Query *queryTree = (Query *) linitial((List *) linitial(qtlist)); if (queryTree->commandType == CMD_SELECT && queryTree->into == NULL) return true; @@ -1062,7 +1062,7 @@ _SPI_execute(const char *src, int tcount, _SPI_plan *plan) List *raw_parsetree_list; List *query_list_list; List *plan_list; - List *list_item; + ListCell *list_item; ErrorContextCallback spierrcontext; int nargs = 0; Oid *argtypes = NULL; @@ -1110,7 +1110,7 @@ _SPI_execute(const char *src, int tcount, _SPI_plan *plan) { Node *parsetree = (Node *) lfirst(list_item); List *query_list; - List *query_list_item; + ListCell *query_list_item; query_list = pg_analyze_and_rewrite(parsetree, argtypes, nargs); @@ -1207,8 +1207,8 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls, bool useCurrentSnapshot, int tcount) { List *query_list_list = plan->qtlist; - List *plan_list = plan->ptlist; - List *query_list_list_item; + ListCell *plan_list_item = list_head(plan->ptlist); + ListCell *query_list_list_item; ErrorContextCallback spierrcontext; int nargs = plan->nargs; int res = 0; @@ -1254,7 +1254,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls, foreach(query_list_list_item, query_list_list) { List *query_list = lfirst(query_list_list_item); - List *query_list_item; + ListCell *query_list_item; /* Reset state for each original parsetree */ /* (at most one of its querytrees will be marked canSetTag) */ @@ -1270,8 +1270,8 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls, QueryDesc *qdesc; DestReceiver *dest; - planTree = lfirst(plan_list); - plan_list = lnext(plan_list); + planTree = lfirst(plan_list_item); + plan_list_item = lnext(plan_list_item); dest = CreateDestReceiver(queryTree->canSetTag ? SPI : None, NULL); if (queryTree->commandType == CMD_UTILITY) |