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/rewrite/rewriteManip.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/rewrite/rewriteManip.c')
-rw-r--r-- | src/backend/rewrite/rewriteManip.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/backend/rewrite/rewriteManip.c b/src/backend/rewrite/rewriteManip.c index 45b60715966..4079230c0b1 100644 --- a/src/backend/rewrite/rewriteManip.c +++ b/src/backend/rewrite/rewriteManip.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.82 2004/05/10 22:44:46 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.83 2004/05/26 04:41:33 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -216,7 +216,6 @@ OffsetVarNodes(Node *node, int offset, int sublevels_up) if (node && IsA(node, Query)) { Query *qry = (Query *) node; - List *l; /* * If we are starting at a Query, and sublevels_up is zero, then @@ -227,6 +226,8 @@ OffsetVarNodes(Node *node, int offset, int sublevels_up) */ if (sublevels_up == 0) { + ListCell *l; + if (qry->resultRelation) qry->resultRelation += offset; foreach(l, qry->rowMarks) @@ -356,7 +357,6 @@ ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up) if (node && IsA(node, Query)) { Query *qry = (Query *) node; - List *l; /* * If we are starting at a Query, and sublevels_up is zero, then @@ -367,6 +367,8 @@ ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up) */ if (sublevels_up == 0) { + ListCell *l; + if (qry->resultRelation == rt_index) qry->resultRelation = new_index; foreach(l, qry->rowMarks) @@ -678,7 +680,7 @@ getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr) Assert(parsetree->jointree && IsA(parsetree->jointree, FromExpr)); if (length(parsetree->jointree->fromlist) != 1) elog(ERROR, "expected to find SELECT subquery"); - rtr = (RangeTblRef *) lfirst(parsetree->jointree->fromlist); + rtr = (RangeTblRef *) linitial(parsetree->jointree->fromlist); Assert(IsA(rtr, RangeTblRef)); selectrte = rt_fetch(rtr->rtindex, parsetree->rtable); selectquery = selectrte->subquery; |