aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2004-05-26 04:41:50 +0000
committerNeil Conway <neilc@samurai.com>2004-05-26 04:41:50 +0000
commitd0b4399d81f39decccb23fa38f772b71b51bf96a (patch)
tree71d3b737f5d93f6c3984412a4910b5810156c5ca /src/backend/optimizer/util
parent18d0d105635fbc7e476063e662b449f296953a04 (diff)
downloadpostgresql-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/util')
-rw-r--r--src/backend/optimizer/util/clauses.c78
-rw-r--r--src/backend/optimizer/util/joininfo.c8
-rw-r--r--src/backend/optimizer/util/pathnode.c43
-rw-r--r--src/backend/optimizer/util/plancat.c12
-rw-r--r--src/backend/optimizer/util/relnode.c46
-rw-r--r--src/backend/optimizer/util/restrictinfo.c22
-rw-r--r--src/backend/optimizer/util/tlist.c12
-rw-r--r--src/backend/optimizer/util/var.c8
8 files changed, 114 insertions, 115 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index 4dabbf50dac..0727bfb6f2c 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.170 2004/05/10 22:44:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.171 2004/05/26 04:41:27 neilc Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -114,7 +114,7 @@ get_leftop(Expr *clause)
OpExpr *expr = (OpExpr *) clause;
if (expr->args != NIL)
- return lfirst(expr->args);
+ return linitial(expr->args);
else
return NULL;
}
@@ -130,8 +130,8 @@ get_rightop(Expr *clause)
{
OpExpr *expr = (OpExpr *) clause;
- if (expr->args != NIL && lnext(expr->args) != NIL)
- return lfirst(lnext(expr->args));
+ if (list_length(expr->args) >= 2)
+ return lsecond(expr->args);
else
return NULL;
}
@@ -176,7 +176,7 @@ make_notclause(Expr *notclause)
Expr *
get_notclausearg(Expr *notclause)
{
- return lfirst(((BoolExpr *) notclause)->args);
+ return linitial(((BoolExpr *) notclause)->args);
}
/*****************************************************************************
@@ -278,8 +278,8 @@ make_ands_explicit(List *andclauses)
{
if (andclauses == NIL)
return (Expr *) makeBoolConst(true, false);
- else if (lnext(andclauses) == NIL)
- return (Expr *) lfirst(andclauses);
+ else if (length(andclauses) == 1)
+ return (Expr *) linitial(andclauses);
else
return make_andclause(andclauses);
}
@@ -595,7 +595,7 @@ contain_mutable_functions_walker(Node *node, void *context)
if (IsA(node, SubLink))
{
SubLink *sublink = (SubLink *) node;
- List *opid;
+ ListCell *opid;
foreach(opid, sublink->operOids)
{
@@ -678,7 +678,7 @@ contain_volatile_functions_walker(Node *node, void *context)
if (IsA(node, SubLink))
{
SubLink *sublink = (SubLink *) node;
- List *opid;
+ ListCell *opid;
foreach(opid, sublink->operOids)
{
@@ -848,7 +848,7 @@ pull_constant_clauses(List *quals, List **constantQual)
{
FastList constqual,
restqual;
- List *q;
+ ListCell *q;
FastListInit(&constqual);
FastListInit(&restqual);
@@ -882,7 +882,7 @@ pull_constant_clauses(List *quals, List **constantQual)
bool
has_distinct_on_clause(Query *query)
{
- List *targetList;
+ ListCell *l;
/* Is there a DISTINCT clause at all? */
if (query->distinctClause == NIL)
@@ -901,9 +901,9 @@ has_distinct_on_clause(Query *query)
* This code assumes that the DISTINCT list is valid, ie, all its entries
* match some entry of the tlist.
*/
- foreach(targetList, query->targetList)
+ foreach(l, query->targetList)
{
- TargetEntry *tle = (TargetEntry *) lfirst(targetList);
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
if (tle->resdom->ressortgroupref == 0)
{
@@ -998,8 +998,8 @@ CommuteClause(OpExpr *clause)
clause->opfuncid = InvalidOid;
/* opresulttype and opretset are assumed not to change */
- temp = lfirst(clause->args);
- lfirst(clause->args) = lsecond(clause->args);
+ temp = linitial(clause->args);
+ linitial(clause->args) = lsecond(clause->args);
lsecond(clause->args) = temp;
}
@@ -1162,7 +1162,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
{
DistinctExpr *expr = (DistinctExpr *) node;
List *args;
- List *arg;
+ ListCell *arg;
bool has_null_input = false;
bool all_null_input = true;
bool has_nonconst_input = false;
@@ -1281,8 +1281,8 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
if (newargs == NIL)
return makeBoolConst(false, false);
/* If only one nonconst-or-NULL input, it's the result */
- if (lnext(newargs) == NIL)
- return (Node *) lfirst(newargs);
+ if (length(newargs) == 1)
+ return (Node *) linitial(newargs);
/* Else we still need an OR node */
return (Node *) make_orclause(newargs);
}
@@ -1302,16 +1302,16 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
if (newargs == NIL)
return makeBoolConst(true, false);
/* If only one nonconst-or-NULL input, it's the result */
- if (lnext(newargs) == NIL)
- return (Node *) lfirst(newargs);
+ if (length(newargs) == 1)
+ return (Node *) linitial(newargs);
/* Else we still need an AND node */
return (Node *) make_andclause(newargs);
}
case NOT_EXPR:
Assert(length(args) == 1);
- if (IsA(lfirst(args), Const))
+ if (IsA(linitial(args), Const))
{
- Const *const_input = (Const *) lfirst(args);
+ Const *const_input = (Const *) linitial(args);
/* NOT NULL => NULL */
if (const_input->constisnull)
@@ -1320,13 +1320,13 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
return makeBoolConst(!DatumGetBool(const_input->constvalue),
false);
}
- else if (not_clause((Node *) lfirst(args)))
+ else if (not_clause((Node *) linitial(args)))
{
/* Cancel NOT/NOT */
- return (Node *) get_notclausearg((Expr *) lfirst(args));
+ return (Node *) get_notclausearg((Expr *) linitial(args));
}
/* Else we still need a NOT node */
- return (Node *) make_notclause((Expr *) lfirst(args));
+ return (Node *) make_notclause((Expr *) linitial(args));
default:
elog(ERROR, "unrecognized boolop: %d",
(int) expr->boolop);
@@ -1414,7 +1414,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
FastList newargs;
Node *defresult;
Const *const_input;
- List *arg;
+ ListCell *arg;
/* Simplify the test expression, if any */
newarg = eval_const_expressions_mutator((Node *) caseexpr->arg,
@@ -1480,7 +1480,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
ArrayExpr *newarray;
bool all_const = true;
FastList newelems;
- List *element;
+ ListCell *element;
FastListInit(&newelems);
foreach(element, arrayexpr->elements)
@@ -1511,7 +1511,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
CoalesceExpr *newcoalesce;
FastList newargs;
- List *arg;
+ ListCell *arg;
FastListInit(&newargs);
foreach(arg, coalesceexpr->args)
@@ -1614,7 +1614,7 @@ static List *
simplify_or_arguments(List *args, bool *haveNull, bool *forceTrue)
{
List *newargs = NIL;
- List *larg;
+ ListCell *larg;
foreach(larg, args)
{
@@ -1675,7 +1675,7 @@ static List *
simplify_and_arguments(List *args, bool *haveNull, bool *forceFalse)
{
List *newargs = NIL;
- List *larg;
+ ListCell *larg;
foreach(larg, args)
{
@@ -1774,7 +1774,7 @@ evaluate_function(Oid funcid, Oid result_type, List *args,
Form_pg_proc funcform = (Form_pg_proc) GETSTRUCT(func_tuple);
bool has_nonconst_input = false;
bool has_null_input = false;
- List *arg;
+ ListCell *arg;
FuncExpr *newexpr;
/*
@@ -1870,7 +1870,7 @@ inline_function(Oid funcid, Oid result_type, List *args,
Query *querytree;
Node *newexpr;
int *usecounts;
- List *arg;
+ ListCell *arg;
int i;
/*
@@ -1946,13 +1946,13 @@ inline_function(Oid funcid, Oid result_type, List *args,
if (length(raw_parsetree_list) != 1)
goto fail;
- querytree_list = parse_analyze(lfirst(raw_parsetree_list),
+ querytree_list = parse_analyze(linitial(raw_parsetree_list),
argtypes, funcform->pronargs);
if (length(querytree_list) != 1)
goto fail;
- querytree = (Query *) lfirst(querytree_list);
+ querytree = (Query *) linitial(querytree_list);
/*
* The single command must be a simple "SELECT expression".
@@ -1976,7 +1976,7 @@ inline_function(Oid funcid, Oid result_type, List *args,
length(querytree->targetList) != 1)
goto fail;
- newexpr = (Node *) ((TargetEntry *) lfirst(querytree->targetList))->expr;
+ newexpr = (Node *) ((TargetEntry *) linitial(querytree->targetList))->expr;
/*
* If the function has any arguments declared as polymorphic types,
@@ -2330,7 +2330,7 @@ expression_tree_walker(Node *node,
bool (*walker) (),
void *context)
{
- List *temp;
+ ListCell *temp;
/*
* The walker has already visited the current node, and so we need
@@ -2576,7 +2576,7 @@ query_tree_walker(Query *query,
void *context,
int flags)
{
- List *rt;
+ ListCell *rt;
Assert(query != NULL && IsA(query, Query));
@@ -2972,7 +2972,7 @@ expression_tree_mutator(Node *node,
* elements!
*/
FastList resultlist;
- List *temp;
+ ListCell *temp;
FastListInit(&resultlist);
foreach(temp, (List *) node)
@@ -3064,7 +3064,7 @@ query_tree_mutator(Query *query,
int flags)
{
FastList newrt;
- List *rt;
+ ListCell *rt;
Assert(query != NULL && IsA(query, Query));
diff --git a/src/backend/optimizer/util/joininfo.c b/src/backend/optimizer/util/joininfo.c
index 9c207ac96ef..7c082754c30 100644
--- a/src/backend/optimizer/util/joininfo.c
+++ b/src/backend/optimizer/util/joininfo.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/joininfo.c,v 1.37 2003/11/29 19:51:51 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/joininfo.c,v 1.38 2004/05/26 04:41:27 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,11 +29,11 @@
JoinInfo *
find_joininfo_node(RelOptInfo *this_rel, Relids join_relids)
{
- List *i;
+ ListCell *l;
- foreach(i, this_rel->joininfo)
+ foreach(l, this_rel->joininfo)
{
- JoinInfo *joininfo = (JoinInfo *) lfirst(i);
+ JoinInfo *joininfo = (JoinInfo *) lfirst(l);
if (bms_equal(join_relids, joininfo->unjoined_relids))
return joininfo;
diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c
index 619013a18d5..3bad7a4f601 100644
--- a/src/backend/optimizer/util/pathnode.c
+++ b/src/backend/optimizer/util/pathnode.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.104 2004/04/25 18:23:56 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.105 2004/05/26 04:41:27 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -200,7 +200,7 @@ void
set_cheapest(RelOptInfo *parent_rel)
{
List *pathlist = parent_rel->pathlist;
- List *p;
+ ListCell *p;
Path *cheapest_startup_path;
Path *cheapest_total_path;
@@ -209,9 +209,9 @@ set_cheapest(RelOptInfo *parent_rel)
if (pathlist == NIL)
elog(ERROR, "could not devise a query plan for the given query");
- cheapest_startup_path = cheapest_total_path = (Path *) lfirst(pathlist);
+ cheapest_startup_path = cheapest_total_path = (Path *) linitial(pathlist);
- foreach(p, lnext(pathlist))
+ for_each_cell(p, lnext(list_head(pathlist)))
{
Path *path = (Path *) lfirst(p);
int cmp;
@@ -269,17 +269,17 @@ add_path(RelOptInfo *parent_rel, Path *new_path)
{
bool accept_new = true; /* unless we find a superior old
* path */
- List *insert_after = NIL; /* where to insert new item */
- List *p1_prev = NIL;
- List *p1;
+ ListCell *insert_after = NULL; /* where to insert new item */
+ ListCell *p1_prev = NULL;
+ ListCell *p1;
/*
* Loop to check proposed new path against old paths. Note it is
* possible for more than one old path to be tossed out because
* new_path dominates it.
*/
- p1 = parent_rel->pathlist; /* cannot use foreach here */
- while (p1 != NIL)
+ p1 = list_head(parent_rel->pathlist); /* cannot use foreach here */
+ while (p1 != NULL)
{
Path *old_path = (Path *) lfirst(p1);
bool remove_old = false; /* unless new proves superior */
@@ -346,15 +346,14 @@ add_path(RelOptInfo *parent_rel, Path *new_path)
*/
if (remove_old)
{
- List *p1_next = lnext(p1);
-
+ parent_rel->pathlist = list_delete_cell(parent_rel->pathlist,
+ p1, p1_prev);
+ /* Delete the data pointed-to by the deleted cell */
+ pfree(old_path);
if (p1_prev)
- lnext(p1_prev) = p1_next;
+ p1 = lnext(p1_prev);
else
- parent_rel->pathlist = p1_next;
- pfree(old_path);
- pfree(p1); /* this is why we can't use foreach */
- p1 = p1_next;
+ p1 = list_head(parent_rel->pathlist);
}
else
{
@@ -378,7 +377,7 @@ add_path(RelOptInfo *parent_rel, Path *new_path)
{
/* Accept the new path: insert it at proper place in pathlist */
if (insert_after)
- lnext(insert_after) = lcons(new_path, lnext(insert_after));
+ lappend_cell(parent_rel->pathlist, insert_after, new_path);
else
parent_rel->pathlist = lcons(new_path, parent_rel->pathlist);
}
@@ -508,7 +507,7 @@ AppendPath *
create_append_path(RelOptInfo *rel, List *subpaths)
{
AppendPath *pathnode = makeNode(AppendPath);
- List *l;
+ ListCell *l;
pathnode->path.pathtype = T_Append;
pathnode->path.parent = rel;
@@ -522,7 +521,7 @@ create_append_path(RelOptInfo *rel, List *subpaths)
{
Path *subpath = (Path *) lfirst(l);
- if (l == subpaths) /* first node? */
+ if (l == list_head(subpaths)) /* first node? */
pathnode->path.startup_cost = subpath->startup_cost;
pathnode->path.total_cost += subpath->total_cost;
}
@@ -608,7 +607,7 @@ create_unique_path(Query *root, RelOptInfo *rel, Path *subpath)
Path agg_path; /* dummy for result of cost_agg */
MemoryContext oldcontext;
List *sub_targetlist;
- List *l;
+ ListCell *l;
int numCols;
/* Caller made a mistake if subpath isn't cheapest_total */
@@ -783,7 +782,7 @@ is_distinct_query(Query *query)
*/
if (query->groupClause)
{
- List *gl;
+ ListCell *gl;
foreach(gl, query->groupClause)
{
@@ -818,7 +817,7 @@ is_distinct_query(Query *query)
static bool
hash_safe_tlist(List *tlist)
{
- List *tl;
+ ListCell *tl;
foreach(tl, tlist)
{
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 37067dd4d42..55b9a12d8cf 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.91 2004/01/04 00:07:32 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.92 2004/05/26 04:41:27 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -75,14 +75,14 @@ get_relation_info(Oid relationObjectId, RelOptInfo *rel)
if (hasindex)
{
- List *indexoidlist,
- *indexoidscan;
+ List *indexoidlist;
+ ListCell *l;
indexoidlist = RelationGetIndexList(relation);
- foreach(indexoidscan, indexoidlist)
+ foreach(l, indexoidlist)
{
- Oid indexoid = lfirsto(indexoidscan);
+ Oid indexoid = lfirsto(l);
Relation indexRelation;
Form_pg_index index;
IndexOptInfo *info;
@@ -384,7 +384,7 @@ has_subclass(Oid relationId)
bool
has_unique_index(RelOptInfo *rel, AttrNumber attno)
{
- List *ilist;
+ ListCell *ilist;
foreach(ilist, rel->indexlist)
{
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
index d6853ca819d..8969b2d6185 100644
--- a/src/backend/optimizer/util/relnode.c
+++ b/src/backend/optimizer/util/relnode.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.56 2004/04/25 18:23:56 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.57 2004/05/26 04:41:27 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -47,21 +47,21 @@ static void subbuild_joinrel_joinlist(RelOptInfo *joinrel,
void
build_base_rel(Query *root, int relid)
{
- List *rels;
+ ListCell *l;
RelOptInfo *rel;
/* Rel should not exist already */
- foreach(rels, root->base_rel_list)
+ foreach(l, root->base_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
elog(ERROR, "rel already exists");
}
/* It should not exist as an "other" rel, either */
- foreach(rels, root->other_rel_list)
+ foreach(l, root->other_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
elog(ERROR, "rel already exists as \"other\" rel");
}
@@ -82,21 +82,21 @@ build_base_rel(Query *root, int relid)
RelOptInfo *
build_other_rel(Query *root, int relid)
{
- List *rels;
+ ListCell *l;
RelOptInfo *rel;
/* Already made? */
- foreach(rels, root->other_rel_list)
+ foreach(l, root->other_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
return rel;
}
/* It should not exist as a base rel */
- foreach(rels, root->base_rel_list)
+ foreach(l, root->base_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
elog(ERROR, "rel already exists as base rel");
}
@@ -187,19 +187,19 @@ make_base_rel(Query *root, int relid)
RelOptInfo *
find_base_rel(Query *root, int relid)
{
- List *rels;
+ ListCell *l;
RelOptInfo *rel;
- foreach(rels, root->base_rel_list)
+ foreach(l, root->base_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
return rel;
}
- foreach(rels, root->other_rel_list)
+ foreach(l, root->other_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
return rel;
}
@@ -217,11 +217,11 @@ find_base_rel(Query *root, int relid)
RelOptInfo *
find_join_rel(Query *root, Relids relids)
{
- List *joinrels;
+ ListCell *l;
- foreach(joinrels, root->join_rel_list)
+ foreach(l, root->join_rel_list)
{
- RelOptInfo *rel = (RelOptInfo *) lfirst(joinrels);
+ RelOptInfo *rel = (RelOptInfo *) lfirst(l);
if (bms_equal(rel->relids, relids))
return rel;
@@ -363,8 +363,7 @@ static void
build_joinrel_tlist(Query *root, RelOptInfo *joinrel)
{
Relids relids = joinrel->relids;
- List *rels;
- List *vars;
+ ListCell *rels;
FastListInit(&joinrel->reltargetlist);
joinrel->width = 0;
@@ -372,6 +371,7 @@ build_joinrel_tlist(Query *root, RelOptInfo *joinrel)
foreach(rels, root->base_rel_list)
{
RelOptInfo *baserel = (RelOptInfo *) lfirst(rels);
+ ListCell *vars;
if (!bms_is_member(baserel->relid, relids))
continue;
@@ -481,7 +481,7 @@ subbuild_joinrel_restrictlist(RelOptInfo *joinrel,
List *joininfo_list)
{
List *restrictlist = NIL;
- List *xjoininfo;
+ ListCell *xjoininfo;
foreach(xjoininfo, joininfo_list)
{
@@ -515,7 +515,7 @@ static void
subbuild_joinrel_joinlist(RelOptInfo *joinrel,
List *joininfo_list)
{
- List *xjoininfo;
+ ListCell *xjoininfo;
foreach(xjoininfo, joininfo_list)
{
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index ddf965fdf2b..1cb446e44fa 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.26 2004/02/27 21:48:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.27 2004/05/26 04:41:27 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -93,14 +93,14 @@ make_restrictinfo_from_indexclauses(List *indexclauses,
{
List *withris = NIL;
List *withoutris = NIL;
- List *orlist;
+ ListCell *orlist;
/* Empty list probably can't happen, but here's what to do */
if (indexclauses == NIL)
return NIL;
/* If single indexscan, just return the ANDed clauses */
- if (lnext(indexclauses) == NIL)
- return (List *) lfirst(indexclauses);
+ if (length(indexclauses) == 1)
+ return (List *) linitial(indexclauses);
/* Else we need an OR RestrictInfo structure */
foreach(orlist, indexclauses)
{
@@ -206,7 +206,7 @@ make_sub_restrictinfos(Expr *clause, bool is_pushed_down,
if (or_clause((Node *) clause))
{
List *orlist = NIL;
- List *temp;
+ ListCell *temp;
foreach(temp, ((BoolExpr *) clause)->args)
orlist = lappend(orlist,
@@ -218,7 +218,7 @@ make_sub_restrictinfos(Expr *clause, bool is_pushed_down,
else if (and_clause((Node *) clause))
{
List *andlist = NIL;
- List *temp;
+ ListCell *temp;
foreach(temp, ((BoolExpr *) clause)->args)
andlist = lappend(andlist,
@@ -257,7 +257,7 @@ List *
get_actual_clauses(List *restrictinfo_list)
{
List *result = NIL;
- List *temp;
+ ListCell *temp;
foreach(temp, restrictinfo_list)
{
@@ -280,7 +280,7 @@ void
get_actual_join_clauses(List *restrictinfo_list,
List **joinquals, List **otherquals)
{
- List *temp;
+ ListCell *temp;
*joinquals = NIL;
*otherquals = NIL;
@@ -317,7 +317,7 @@ remove_redundant_join_clauses(Query *root, List *restrictinfo_list,
JoinType jointype)
{
List *result = NIL;
- List *item;
+ ListCell *item;
QualCost cost;
/*
@@ -380,7 +380,7 @@ select_nonredundant_join_clauses(Query *root,
JoinType jointype)
{
List *result = NIL;
- List *item;
+ ListCell *item;
foreach(item, restrictinfo_list)
{
@@ -431,7 +431,7 @@ join_clause_is_redundant(Query *root,
List *reference_list,
JoinType jointype)
{
- List *refitem;
+ ListCell *refitem;
/* always consider exact duplicates redundant */
foreach(refitem, reference_list)
diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c
index 2c891c49644..cd8ced1307f 100644
--- a/src/backend/optimizer/util/tlist.c
+++ b/src/backend/optimizer/util/tlist.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.62 2004/01/07 18:56:26 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.63 2004/05/26 04:41:27 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -31,7 +31,7 @@
TargetEntry *
tlistentry_member(Node *node, List *targetlist)
{
- List *temp;
+ ListCell *temp;
foreach(temp, targetlist)
{
@@ -138,11 +138,11 @@ List *
add_to_flat_tlist(List *tlist, List *vars)
{
int next_resdomno = length(tlist) + 1;
- List *v;
+ ListCell *v;
foreach(v, vars)
{
- Var *var = lfirst(v);
+ Var *var = (Var *) lfirst(v);
if (!tlistentry_member((Node *) var, tlist))
{
@@ -173,7 +173,7 @@ get_sortgroupclause_tle(SortClause *sortClause,
List *targetList)
{
Index refnumber = sortClause->tleSortGroupRef;
- List *l;
+ ListCell *l;
foreach(l, targetList)
{
@@ -212,7 +212,7 @@ List *
get_sortgrouplist_exprs(List *sortClauses, List *targetList)
{
List *result = NIL;
- List *l;
+ ListCell *l;
foreach(l, sortClauses)
{
diff --git a/src/backend/optimizer/util/var.c b/src/backend/optimizer/util/var.c
index 47b1fdbf70e..ecdc93ab7f5 100644
--- a/src/backend/optimizer/util/var.c
+++ b/src/backend/optimizer/util/var.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.56 2004/05/10 22:44:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.57 2004/05/26 04:41:27 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -513,9 +513,9 @@ flatten_join_alias_vars_mutator(Node *node,
if (var->varattno == InvalidAttrNumber)
{
/* Must expand whole-row reference */
- RowExpr *rowexpr;
- List *fields = NIL;
- List *l;
+ RowExpr *rowexpr;
+ List *fields = NIL;
+ ListCell *l;
foreach(l, rte->joinaliasvars)
{