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/optimizer/prep/preptlist.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/optimizer/prep/preptlist.c')
-rw-r--r-- | src/backend/optimizer/prep/preptlist.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index 86a14cacd80..89df7bca35a 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.66 2003/11/29 19:51:51 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.67 2004/05/26 04:41:26 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -122,10 +122,13 @@ expand_targetlist(List *tlist, int command_type, Index result_relation, List *range_table) { List *new_tlist = NIL; + ListCell *tlist_item; Relation rel; int attrno, numattrs; + tlist_item = list_head(tlist); + /* * The rewriter should have already ensured that the TLEs are in * correct order; but we have to insert TLEs for any missing @@ -143,15 +146,15 @@ expand_targetlist(List *tlist, int command_type, Form_pg_attribute att_tup = rel->rd_att->attrs[attrno - 1]; TargetEntry *new_tle = NULL; - if (tlist != NIL) + if (tlist_item != NULL) { - TargetEntry *old_tle = (TargetEntry *) lfirst(tlist); + TargetEntry *old_tle = (TargetEntry *) lfirst(tlist_item); Resdom *resdom = old_tle->resdom; if (!resdom->resjunk && resdom->resno == attrno) { new_tle = old_tle; - tlist = lnext(tlist); + tlist_item = lnext(tlist_item); } } @@ -259,9 +262,9 @@ expand_targetlist(List *tlist, int command_type, * an UPDATE in a table with dropped columns, or an inheritance child * table with extra columns.) */ - while (tlist) + while (tlist_item) { - TargetEntry *old_tle = (TargetEntry *) lfirst(tlist); + TargetEntry *old_tle = (TargetEntry *) lfirst(tlist_item); Resdom *resdom = old_tle->resdom; if (!resdom->resjunk) @@ -275,7 +278,7 @@ expand_targetlist(List *tlist, int command_type, } new_tlist = lappend(new_tlist, old_tle); attrno++; - tlist = lnext(tlist); + tlist_item = lnext(tlist_item); } heap_close(rel, AccessShareLock); |