aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer
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
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')
-rw-r--r--src/backend/optimizer/geqo/geqo_eval.c12
-rw-r--r--src/backend/optimizer/path/allpaths.c51
-rw-r--r--src/backend/optimizer/path/clausesel.c14
-rw-r--r--src/backend/optimizer/path/costsize.c12
-rw-r--r--src/backend/optimizer/path/indxpath.c87
-rw-r--r--src/backend/optimizer/path/joinpath.c28
-rw-r--r--src/backend/optimizer/path/joinrels.c56
-rw-r--r--src/backend/optimizer/path/orindxpath.c20
-rw-r--r--src/backend/optimizer/path/pathkeys.c132
-rw-r--r--src/backend/optimizer/path/tidpath.c28
-rw-r--r--src/backend/optimizer/plan/createplan.c103
-rw-r--r--src/backend/optimizer/plan/initsplan.c21
-rw-r--r--src/backend/optimizer/plan/planner.c63
-rw-r--r--src/backend/optimizer/plan/setrefs.c25
-rw-r--r--src/backend/optimizer/plan/subselect.c75
-rw-r--r--src/backend/optimizer/prep/prepjointree.c50
-rw-r--r--src/backend/optimizer/prep/prepqual.c50
-rw-r--r--src/backend/optimizer/prep/preptlist.c17
-rw-r--r--src/backend/optimizer/prep/prepunion.c63
-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
27 files changed, 575 insertions, 561 deletions
diff --git a/src/backend/optimizer/geqo/geqo_eval.c b/src/backend/optimizer/geqo/geqo_eval.c
index ccb095aad03..1642f34b408 100644
--- a/src/backend/optimizer/geqo/geqo_eval.c
+++ b/src/backend/optimizer/geqo/geqo_eval.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.67 2004/01/23 23:54:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.68 2004/05/26 04:41:20 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -238,14 +238,14 @@ static bool
desirable_join(Query *root,
RelOptInfo *outer_rel, RelOptInfo *inner_rel)
{
- List *i;
+ ListCell *l;
/*
* Join if there is an applicable join clause.
*/
- foreach(i, outer_rel->joininfo)
+ foreach(l, outer_rel->joininfo)
{
- JoinInfo *joininfo = (JoinInfo *) lfirst(i);
+ JoinInfo *joininfo = (JoinInfo *) lfirst(l);
if (bms_is_subset(joininfo->unjoined_relids, inner_rel->relids))
return true;
@@ -256,9 +256,9 @@ desirable_join(Query *root,
* needed to improve the odds that we will find a valid solution in
* a case where an IN sub-select has a clauseless join.
*/
- foreach(i, root->in_info_list)
+ foreach(l, root->in_info_list)
{
- InClauseInfo *ininfo = (InClauseInfo *) lfirst(i);
+ InClauseInfo *ininfo = (InClauseInfo *) lfirst(l);
if (bms_is_subset(outer_rel->relids, ininfo->righthand) &&
bms_is_subset(inner_rel->relids, ininfo->righthand))
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 217f06a6b2b..a4bc92b1c3b 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.114 2004/05/10 22:44:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.115 2004/05/26 04:41:21 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -102,11 +102,11 @@ make_one_rel(Query *root)
static void
set_base_rel_pathlists(Query *root)
{
- List *rellist;
+ ListCell *l;
- foreach(rellist, root->base_rel_list)
+ foreach(l, root->base_rel_list)
{
- RelOptInfo *rel = (RelOptInfo *) lfirst(rellist);
+ RelOptInfo *rel = (RelOptInfo *) lfirst(l);
Index rti = rel->relid;
RangeTblEntry *rte;
List *inheritlist;
@@ -212,7 +212,7 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
int parentRTindex = rti;
Oid parentOID = rte->relid;
List *subpaths = NIL;
- List *il;
+ ListCell *il;
/*
* XXX for now, can't handle inherited expansion of FOR UPDATE; can we
@@ -247,8 +247,8 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
Oid childOID;
RelOptInfo *childrel;
List *reltlist;
- List *parentvars;
- List *childvars;
+ ListCell *parentvars;
+ ListCell *childvars;
childrte = rt_fetch(childRTindex, root->rtable);
childOID = childrte->relid;
@@ -300,7 +300,7 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
if (childrel->width > rel->width)
rel->width = childrel->width;
- childvars = FastListValue(&childrel->reltargetlist);
+ childvars = list_head(FastListValue(&childrel->reltargetlist));
foreach(parentvars, FastListValue(&rel->reltargetlist))
{
Var *parentvar = (Var *) lfirst(parentvars);
@@ -366,11 +366,11 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel,
{
/* OK to consider pushing down individual quals */
List *upperrestrictlist = NIL;
- List *lst;
+ ListCell *l;
- foreach(lst, rel->baserestrictinfo)
+ foreach(l, rel->baserestrictinfo)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lst);
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
Node *clause = (Node *) rinfo->clause;
if (qual_is_pushdown_safe(subquery, rti, clause, differentTypes))
@@ -434,7 +434,7 @@ make_fromexpr_rel(Query *root, FromExpr *from)
{
int levels_needed;
List *initial_rels = NIL;
- List *jt;
+ ListCell *jt;
/*
* Count the number of child jointree nodes. This is the depth of the
@@ -464,7 +464,7 @@ make_fromexpr_rel(Query *root, FromExpr *from)
/*
* Single jointree node, so we're done.
*/
- return (RelOptInfo *) lfirst(initial_rels);
+ return (RelOptInfo *) linitial(initial_rels);
}
else
{
@@ -516,7 +516,7 @@ make_one_rel_by_joins(Query *root, int levels_needed, List *initial_rels)
for (lev = 2; lev <= levels_needed; lev++)
{
- List *x;
+ ListCell *x;
/*
* Determine all possible pairs of relations to be joined at this
@@ -548,7 +548,7 @@ make_one_rel_by_joins(Query *root, int levels_needed, List *initial_rels)
elog(ERROR, "failed to build any %d-way joins", levels_needed);
Assert(length(joinitems[levels_needed]) == 1);
- rel = (RelOptInfo *) lfirst(joinitems[levels_needed]);
+ rel = (RelOptInfo *) linitial(joinitems[levels_needed]);
return rel;
}
@@ -660,21 +660,22 @@ static void
compare_tlist_datatypes(List *tlist, List *colTypes,
bool *differentTypes)
{
- List *i;
+ ListCell *l;
+ ListCell *colType = list_head(colTypes);
- foreach(i, tlist)
+ foreach(l, tlist)
{
- TargetEntry *tle = (TargetEntry *) lfirst(i);
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
if (tle->resdom->resjunk)
continue; /* ignore resjunk columns */
- if (colTypes == NIL)
+ if (colType == NULL)
elog(ERROR, "wrong number of tlist entries");
- if (tle->resdom->restype != lfirsto(colTypes))
+ if (tle->resdom->restype != lfirst_oid(colType))
differentTypes[tle->resdom->resno] = true;
- colTypes = lnext(colTypes);
+ colType = lnext(colType);
}
- if (colTypes != NIL)
+ if (colType != NULL)
elog(ERROR, "wrong number of tlist entries");
}
@@ -712,7 +713,7 @@ qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
{
bool safe = true;
List *vars;
- List *vl;
+ ListCell *vl;
Bitmapset *tested = NULL;
/* Refuse subselects (point 1) */
@@ -869,7 +870,7 @@ print_relids(Relids relids)
static void
print_restrictclauses(Query *root, List *clauses)
{
- List *l;
+ ListCell *l;
foreach(l, clauses)
{
@@ -987,7 +988,7 @@ print_path(Query *root, Path *path, int indent)
void
debug_print_rel(Query *root, RelOptInfo *rel)
{
- List *l;
+ ListCell *l;
printf("RELOPTINFO (");
print_relids(rel->relids);
diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c
index 96ce94c8fcb..c8b54bf223a 100644
--- a/src/backend/optimizer/path/clausesel.c
+++ b/src/backend/optimizer/path/clausesel.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.65 2004/05/10 22:44:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.66 2004/05/26 04:41:21 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -98,16 +98,16 @@ clauselist_selectivity(Query *root,
{
Selectivity s1 = 1.0;
RangeQueryClause *rqlist = NULL;
- List *clist;
+ ListCell *l;
/*
* Initial scan over clauses. Anything that doesn't look like a
* potential rangequery clause gets multiplied into s1 and forgotten.
* Anything that does gets inserted into an rqlist entry.
*/
- foreach(clist, clauses)
+ foreach(l, clauses)
{
- Node *clause = (Node *) lfirst(clist);
+ Node *clause = (Node *) lfirst(l);
RestrictInfo *rinfo;
Selectivity s2;
@@ -143,7 +143,7 @@ clauselist_selectivity(Query *root,
(is_pseudo_constant_clause_relids(lsecond(expr->args),
rinfo->right_relids) ||
(varonleft = false,
- is_pseudo_constant_clause_relids(lfirst(expr->args),
+ is_pseudo_constant_clause_relids(linitial(expr->args),
rinfo->left_relids)));
}
else
@@ -151,7 +151,7 @@ clauselist_selectivity(Query *root,
ok = (NumRelids(clause) == 1) &&
(is_pseudo_constant_clause(lsecond(expr->args)) ||
(varonleft = false,
- is_pseudo_constant_clause(lfirst(expr->args))));
+ is_pseudo_constant_clause(linitial(expr->args))));
}
if (ok)
@@ -521,7 +521,7 @@ clause_selectivity(Query *root,
*
* XXX is this too conservative?
*/
- List *arg;
+ ListCell *arg;
s1 = 0.0;
foreach(arg, ((BoolExpr *) clause)->args)
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index 94ce4446fa2..71b879b134a 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -49,7 +49,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.126 2004/04/06 18:46:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.127 2004/05/26 04:41:21 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -920,7 +920,7 @@ cost_mergejoin(MergePath *path, Query *root)
*/
if (mergeclauses)
{
- firstclause = (RestrictInfo *) lfirst(mergeclauses);
+ firstclause = (RestrictInfo *) linitial(mergeclauses);
if (firstclause->left_mergescansel < 0) /* not computed yet? */
mergejoinscansel(root, (Node *) firstclause->clause,
&firstclause->left_mergescansel,
@@ -1069,7 +1069,7 @@ cost_hashjoin(HashPath *path, Query *root)
int numbatches;
Selectivity innerbucketsize;
Selectivity joininfactor;
- List *hcl;
+ ListCell *hcl;
if (!enable_hashjoin)
startup_cost += disable_cost;
@@ -1267,7 +1267,7 @@ cost_hashjoin(HashPath *path, Query *root)
void
cost_qual_eval(QualCost *cost, List *quals)
{
- List *l;
+ ListCell *l;
cost->startup = 0;
cost->per_tuple = 0;
@@ -1444,7 +1444,7 @@ static Selectivity
approx_selectivity(Query *root, List *quals, JoinType jointype)
{
Selectivity total = 1.0;
- List *l;
+ ListCell *l;
foreach(l, quals)
{
@@ -1699,7 +1699,7 @@ static void
set_rel_width(Query *root, RelOptInfo *rel)
{
int32 tuple_width = 0;
- List *tllist;
+ ListCell *tllist;
foreach(tllist, FastListValue(&rel->reltargetlist))
{
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 565e9018daa..7c72b540647 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.158 2004/03/27 00:24:28 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.159 2004/05/26 04:41:21 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -121,7 +121,7 @@ void
create_index_paths(Query *root, RelOptInfo *rel)
{
Relids all_join_outerrelids = NULL;
- List *ilist;
+ ListCell *ilist;
foreach(ilist, rel->indexlist)
{
@@ -250,12 +250,12 @@ group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index)
{
Oid curClass = classes[0];
FastList clausegroup;
- List *i;
+ ListCell *l;
FastListInit(&clausegroup);
- foreach(i, restrictinfo_list)
+ foreach(l, restrictinfo_list)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
if (match_clause_to_indexcol(rel,
index,
@@ -312,7 +312,7 @@ group_clauses_by_indexkey_for_join(Query *root,
Oid curClass = classes[0];
FastList clausegroup;
int numsources;
- List *i;
+ ListCell *l;
FastListInit(&clausegroup);
@@ -324,9 +324,9 @@ group_clauses_by_indexkey_for_join(Query *root,
* of a non-join clause if it appears after a join clause it is
* redundant with.
*/
- foreach(i, rel->baserestrictinfo)
+ foreach(l, rel->baserestrictinfo)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
/* Can't use pushed-down clauses in outer join */
if (isouterjoin && rinfo->is_pushed_down)
@@ -344,11 +344,11 @@ group_clauses_by_indexkey_for_join(Query *root,
numsources = (FastListValue(&clausegroup) != NIL) ? 1 : 0;
/* Look for joinclauses that are usable with given outer_relids */
- foreach(i, rel->joininfo)
+ foreach(l, rel->joininfo)
{
- JoinInfo *joininfo = (JoinInfo *) lfirst(i);
+ JoinInfo *joininfo = (JoinInfo *) lfirst(l);
bool jfoundhere = false;
- List *j;
+ ListCell *j;
if (!bms_is_subset(joininfo->unjoined_relids, outer_relids))
continue;
@@ -448,7 +448,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
{
Oid curClass = classes[0];
FastList clausegroup;
- List *item;
+ ListCell *item;
FastListInit(&clausegroup);
@@ -511,7 +511,6 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
indexcol++;
classes++;
-
} while (!DoneMatchingIndexKeys(classes));
/* if OR clause was not used then forget it, per comments above */
@@ -738,7 +737,7 @@ void
check_partial_indexes(Query *root, RelOptInfo *rel)
{
List *restrictinfo_list = rel->baserestrictinfo;
- List *ilist;
+ ListCell *ilist;
foreach(ilist, rel->indexlist)
{
@@ -772,7 +771,7 @@ check_partial_indexes(Query *root, RelOptInfo *rel)
static bool
pred_test(List *predicate_list, List *restrictinfo_list)
{
- List *pred;
+ ListCell *pred;
/*
* Note: if Postgres tried to optimize queries by forming equivalence
@@ -815,7 +814,7 @@ pred_test(List *predicate_list, List *restrictinfo_list)
static bool
pred_test_restrict_list(Expr *predicate, List *restrictinfo_list)
{
- List *item;
+ ListCell *item;
foreach(item, restrictinfo_list)
{
@@ -839,8 +838,8 @@ pred_test_restrict_list(Expr *predicate, List *restrictinfo_list)
static bool
pred_test_recurse_clause(Expr *predicate, Node *clause)
{
- List *items,
- *item;
+ List *items;
+ ListCell *item;
Assert(clause != NULL);
if (or_clause(clause))
@@ -883,8 +882,8 @@ pred_test_recurse_clause(Expr *predicate, Node *clause)
static bool
pred_test_recurse_pred(Expr *predicate, Node *clause)
{
- List *items,
- *item;
+ List *items;
+ ListCell *item;
Assert(predicate != NULL);
if (or_clause((Node *) predicate))
@@ -1360,13 +1359,13 @@ static Relids
indexable_outerrelids(RelOptInfo *rel, IndexOptInfo *index)
{
Relids outer_relids = NULL;
- List *i;
+ ListCell *l;
- foreach(i, rel->joininfo)
+ foreach(l, rel->joininfo)
{
- JoinInfo *joininfo = (JoinInfo *) lfirst(i);
+ JoinInfo *joininfo = (JoinInfo *) lfirst(l);
bool match_found = false;
- List *j;
+ ListCell *j;
/*
* Examine each joinclause in the JoinInfo node's list to see if
@@ -1433,8 +1432,8 @@ best_inner_indexscan(Query *root, RelOptInfo *rel,
{
Path *cheapest = NULL;
bool isouterjoin;
- List *ilist;
- List *jlist;
+ ListCell *ilist;
+ ListCell *jlist;
InnerIndexscanInfo *info;
MemoryContext oldcontext;
@@ -1538,7 +1537,7 @@ best_inner_indexscan(Query *root, RelOptInfo *rel,
}
}
- if (jlist == NIL) /* failed to find a match? */
+ if (jlist == NULL) /* failed to find a match? */
{
List *clausegroups;
@@ -1676,7 +1675,7 @@ List *
flatten_clausegroups_list(List *clausegroups)
{
List *allclauses = NIL;
- List *l;
+ ListCell *l;
foreach(l, clausegroups)
{
@@ -1697,7 +1696,7 @@ Expr *
make_expr_from_indexclauses(List *indexclauses)
{
List *orclauses = NIL;
- List *orlist;
+ ListCell *orlist;
/* There's no such thing as an indexpath with zero scans */
Assert(indexclauses != NIL);
@@ -1715,7 +1714,7 @@ make_expr_from_indexclauses(List *indexclauses)
if (length(orclauses) > 1)
return make_orclause(orclauses);
else
- return (Expr *) lfirst(orclauses);
+ return (Expr *) linitial(orclauses);
}
@@ -1768,23 +1767,23 @@ match_index_to_operand(Node *operand,
* could be avoided, at the cost of complicating all the callers
* of this routine; doesn't seem worth it.)
*/
- List *indexprs;
+ ListCell *indexpr_item;
int i;
Node *indexkey;
- indexprs = index->indexprs;
+ indexpr_item = list_head(index->indexprs);
for (i = 0; i < indexcol; i++)
{
if (index->indexkeys[i] == 0)
{
- if (indexprs == NIL)
+ if (indexpr_item == NULL)
elog(ERROR, "wrong number of index expressions");
- indexprs = lnext(indexprs);
+ indexpr_item = lnext(indexpr_item);
}
}
- if (indexprs == NIL)
+ if (indexpr_item == NULL)
elog(ERROR, "wrong number of index expressions");
- indexkey = (Node *) lfirst(indexprs);
+ indexkey = (Node *) lfirst(indexpr_item);
/*
* Does it match the operand? Again, strip any relabeling.
@@ -2013,32 +2012,32 @@ List *
expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
{
FastList resultquals;
+ ListCell *clausegroup_item;
Oid *classes = index->classlist;
if (clausegroups == NIL)
return NIL;
FastListInit(&resultquals);
+ clausegroup_item = list_head(clausegroups);
do
{
Oid curClass = classes[0];
- List *i;
+ ListCell *l;
- foreach(i, (List *) lfirst(clausegroups))
+ foreach(l, (List *) lfirst(clausegroup_item))
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
FastConc(&resultquals,
expand_indexqual_condition(rinfo, curClass));
}
- clausegroups = lnext(clausegroups);
-
+ clausegroup_item = lnext(clausegroup_item);
classes++;
+ } while (clausegroup_item != NULL && !DoneMatchingIndexKeys(classes));
- } while (clausegroups != NIL && !DoneMatchingIndexKeys(classes));
-
- Assert(clausegroups == NIL); /* else more groups than indexkeys... */
+ Assert(clausegroup_item == NULL); /* else more groups than indexkeys... */
return FastListValue(&resultquals);
}
diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c
index ac6838d26e0..e854fe03b77 100644
--- a/src/backend/optimizer/path/joinpath.c
+++ b/src/backend/optimizer/path/joinpath.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.86 2004/04/06 18:46:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.87 2004/05/26 04:41:22 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -145,7 +145,7 @@ sort_inner_and_outer(Query *root,
Path *outer_path;
Path *inner_path;
List *all_pathkeys;
- List *i;
+ ListCell *l;
/*
* If we are doing a right or full join, we must use *all* the
@@ -224,9 +224,9 @@ sort_inner_and_outer(Query *root,
mergeclause_list,
outerrel);
- foreach(i, all_pathkeys)
+ foreach(l, all_pathkeys)
{
- List *front_pathkey = lfirst(i);
+ List *front_pathkey = (List *) lfirst(l);
List *cur_pathkeys;
List *cur_mergeclauses;
List *outerkeys;
@@ -234,7 +234,7 @@ sort_inner_and_outer(Query *root,
List *merge_pathkeys;
/* Make a pathkey list with this guy first. */
- if (i != all_pathkeys)
+ if (l != list_head(all_pathkeys))
cur_pathkeys = lcons(front_pathkey,
lremove(front_pathkey,
listCopy(all_pathkeys)));
@@ -338,7 +338,7 @@ match_unsorted_outer(Query *root,
Path *inner_cheapest_total = innerrel->cheapest_total_path;
Path *matpath = NULL;
Path *bestinnerjoin = NULL;
- List *i;
+ ListCell *l;
/*
* Nestloop only supports inner, left, and IN joins. Also, if we are
@@ -402,9 +402,9 @@ match_unsorted_outer(Query *root,
outerrel->relids, jointype);
}
- foreach(i, outerrel->pathlist)
+ foreach(l, outerrel->pathlist)
{
- Path *outerpath = (Path *) lfirst(i);
+ Path *outerpath = (Path *) lfirst(l);
List *merge_pathkeys;
List *mergeclauses;
List *innersortkeys;
@@ -676,7 +676,7 @@ hash_inner_and_outer(Query *root,
{
bool isouterjoin;
List *hashclauses;
- List *i;
+ ListCell *l;
/*
* Hashjoin only supports inner, left, and IN joins.
@@ -704,9 +704,9 @@ hash_inner_and_outer(Query *root,
* are usable with this pair of sub-relations.
*/
hashclauses = NIL;
- foreach(i, restrictlist)
+ foreach(l, restrictlist)
{
- RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(l);
if (!restrictinfo->can_join ||
restrictinfo->hashjoinoperator == InvalidOid)
@@ -803,11 +803,11 @@ select_mergejoin_clauses(RelOptInfo *joinrel,
{
List *result_list = NIL;
bool isouterjoin = IS_OUTER_JOIN(jointype);
- List *i;
+ ListCell *l;
- foreach(i, restrictlist)
+ foreach(l, restrictlist)
{
- RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(l);
/*
* If processing an outer join, only use its own join clauses in
diff --git a/src/backend/optimizer/path/joinrels.c b/src/backend/optimizer/path/joinrels.c
index 07caab48ac6..6debd825c11 100644
--- a/src/backend/optimizer/path/joinrels.c
+++ b/src/backend/optimizer/path/joinrels.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.67 2004/03/08 17:20:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.68 2004/05/26 04:41:22 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -20,10 +20,10 @@
static List *make_rels_by_clause_joins(Query *root,
RelOptInfo *old_rel,
- List *other_rels);
+ ListCell *other_rels);
static List *make_rels_by_clauseless_joins(Query *root,
RelOptInfo *old_rel,
- List *other_rels);
+ ListCell *other_rels);
static bool is_inside_IN(Query *root, RelOptInfo *rel);
@@ -43,8 +43,8 @@ make_rels_by_joins(Query *root, int level, List **joinrels)
{
List *result_rels = NIL;
List *new_rels;
- List *nr;
- List *r;
+ ListCell *nr;
+ ListCell *r;
int k;
/*
@@ -64,13 +64,13 @@ make_rels_by_joins(Query *root, int level, List **joinrels)
foreach(r, joinrels[level - 1])
{
RelOptInfo *old_rel = (RelOptInfo *) lfirst(r);
- List *other_rels;
+ ListCell *other_rels;
if (level == 2)
other_rels = lnext(r); /* only consider remaining initial
* rels */
else
- other_rels = joinrels[1]; /* consider all initial rels */
+ other_rels = list_head(joinrels[1]); /* consider all initial rels */
if (old_rel->joininfo != NIL)
{
@@ -149,8 +149,8 @@ make_rels_by_joins(Query *root, int level, List **joinrels)
foreach(r, joinrels[k])
{
RelOptInfo *old_rel = (RelOptInfo *) lfirst(r);
- List *other_rels;
- List *r2;
+ ListCell *other_rels;
+ ListCell *r2;
if (old_rel->joininfo == NIL)
continue; /* we ignore clauseless joins here */
@@ -158,15 +158,15 @@ make_rels_by_joins(Query *root, int level, List **joinrels)
if (k == other_level)
other_rels = lnext(r); /* only consider remaining rels */
else
- other_rels = joinrels[other_level];
+ other_rels = list_head(joinrels[other_level]);
- foreach(r2, other_rels)
+ for_each_cell(r2, other_rels)
{
RelOptInfo *new_rel = (RelOptInfo *) lfirst(r2);
if (!bms_overlap(old_rel->relids, new_rel->relids))
{
- List *i;
+ ListCell *i;
/*
* OK, we can build a rel of the right level from this
@@ -217,14 +217,14 @@ make_rels_by_joins(Query *root, int level, List **joinrels)
foreach(r, joinrels[level - 1])
{
RelOptInfo *old_rel = (RelOptInfo *) lfirst(r);
- List *other_rels;
+ ListCell *other_rels;
if (level == 2)
other_rels = lnext(r); /* only consider remaining initial
* rels */
else
- other_rels = joinrels[1]; /* consider all initial
- * rels */
+ other_rels = list_head(joinrels[1]); /* consider all initial
+ * rels */
new_rels = make_rels_by_clauseless_joins(root,
old_rel,
@@ -271,7 +271,8 @@ make_rels_by_joins(Query *root, int level, List **joinrels)
* The join rel nodes are returned in a list.
*
* 'old_rel' is the relation entry for the relation to be joined
- * 'other_rels': other rels to be considered for joining
+ * 'other_rels': the first cell in a linked list containing the other
+ * rels to be considered for joining
*
* Currently, this is only used with initial rels in other_rels, but it
* will work for joining to joinrels too, if the caller ensures there is no
@@ -282,10 +283,10 @@ make_rels_by_joins(Query *root, int level, List **joinrels)
static List *
make_rels_by_clause_joins(Query *root,
RelOptInfo *old_rel,
- List *other_rels)
+ ListCell *other_rels)
{
List *result = NIL;
- List *i,
+ ListCell *i,
*j;
foreach(i, old_rel->joininfo)
@@ -293,7 +294,7 @@ make_rels_by_clause_joins(Query *root,
JoinInfo *joininfo = (JoinInfo *) lfirst(i);
Relids unjoined_relids = joininfo->unjoined_relids;
- foreach(j, other_rels)
+ for_each_cell(j, other_rels)
{
RelOptInfo *other_rel = (RelOptInfo *) lfirst(j);
@@ -324,7 +325,8 @@ make_rels_by_clause_joins(Query *root,
* The join rel nodes are returned in a list.
*
* 'old_rel' is the relation entry for the relation to be joined
- * 'other_rels': other rels to be considered for joining
+ * 'other_rels': the first cell of a linked list containing the
+ * other rels to be considered for joining
*
* Currently, this is only used with initial rels in other_rels, but it would
* work for joining to joinrels too.
@@ -332,12 +334,12 @@ make_rels_by_clause_joins(Query *root,
static List *
make_rels_by_clauseless_joins(Query *root,
RelOptInfo *old_rel,
- List *other_rels)
+ ListCell *other_rels)
{
List *result = NIL;
- List *i;
+ ListCell *i;
- foreach(i, other_rels)
+ for_each_cell(i, other_rels)
{
RelOptInfo *other_rel = (RelOptInfo *) lfirst(i);
@@ -370,11 +372,11 @@ make_rels_by_clauseless_joins(Query *root,
static bool
is_inside_IN(Query *root, RelOptInfo *rel)
{
- List *i;
+ ListCell *l;
- foreach(i, root->in_info_list)
+ foreach(l, root->in_info_list)
{
- InClauseInfo *ininfo = (InClauseInfo *) lfirst(i);
+ InClauseInfo *ininfo = (InClauseInfo *) lfirst(l);
if (bms_is_subset(rel->relids, ininfo->righthand))
return true;
@@ -476,7 +478,7 @@ make_join_rel(Query *root, RelOptInfo *rel1, RelOptInfo *rel2,
*/
if (jointype == JOIN_INNER)
{
- List *l;
+ ListCell *l;
foreach(l, root->in_info_list)
{
diff --git a/src/backend/optimizer/path/orindxpath.c b/src/backend/optimizer/path/orindxpath.c
index 9722b69965d..cc160e7a46e 100644
--- a/src/backend/optimizer/path/orindxpath.c
+++ b/src/backend/optimizer/path/orindxpath.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.57 2004/01/05 23:39:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.58 2004/05/26 04:41:22 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -100,7 +100,7 @@ create_or_index_quals(Query *root, RelOptInfo *rel)
RestrictInfo *or_rinfo;
Selectivity or_selec,
orig_selec;
- List *i;
+ ListCell *i;
/*
* We use the best_or_subclause_indexes() machinery to locate the
@@ -111,7 +111,7 @@ create_or_index_quals(Query *root, RelOptInfo *rel)
foreach(i, rel->joininfo)
{
JoinInfo *joininfo = (JoinInfo *) lfirst(i);
- List *j;
+ ListCell *j;
foreach(j, joininfo->jinfo_restrictinfo)
{
@@ -150,7 +150,7 @@ create_or_index_quals(Query *root, RelOptInfo *rel)
newrinfos = make_restrictinfo_from_indexclauses(bestpath->indexclauses,
true, true);
Assert(length(newrinfos) == 1);
- or_rinfo = (RestrictInfo *) lfirst(newrinfos);
+ or_rinfo = (RestrictInfo *) linitial(newrinfos);
rel->baserestrictinfo = nconc(rel->baserestrictinfo, newrinfos);
/*
@@ -190,15 +190,15 @@ create_or_index_quals(Query *root, RelOptInfo *rel)
void
create_or_index_paths(Query *root, RelOptInfo *rel)
{
- List *i;
+ ListCell *l;
/*
* Check each restriction clause to see if it is an OR clause, and if so,
* try to make a path using it.
*/
- foreach(i, rel->baserestrictinfo)
+ foreach(l, rel->baserestrictinfo)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
if (restriction_is_or_clause(rinfo))
{
@@ -248,7 +248,7 @@ best_or_subclause_indexes(Query *root,
FastList quals;
Cost path_startup_cost;
Cost path_total_cost;
- List *slist;
+ ListCell *slist;
IndexPath *pathnode;
FastListInit(&infos);
@@ -283,7 +283,7 @@ best_or_subclause_indexes(Query *root,
*
* Total cost is sum of the per-scan costs.
*/
- if (slist == subclauses) /* first scan? */
+ if (slist == list_head(subclauses)) /* first scan? */
path_startup_cost = best_startup_cost;
path_total_cost += best_total_cost;
}
@@ -351,7 +351,7 @@ best_or_subclause_index(Query *root,
Cost *retTotalCost) /* return value */
{
bool found = false;
- List *ilist;
+ ListCell *ilist;
foreach(ilist, rel->indexlist)
{
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c
index 65eb5cb8a65..af232bd0c98 100644
--- a/src/backend/optimizer/path/pathkeys.c
+++ b/src/backend/optimizer/path/pathkeys.c
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.56 2004/04/07 17:42:28 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.57 2004/05/26 04:41:22 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -95,8 +95,8 @@ add_equijoined_keys(Query *root, RestrictInfo *restrictinfo)
PathKeyItem *item2 = makePathKeyItem(get_rightop(clause),
restrictinfo->right_sortop,
false);
- List *newset,
- *cursetlink;
+ List *newset;
+ ListCell *cursetlink;
/* We might see a clause X=X; don't make a single-element list from it */
if (equal(item1, item2))
@@ -122,10 +122,10 @@ add_equijoined_keys(Query *root, RestrictInfo *restrictinfo)
newset = NIL;
/* cannot use foreach here because of possible lremove */
- cursetlink = root->equi_key_list;
+ cursetlink = list_head(root->equi_key_list);
while (cursetlink)
{
- List *curset = lfirst(cursetlink);
+ List *curset = (List *) lfirst(cursetlink);
bool item1here = member(item1, curset);
bool item2here = member(item2, curset);
@@ -199,15 +199,15 @@ add_equijoined_keys(Query *root, RestrictInfo *restrictinfo)
void
generate_implied_equalities(Query *root)
{
- List *cursetlink;
+ ListCell *cursetlink;
foreach(cursetlink, root->equi_key_list)
{
- List *curset = lfirst(cursetlink);
+ List *curset = (List *) lfirst(cursetlink);
int nitems = length(curset);
Relids *relids;
bool have_consts;
- List *ptr1;
+ ListCell *ptr1;
int i1;
/*
@@ -245,10 +245,10 @@ generate_implied_equalities(Query *root)
{
PathKeyItem *item1 = (PathKeyItem *) lfirst(ptr1);
bool i1_is_variable = !bms_is_empty(relids[i1]);
- List *ptr2;
+ ListCell *ptr2;
int i2 = i1 + 1;
- foreach(ptr2, lnext(ptr1))
+ for_each_cell(ptr2, lnext(ptr1))
{
PathKeyItem *item2 = (PathKeyItem *) lfirst(ptr2);
bool i2_is_variable = !bms_is_empty(relids[i2]);
@@ -294,14 +294,14 @@ generate_implied_equalities(Query *root)
bool
exprs_known_equal(Query *root, Node *item1, Node *item2)
{
- List *cursetlink;
+ ListCell *cursetlink;
foreach(cursetlink, root->equi_key_list)
{
- List *curset = lfirst(cursetlink);
+ List *curset = (List *) lfirst(cursetlink);
bool item1member = false;
bool item2member = false;
- List *ptr;
+ ListCell *ptr;
foreach(ptr, curset)
{
@@ -334,12 +334,12 @@ exprs_known_equal(Query *root, Node *item1, Node *item2)
static List *
make_canonical_pathkey(Query *root, PathKeyItem *item)
{
- List *cursetlink;
List *newset;
+ ListCell *cursetlink;
foreach(cursetlink, root->equi_key_list)
{
- List *curset = lfirst(cursetlink);
+ List *curset = (List *) lfirst(cursetlink);
if (member(item, curset))
return curset;
@@ -360,11 +360,11 @@ List *
canonicalize_pathkeys(Query *root, List *pathkeys)
{
List *new_pathkeys = NIL;
- List *i;
+ ListCell *l;
- foreach(i, pathkeys)
+ foreach(l, pathkeys)
{
- List *pathkey = (List *) lfirst(i);
+ List *pathkey = (List *) lfirst(l);
PathKeyItem *item;
List *cpathkey;
@@ -374,7 +374,7 @@ canonicalize_pathkeys(Query *root, List *pathkeys)
* set by definition.
*/
Assert(pathkey != NIL);
- item = (PathKeyItem *) lfirst(pathkey);
+ item = (PathKeyItem *) linitial(pathkey);
cpathkey = make_canonical_pathkey(root, item);
/*
@@ -402,11 +402,11 @@ canonicalize_pathkeys(Query *root, List *pathkeys)
static int
count_canonical_peers(Query *root, PathKeyItem *item)
{
- List *cursetlink;
+ ListCell *cursetlink;
foreach(cursetlink, root->equi_key_list)
{
- List *curset = lfirst(cursetlink);
+ List *curset = (List *) lfirst(cursetlink);
if (member(item, curset))
return length(curset) - 1;
@@ -430,15 +430,13 @@ count_canonical_peers(Query *root, PathKeyItem *item)
PathKeysComparison
compare_pathkeys(List *keys1, List *keys2)
{
- List *key1,
+ ListCell *key1,
*key2;
- for (key1 = keys1, key2 = keys2;
- key1 != NIL && key2 != NIL;
- key1 = lnext(key1), key2 = lnext(key2))
+ forboth(key1, keys1, key2, keys2)
{
- List *subkey1 = lfirst(key1);
- List *subkey2 = lfirst(key2);
+ List *subkey1 = (List *) lfirst(key1);
+ List *subkey2 = (List *) lfirst(key2);
/*
* XXX would like to check that we've been given canonicalized
@@ -465,9 +463,9 @@ compare_pathkeys(List *keys1, List *keys2)
* the other list are not NIL --- no pathkey list should ever have a
* NIL sublist.)
*/
- if (key1 == NIL && key2 == NIL)
+ if (key1 == NULL && key2 == NULL)
return PATHKEYS_EQUAL;
- if (key1 != NIL)
+ if (key1 != NULL)
return PATHKEYS_BETTER1; /* key1 is longer */
return PATHKEYS_BETTER2; /* key2 is longer */
}
@@ -493,15 +491,13 @@ compare_pathkeys(List *keys1, List *keys2)
PathKeysComparison
compare_noncanonical_pathkeys(List *keys1, List *keys2)
{
- List *key1,
+ ListCell *key1,
*key2;
- for (key1 = keys1, key2 = keys2;
- key1 != NIL && key2 != NIL;
- key1 = lnext(key1), key2 = lnext(key2))
+ forboth(key1, keys1, key2, keys2)
{
- List *subkey1 = lfirst(key1);
- List *subkey2 = lfirst(key2);
+ List *subkey1 = (List *) lfirst(key1);
+ List *subkey2 = (List *) lfirst(key2);
Assert(length(subkey1) == 1);
Assert(length(subkey2) == 1);
@@ -515,9 +511,9 @@ compare_noncanonical_pathkeys(List *keys1, List *keys2)
* the other list are not NIL --- no pathkey list should ever have a
* NIL sublist.)
*/
- if (key1 == NIL && key2 == NIL)
+ if (key1 == NULL && key2 == NULL)
return PATHKEYS_EQUAL;
- if (key1 != NIL)
+ if (key1 != NULL)
return PATHKEYS_BETTER1; /* key1 is longer */
return PATHKEYS_BETTER2; /* key2 is longer */
}
@@ -573,11 +569,11 @@ get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
CostSelector cost_criterion)
{
Path *matched_path = NULL;
- List *i;
+ ListCell *l;
- foreach(i, paths)
+ foreach(l, paths)
{
- Path *path = (Path *) lfirst(i);
+ Path *path = (Path *) lfirst(l);
/*
* Since cost comparison is a lot cheaper than pathkey comparison,
@@ -612,11 +608,11 @@ get_cheapest_fractional_path_for_pathkeys(List *paths,
double fraction)
{
Path *matched_path = NULL;
- List *i;
+ ListCell *l;
- foreach(i, paths)
+ foreach(l, paths)
{
- Path *path = (Path *) lfirst(i);
+ Path *path = (Path *) lfirst(l);
/*
* Since cost comparison is a lot cheaper than pathkey comparison,
@@ -658,7 +654,7 @@ build_index_pathkeys(Query *root,
List *retval = NIL;
int *indexkeys = index->indexkeys;
Oid *ordering = index->ordering;
- List *indexprs = index->indexprs;
+ ListCell *indexprs_item = list_head(index->indexprs);
while (*ordering != InvalidOid)
{
@@ -683,10 +679,10 @@ build_index_pathkeys(Query *root,
else
{
/* expression --- assume we need not copy it */
- if (indexprs == NIL)
+ if (indexprs_item == NULL)
elog(ERROR, "wrong number of index expressions");
- indexkey = (Node *) lfirst(indexprs);
- indexprs = lnext(indexprs);
+ indexkey = (Node *) lfirst(indexprs_item);
+ indexprs_item = lnext(indexprs_item);
}
/* OK, make a sublist for this sort key */
@@ -719,7 +715,7 @@ build_index_pathkeys(Query *root,
static Var *
find_indexkey_var(Query *root, RelOptInfo *rel, AttrNumber varattno)
{
- List *temp;
+ ListCell *temp;
Index relid;
Oid reloid,
vartypeid;
@@ -758,12 +754,12 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
int retvallen = 0;
int outer_query_keys = length(root->query_pathkeys);
List *sub_tlist = rel->subplan->targetlist;
- List *l;
+ ListCell *i;
- foreach(l, subquery->query_pathkeys)
+ foreach(i, subquery->query_pathkeys)
{
- List *sub_pathkey = (List *) lfirst(l);
- List *j;
+ List *sub_pathkey = (List *) lfirst(i);
+ ListCell *j;
PathKeyItem *best_item = NULL;
int best_score = 0;
List *cpathkey;
@@ -788,7 +784,7 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
{
PathKeyItem *sub_item = (PathKeyItem *) lfirst(j);
Node *sub_key = sub_item->key;
- List *k;
+ ListCell *k;
foreach(k, sub_tlist)
{
@@ -908,11 +904,11 @@ make_pathkeys_for_sortclauses(List *sortclauses,
List *tlist)
{
List *pathkeys = NIL;
- List *i;
+ ListCell *l;
- foreach(i, sortclauses)
+ foreach(l, sortclauses)
{
- SortClause *sortcl = (SortClause *) lfirst(i);
+ SortClause *sortcl = (SortClause *) lfirst(l);
Node *sortkey;
PathKeyItem *pathkey;
@@ -1000,21 +996,21 @@ find_mergeclauses_for_pathkeys(Query *root,
List *restrictinfos)
{
List *mergeclauses = NIL;
- List *i;
+ ListCell *i;
/* make sure we have pathkeys cached in the clauses */
foreach(i, restrictinfos)
{
- RestrictInfo *restrictinfo = lfirst(i);
+ RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(i);
cache_mergeclause_pathkeys(root, restrictinfo);
}
foreach(i, pathkeys)
{
- List *pathkey = lfirst(i);
+ List *pathkey = (List *) lfirst(i);
List *matched_restrictinfos = NIL;
- List *j;
+ ListCell *j;
/*
* We can match a pathkey against either left or right side of any
@@ -1037,7 +1033,7 @@ find_mergeclauses_for_pathkeys(Query *root,
*/
foreach(j, restrictinfos)
{
- RestrictInfo *restrictinfo = lfirst(j);
+ RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(j);
/*
* We can compare canonical pathkey sublists by simple pointer
@@ -1093,11 +1089,11 @@ make_pathkeys_for_mergeclauses(Query *root,
RelOptInfo *rel)
{
List *pathkeys = NIL;
- List *i;
+ ListCell *l;
- foreach(i, mergeclauses)
+ foreach(l, mergeclauses)
{
- RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(l);
List *pathkey;
cache_mergeclause_pathkeys(root, restrictinfo);
@@ -1160,18 +1156,18 @@ int
pathkeys_useful_for_merging(Query *root, RelOptInfo *rel, List *pathkeys)
{
int useful = 0;
- List *i;
+ ListCell *i;
foreach(i, pathkeys)
{
- List *pathkey = lfirst(i);
+ List *pathkey = (List *) lfirst(i);
bool matched = false;
- List *j;
+ ListCell *j;
foreach(j, rel->joininfo)
{
JoinInfo *joininfo = (JoinInfo *) lfirst(j);
- List *k;
+ ListCell *k;
foreach(k, joininfo->jinfo_restrictinfo)
{
diff --git a/src/backend/optimizer/path/tidpath.c b/src/backend/optimizer/path/tidpath.c
index 1baccc1b387..dcb6566db04 100644
--- a/src/backend/optimizer/path/tidpath.c
+++ b/src/backend/optimizer/path/tidpath.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/tidpath.c,v 1.18 2003/11/29 19:51:50 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/tidpath.c,v 1.19 2004/05/26 04:41:22 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -33,7 +33,7 @@ static List *TidqualFromExpr(int varno, Expr *expr);
static bool
isEvaluable(int varno, Node *node)
{
- List *lst;
+ ListCell *l;
FuncExpr *expr;
if (IsA(node, Const))
@@ -51,9 +51,9 @@ isEvaluable(int varno, Node *node)
if (!is_funcclause(node))
return false;
expr = (FuncExpr *) node;
- foreach(lst, expr->args)
+ foreach(l, expr->args)
{
- if (!isEvaluable(varno, lfirst(lst)))
+ if (!isEvaluable(varno, lfirst(l)))
return false;
}
@@ -81,7 +81,7 @@ TidequalClause(int varno, OpExpr *node)
return rnode;
if (length(node->args) != 2)
return rnode;
- arg1 = lfirst(node->args);
+ arg1 = linitial(node->args);
arg2 = lsecond(node->args);
arg = NULL;
@@ -156,8 +156,8 @@ static List *
TidqualFromExpr(int varno, Expr *expr)
{
List *rlst = NIL,
- *lst,
*frtn;
+ ListCell *l;
Node *node = (Node *) expr,
*rnode;
@@ -169,9 +169,9 @@ TidqualFromExpr(int varno, Expr *expr)
}
else if (and_clause(node))
{
- foreach(lst, ((BoolExpr *) expr)->args)
+ foreach(l, ((BoolExpr *) expr)->args)
{
- node = lfirst(lst);
+ node = (Node *) lfirst(l);
rlst = TidqualFromExpr(varno, (Expr *) node);
if (rlst)
break;
@@ -179,9 +179,9 @@ TidqualFromExpr(int varno, Expr *expr)
}
else if (or_clause(node))
{
- foreach(lst, ((BoolExpr *) expr)->args)
+ foreach(l, ((BoolExpr *) expr)->args)
{
- node = lfirst(lst);
+ node = (Node *) lfirst(l);
frtn = TidqualFromExpr(varno, (Expr *) node);
if (frtn)
rlst = nconc(rlst, frtn);
@@ -200,8 +200,8 @@ TidqualFromExpr(int varno, Expr *expr)
static List *
TidqualFromRestrictinfo(Relids relids, List *restrictinfo)
{
- List *lst,
- *rlst = NIL;
+ ListCell *l;
+ List *rlst = NIL;
int varno;
Node *node;
Expr *expr;
@@ -209,9 +209,9 @@ TidqualFromRestrictinfo(Relids relids, List *restrictinfo)
if (bms_membership(relids) != BMS_SINGLETON)
return NIL;
varno = bms_singleton_member(relids);
- foreach(lst, restrictinfo)
+ foreach(l, restrictinfo)
{
- node = lfirst(lst);
+ node = (Node *) lfirst(l);
if (!IsA(node, RestrictInfo))
continue;
expr = ((RestrictInfo *) node)->clause;
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 1b4c9d47809..efa7dd77122 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.169 2004/04/25 18:23:56 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.170 2004/05/26 04:41:24 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -263,7 +263,7 @@ build_relation_tlist(RelOptInfo *rel)
{
FastList tlist;
int resdomno = 1;
- List *v;
+ ListCell *v;
FastListInit(&tlist);
foreach(v, FastListValue(&rel->reltargetlist))
@@ -415,7 +415,7 @@ create_append_plan(Query *root, AppendPath *best_path)
Append *plan;
List *tlist = build_relation_tlist(best_path->path.parent);
List *subplans = NIL;
- List *subpaths;
+ ListCell *subpaths;
foreach(subpaths, best_path->subpaths)
{
@@ -505,7 +505,7 @@ create_unique_plan(Query *root, UniquePath *best_path)
List *newtlist;
int nextresno;
bool newitems;
- List *l;
+ ListCell *l;
subplan = create_plan(root, best_path->subpath);
@@ -544,7 +544,7 @@ create_unique_plan(Query *root, UniquePath *best_path)
break;
}
}
- if (l == NIL) /* fell out of loop? */
+ if (l == NULL) /* fell out of loop? */
elog(ERROR, "could not find UniquePath in in_info_list");
/* set up to record positions of unique columns */
@@ -702,7 +702,7 @@ create_indexscan_plan(Query *root,
List *indxsubtype;
List *indxlossy;
FastList indexids;
- List *i;
+ ListCell *l;
IndexScan *scan_plan;
/* it should be a base rel... */
@@ -727,7 +727,7 @@ create_indexscan_plan(Query *root,
*/
Assert(length(best_path->indexclauses) == 1);
scan_clauses = set_ptrUnion(scan_clauses,
- (List *) lfirst(best_path->indexclauses));
+ (List *) linitial(best_path->indexclauses));
}
/* Reduce RestrictInfo list to bare expressions */
@@ -738,9 +738,9 @@ create_indexscan_plan(Query *root,
/* Build list of index OIDs */
FastListInit(&indexids);
- foreach(i, best_path->indexinfo)
+ foreach(l, best_path->indexinfo)
{
- IndexOptInfo *index = (IndexOptInfo *) lfirst(i);
+ IndexOptInfo *index = (IndexOptInfo *) lfirst(l);
FastAppendo(&indexids, index->indexoid);
}
@@ -750,9 +750,9 @@ create_indexscan_plan(Query *root,
* executor as indxqualorig
*/
stripped_indxquals = NIL;
- foreach(i, indxquals)
+ foreach(l, indxquals)
{
- List *andlist = (List *) lfirst(i);
+ List *andlist = (List *) lfirst(l);
stripped_indxquals = lappend(stripped_indxquals,
get_actual_clauses(andlist));
@@ -785,7 +785,7 @@ create_indexscan_plan(Query *root,
* behavior.
*/
Assert(stripped_indxquals != NIL);
- qpqual = set_difference(scan_clauses, lfirst(stripped_indxquals));
+ qpqual = set_difference(scan_clauses, linitial(stripped_indxquals));
}
/*
@@ -955,7 +955,7 @@ create_nestloop_plan(Query *root,
joinrestrictclauses =
select_nonredundant_join_clauses(root,
joinrestrictclauses,
- lfirst(indexclauses),
+ linitial(indexclauses),
best_path->jointype);
}
}
@@ -1182,17 +1182,17 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path,
{
Relids baserelids = index_path->path.parent->relids;
int baserelid = index_path->path.parent->relid;
- List *ixinfo = index_path->indexinfo;
- List *i;
+ List *index_info = index_path->indexinfo;
+ ListCell *iq, *ii;
*fixed_indexquals = NIL;
*indxstrategy = NIL;
*indxsubtype = NIL;
*indxlossy = NIL;
- foreach(i, indexquals)
+ forboth(iq, indexquals, ii, index_info)
{
- List *indexqual = lfirst(i);
- IndexOptInfo *index = (IndexOptInfo *) lfirst(ixinfo);
+ List *indexqual = (List *) lfirst(iq);
+ IndexOptInfo *index = (IndexOptInfo *) lfirst(ii);
List *fixed_qual;
List *strategy;
List *subtype;
@@ -1204,8 +1204,6 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path,
*indxstrategy = lappend(*indxstrategy, strategy);
*indxsubtype = lappend(*indxsubtype, subtype);
*indxlossy = lappend(*indxlossy, lossy);
-
- ixinfo = lnext(ixinfo);
}
}
@@ -1232,15 +1230,15 @@ fix_indxqual_sublist(List *indexqual,
List **subtype,
List **lossy)
{
- List *i;
+ ListCell *l;
*fixed_quals = NIL;
*strategy = NIL;
*subtype = NIL;
*lossy = NIL;
- foreach(i, indexqual)
+ foreach(l, indexqual)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
OpExpr *clause;
OpExpr *newclause;
Oid opclass;
@@ -1250,8 +1248,7 @@ fix_indxqual_sublist(List *indexqual,
Assert(IsA(rinfo, RestrictInfo));
clause = (OpExpr *) rinfo->clause;
- if (!IsA(clause, OpExpr) ||
- length(clause->args) != 2)
+ if (!IsA(clause, OpExpr) || length(clause->args) != 2)
elog(ERROR, "indexqual clause is not binary opclause");
/*
@@ -1275,7 +1272,7 @@ fix_indxqual_sublist(List *indexqual,
* Now, determine which index attribute this is, change the
* indexkey operand as needed, and get the index opclass.
*/
- lfirst(newclause->args) = fix_indxqual_operand(lfirst(newclause->args),
+ linitial(newclause->args) = fix_indxqual_operand(linitial(newclause->args),
baserelid,
index,
&opclass);
@@ -1309,7 +1306,7 @@ fix_indxqual_operand(Node *node, int baserelid, IndexOptInfo *index,
*/
Var *result;
int pos;
- List *indexprs;
+ ListCell *indexpr_item;
/*
* Remove any binary-compatible relabeling of the indexkey
@@ -1340,29 +1337,29 @@ fix_indxqual_operand(Node *node, int baserelid, IndexOptInfo *index,
}
/* Try to match against index expressions */
- indexprs = index->indexprs;
+ indexpr_item = list_head(index->indexprs);
for (pos = 0; pos < index->ncolumns; pos++)
{
if (index->indexkeys[pos] == 0)
{
Node *indexkey;
- if (indexprs == NIL)
+ if (indexpr_item == NULL)
elog(ERROR, "too few entries in indexprs list");
- indexkey = (Node *) lfirst(indexprs);
+ indexkey = (Node *) lfirst(indexpr_item);
if (indexkey && IsA(indexkey, RelabelType))
indexkey = (Node *) ((RelabelType *) indexkey)->arg;
if (equal(node, indexkey))
{
/* Found a match */
result = makeVar(baserelid, pos + 1,
- exprType(lfirst(indexprs)), -1,
+ exprType(lfirst(indexpr_item)), -1,
0);
/* return the correct opclass, too */
*opclass = index->classlist[pos];
return (Node *) result;
}
- indexprs = lnext(indexprs);
+ indexpr_item = lnext(indexpr_item);
}
}
@@ -1383,11 +1380,11 @@ static List *
get_switched_clauses(List *clauses, Relids outerrelids)
{
List *t_list = NIL;
- List *i;
+ ListCell *l;
- foreach(i, clauses)
+ foreach(l, clauses)
{
- RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(i);
+ RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(l);
OpExpr *clause = (OpExpr *) restrictinfo->clause;
Assert(is_opclause(clause));
@@ -1432,7 +1429,7 @@ order_qual_clauses(Query *root, List *clauses)
{
FastList nosubplans;
FastList withsubplans;
- List *l;
+ ListCell *l;
/* No need to work hard if the query is subselect-free */
if (!root->hasSubLinks)
@@ -1442,7 +1439,7 @@ order_qual_clauses(Query *root, List *clauses)
FastListInit(&withsubplans);
foreach(l, clauses)
{
- Node *clause = lfirst(l);
+ Node *clause = (Node *) lfirst(l);
if (contain_subplans(clause))
FastAppend(&withsubplans, clause);
@@ -1632,7 +1629,7 @@ make_append(List *appendplans, bool isTarget, List *tlist)
{
Append *node = makeNode(Append);
Plan *plan = &node->plan;
- List *subnode;
+ ListCell *subnode;
/*
* Compute cost as sum of subplan costs. We charge nothing extra for
@@ -1647,7 +1644,7 @@ make_append(List *appendplans, bool isTarget, List *tlist)
{
Plan *subplan = (Plan *) lfirst(subnode);
- if (subnode == appendplans) /* first node? */
+ if (subnode == list_head(appendplans)) /* first node? */
plan->startup_cost = subplan->startup_cost;
plan->total_cost += subplan->total_cost;
plan->plan_rows += subplan->plan_rows;
@@ -1837,7 +1834,7 @@ static Sort *
make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys)
{
List *tlist = lefttree->targetlist;
- List *i;
+ ListCell *i;
int numsortkeys;
AttrNumber *sortColIdx;
Oid *sortOperators;
@@ -1854,7 +1851,7 @@ make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys)
List *keysublist = (List *) lfirst(i);
PathKeyItem *pathkey = NULL;
Resdom *resdom = NULL;
- List *j;
+ ListCell *j;
/*
* We can sort by any one of the sort key items listed in this
@@ -1870,7 +1867,7 @@ make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys)
*/
foreach(j, keysublist)
{
- pathkey = lfirst(j);
+ pathkey = (PathKeyItem *) lfirst(j);
Assert(IsA(pathkey, PathKeyItem));
resdom = tlist_member(pathkey->key, tlist);
if (resdom)
@@ -1881,10 +1878,10 @@ make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys)
/* No matching Var; look for a computable expression */
foreach(j, keysublist)
{
- List *exprvars;
- List *k;
+ List *exprvars;
+ ListCell *k;
- pathkey = lfirst(j);
+ pathkey = (PathKeyItem *) lfirst(j);
exprvars = pull_var_clause(pathkey->key, false);
foreach(k, exprvars)
{
@@ -1948,7 +1945,7 @@ Sort *
make_sort_from_sortclauses(Query *root, List *sortcls, Plan *lefttree)
{
List *sub_tlist = lefttree->targetlist;
- List *i;
+ ListCell *l;
int numsortkeys;
AttrNumber *sortColIdx;
Oid *sortOperators;
@@ -1960,9 +1957,9 @@ make_sort_from_sortclauses(Query *root, List *sortcls, Plan *lefttree)
numsortkeys = 0;
- foreach(i, sortcls)
+ foreach(l, sortcls)
{
- SortClause *sortcl = (SortClause *) lfirst(i);
+ SortClause *sortcl = (SortClause *) lfirst(l);
TargetEntry *tle = get_sortgroupclause_tle(sortcl, sub_tlist);
/*
@@ -2001,7 +1998,7 @@ make_sort_from_groupcols(Query *root,
{
List *sub_tlist = lefttree->targetlist;
int grpno = 0;
- List *i;
+ ListCell *l;
int numsortkeys;
AttrNumber *sortColIdx;
Oid *sortOperators;
@@ -2013,9 +2010,9 @@ make_sort_from_groupcols(Query *root,
numsortkeys = 0;
- foreach(i, groupcls)
+ foreach(l, groupcls)
{
- GroupClause *grpcl = (GroupClause *) lfirst(i);
+ GroupClause *grpcl = (GroupClause *) lfirst(l);
TargetEntry *tle = get_tle_by_resno(sub_tlist, grpColIdx[grpno]);
/*
@@ -2213,7 +2210,7 @@ make_unique(Plan *lefttree, List *distinctList)
int numCols = length(distinctList);
int keyno = 0;
AttrNumber *uniqColIdx;
- List *slitem;
+ ListCell *slitem;
copy_plan_costsize(plan, lefttree);
@@ -2270,7 +2267,7 @@ make_setop(SetOpCmd cmd, Plan *lefttree,
int numCols = length(distinctList);
int keyno = 0;
AttrNumber *dupColIdx;
- List *slitem;
+ ListCell *slitem;
copy_plan_costsize(plan, lefttree);
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index 46fde263456..f8a4bfaaac4 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.98 2004/02/27 21:42:00 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.99 2004/05/26 04:41:24 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -81,7 +81,7 @@ add_base_rels_to_query(Query *root, Node *jtnode)
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
+ ListCell *l;
foreach(l, f->fromlist)
add_base_rels_to_query(root, lfirst(l));
@@ -135,7 +135,7 @@ build_base_rel_tlists(Query *root, List *final_tlist)
static void
add_vars_to_targetlist(Query *root, List *vars, Relids where_needed)
{
- List *temp;
+ ListCell *temp;
Assert(!bms_is_empty(where_needed));
@@ -205,8 +205,7 @@ distribute_quals_to_rels(Query *root, Node *jtnode)
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
- List *qual;
+ ListCell *l;
/*
* First, recurse to handle child joins.
@@ -222,8 +221,8 @@ distribute_quals_to_rels(Query *root, Node *jtnode)
* Now process the top-level quals. These are always marked as
* "pushed down", since they clearly didn't come from a JOIN expr.
*/
- foreach(qual, (List *) f->quals)
- distribute_qual_to_rels(root, (Node *) lfirst(qual),
+ foreach(l, (List *) f->quals)
+ distribute_qual_to_rels(root, (Node *) lfirst(l),
true, false, NULL, result);
}
else if (IsA(jtnode, JoinExpr))
@@ -233,7 +232,7 @@ distribute_quals_to_rels(Query *root, Node *jtnode)
rightids,
nonnullable_rels,
nullable_rels;
- List *qual;
+ ListCell *qual;
/*
* Order of operations here is subtle and critical. First we
@@ -636,7 +635,7 @@ process_implied_equality(Query *root,
BMS_Membership membership;
RelOptInfo *rel1;
List *restrictlist;
- List *itm;
+ ListCell *itm;
Oid ltype,
rtype;
Operator eq_operator;
@@ -803,7 +802,7 @@ qual_is_redundant(Query *root,
Node *newleft;
Node *newright;
List *oldquals;
- List *olditem;
+ ListCell *olditem;
List *equalexprs;
bool someadded;
@@ -860,7 +859,7 @@ qual_is_redundant(Query *root,
{
someadded = false;
/* cannot use foreach here because of possible lremove */
- olditem = oldquals;
+ olditem = list_head(oldquals);
while (olditem)
{
RestrictInfo *oldrinfo = (RestrictInfo *) lfirst(olditem);
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index e094620d620..7b5d44c732b 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.169 2004/05/11 02:21:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.170 2004/05/26 04:41:24 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -174,6 +174,7 @@ subquery_planner(Query *parse, double tuple_fraction)
Plan *plan;
List *newHaving;
List *lst;
+ ListCell *l;
/* Set up for a new level of subquery */
PlannerQueryLevel++;
@@ -206,9 +207,9 @@ subquery_planner(Query *parse, double tuple_fraction)
*/
parse->hasJoinRTEs = false;
hasOuterJoins = false;
- foreach(lst, parse->rtable)
+ foreach(l, parse->rtable)
{
- RangeTblEntry *rte = (RangeTblEntry *) lfirst(lst);
+ RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
if (rte->rtekind == RTE_JOIN)
{
@@ -244,9 +245,9 @@ subquery_planner(Query *parse, double tuple_fraction)
EXPRKIND_ININFO);
/* Also need to preprocess expressions for function RTEs */
- foreach(lst, parse->rtable)
+ foreach(l, parse->rtable)
{
- RangeTblEntry *rte = (RangeTblEntry *) lfirst(lst);
+ RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
if (rte->rtekind == RTE_FUNCTION)
rte->funcexpr = preprocess_expression(parse, rte->funcexpr,
@@ -271,9 +272,9 @@ subquery_planner(Query *parse, double tuple_fraction)
* declared as Node *.
*/
newHaving = NIL;
- foreach(lst, (List *) parse->havingQual)
+ foreach(l, (List *) parse->havingQual)
{
- Node *havingclause = (Node *) lfirst(lst);
+ Node *havingclause = (Node *) lfirst(l);
if (contain_agg_clause(havingclause))
newHaving = lappend(newHaving, havingclause);
@@ -337,9 +338,9 @@ subquery_planner(Query *parse, double tuple_fraction)
*/
plan->initPlan = PlannerInitPlan;
- foreach(lst, plan->initPlan)
+ foreach(l, plan->initPlan)
{
- SubPlan *initplan = (SubPlan *) lfirst(lst);
+ SubPlan *initplan = (SubPlan *) lfirst(l);
plan->extParam = bms_add_members(plan->extParam,
initplan->plan->extParam);
@@ -445,7 +446,7 @@ preprocess_qual_conditions(Query *parse, Node *jtnode)
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
+ ListCell *l;
foreach(l, f->fromlist)
preprocess_qual_conditions(parse, lfirst(l));
@@ -495,7 +496,7 @@ inheritance_planner(Query *parse, List *inheritlist)
int mainrtlength = length(parse->rtable);
List *subplans = NIL;
List *tlist = NIL;
- List *l;
+ ListCell *l;
foreach(l, inheritlist)
{
@@ -524,10 +525,9 @@ inheritance_planner(Query *parse, List *inheritlist)
subrtlength = length(subquery->rtable);
if (subrtlength > mainrtlength)
{
- List *subrt = subquery->rtable;
+ List *subrt;
- while (mainrtlength-- > 0) /* wish we had nthcdr() */
- subrt = lnext(subrt);
+ subrt = list_copy_tail(subquery->rtable, mainrtlength);
parse->rtable = nconc(parse->rtable, subrt);
mainrtlength = subrtlength;
}
@@ -650,7 +650,7 @@ grouping_planner(Query *parse, double tuple_fraction)
*/
if (parse->rowMarks)
{
- List *l;
+ ListCell *l;
/*
* We've got trouble if the FOR UPDATE appears inside
@@ -1328,7 +1328,7 @@ grouping_planner(Query *parse, double tuple_fraction)
static bool
hash_safe_grouping(Query *parse)
{
- List *gl;
+ ListCell *gl;
foreach(gl, parse->groupClause)
{
@@ -1435,17 +1435,17 @@ make_subplanTargetList(Query *parse,
{
int keyno = 0;
AttrNumber *grpColIdx;
- List *gl;
+ ListCell *gl;
grpColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols);
*groupColIdx = grpColIdx;
foreach(gl, parse->groupClause)
{
- GroupClause *grpcl = (GroupClause *) lfirst(gl);
- Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist);
- TargetEntry *te = NULL;
- List *sl;
+ GroupClause *grpcl = (GroupClause *) lfirst(gl);
+ Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist);
+ TargetEntry *te = NULL;
+ ListCell *sl;
/* Find or make a matching sub_tlist entry */
foreach(sl, sub_tlist)
@@ -1489,7 +1489,7 @@ locate_grouping_columns(Query *parse,
AttrNumber *groupColIdx)
{
int keyno = 0;
- List *gl;
+ ListCell *gl;
/*
* No work unless grouping.
@@ -1503,10 +1503,10 @@ locate_grouping_columns(Query *parse,
foreach(gl, parse->groupClause)
{
- GroupClause *grpcl = (GroupClause *) lfirst(gl);
- Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist);
- TargetEntry *te = NULL;
- List *sl;
+ GroupClause *grpcl = (GroupClause *) lfirst(gl);
+ Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist);
+ TargetEntry *te = NULL;
+ ListCell *sl;
foreach(sl, sub_tlist)
{
@@ -1534,7 +1534,8 @@ locate_grouping_columns(Query *parse,
static List *
postprocess_setop_tlist(List *new_tlist, List *orig_tlist)
{
- List *l;
+ ListCell *l;
+ ListCell *orig_tlist_item = list_head(orig_tlist);
foreach(l, new_tlist)
{
@@ -1545,16 +1546,16 @@ postprocess_setop_tlist(List *new_tlist, List *orig_tlist)
if (new_tle->resdom->resjunk)
continue;
- Assert(orig_tlist != NIL);
- orig_tle = (TargetEntry *) lfirst(orig_tlist);
- orig_tlist = lnext(orig_tlist);
+ Assert(orig_tlist_item != NULL);
+ orig_tle = (TargetEntry *) lfirst(orig_tlist_item);
+ orig_tlist_item = lnext(orig_tlist_item);
if (orig_tle->resdom->resjunk) /* should not happen */
elog(ERROR, "resjunk output columns are not implemented");
Assert(new_tle->resdom->resno == orig_tle->resdom->resno);
Assert(new_tle->resdom->restype == orig_tle->resdom->restype);
new_tle->resdom->ressortgroupref = orig_tle->resdom->ressortgroupref;
}
- if (orig_tlist != NIL)
+ if (orig_tlist_item != NULL)
elog(ERROR, "resjunk output columns are not implemented");
return new_tlist;
}
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 84b2aa82805..b8fe70e9350 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.101 2004/05/11 13:15:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.102 2004/05/26 04:41:24 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -84,7 +84,7 @@ static void set_sa_opfuncid(ScalarArrayOpExpr *opexpr);
void
set_plan_references(Plan *plan, List *rtable)
{
- List *pl;
+ ListCell *l;
if (plan == NULL)
return;
@@ -213,15 +213,14 @@ set_plan_references(Plan *plan, List *rtable)
fix_expr_references(plan, ((Result *) plan)->resconstantqual);
break;
case T_Append:
-
/*
* Append, like Sort et al, doesn't actually evaluate its
- * targetlist or quals, and we haven't bothered to give it its
- * own tlist copy. So, don't fix targetlist/qual. But do
- * recurse into child plans.
+ * targetlist or quals, and we haven't bothered to give it
+ * its own tlist copy. So, don't fix targetlist/qual. But
+ * do recurse into child plans.
*/
- foreach(pl, ((Append *) plan)->appendplans)
- set_plan_references((Plan *) lfirst(pl), rtable);
+ foreach(l, ((Append *) plan)->appendplans)
+ set_plan_references((Plan *) lfirst(l), rtable);
break;
default:
elog(ERROR, "unrecognized node type: %d",
@@ -242,9 +241,9 @@ set_plan_references(Plan *plan, List *rtable)
set_plan_references(plan->lefttree, rtable);
set_plan_references(plan->righttree, rtable);
- foreach(pl, plan->initPlan)
+ foreach(l, plan->initPlan)
{
- SubPlan *sp = (SubPlan *) lfirst(pl);
+ SubPlan *sp = (SubPlan *) lfirst(l);
Assert(IsA(sp, SubPlan));
set_plan_references(sp->plan, sp->rtable);
@@ -440,8 +439,8 @@ set_uppernode_references(Plan *plan, Index subvarno)
{
Plan *subplan = plan->lefttree;
List *subplan_targetlist,
- *output_targetlist,
- *l;
+ *output_targetlist;
+ ListCell *l;
bool tlist_has_non_vars;
if (subplan != NULL)
@@ -483,7 +482,7 @@ set_uppernode_references(Plan *plan, Index subvarno)
static bool
targetlist_has_non_vars(List *tlist)
{
- List *l;
+ ListCell *l;
foreach(l, tlist)
{
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index af33da1184e..9245da803e2 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.89 2004/05/11 13:15:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.90 2004/05/26 04:41:24 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -101,7 +101,7 @@ static Param *
replace_outer_var(Var *var)
{
Param *retval;
- List *ppl;
+ ListCell *ppl;
PlannerParamItem *pitem;
Index abslevel;
int i;
@@ -250,7 +250,6 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
Plan *plan;
Bitmapset *tmpset;
int paramid;
- List *lst;
Node *result;
/*
@@ -348,7 +347,7 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
}
else if (node->parParam == NIL && slink->subLinkType == EXPR_SUBLINK)
{
- TargetEntry *te = lfirst(plan->targetlist);
+ TargetEntry *te = linitial(plan->targetlist);
Param *prm;
Assert(!te->resdom->resjunk);
@@ -359,7 +358,7 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
}
else if (node->parParam == NIL && slink->subLinkType == ARRAY_SUBLINK)
{
- TargetEntry *te = lfirst(plan->targetlist);
+ TargetEntry *te = linitial(plan->targetlist);
Oid arraytype;
Param *prm;
@@ -395,11 +394,12 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
result = (Node *) (node->useOr ? make_orclause(exprs) :
make_andclause(exprs));
else
- result = (Node *) lfirst(exprs);
+ result = (Node *) linitial(exprs);
}
else
{
List *args;
+ ListCell *l;
/*
* We can't convert subplans of ALL_SUBLINK or ANY_SUBLINK types
@@ -471,9 +471,9 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
* Make node->args from parParam.
*/
args = NIL;
- foreach(lst, node->parParam)
+ foreach(l, node->parParam)
{
- PlannerParamItem *pitem = nth(lfirsti(lst), PlannerParamList);
+ PlannerParamItem *pitem = nth(lfirsti(l), PlannerParamList);
/*
* The Var or Aggref has already been adjusted to have the
@@ -509,15 +509,17 @@ convert_sublink_opers(List *lefthand, List *operOids,
List **righthandIds)
{
List *result = NIL;
- List *lst;
+ ListCell *l, *lefthand_item, *tlist_item;
*righthandIds = NIL;
+ lefthand_item = list_head(lefthand);
+ tlist_item = list_head(targetlist);
- foreach(lst, operOids)
+ foreach(l, operOids)
{
- Oid opid = lfirsto(lst);
- Node *leftop = lfirst(lefthand);
- TargetEntry *te = lfirst(targetlist);
+ Oid opid = lfirsto(l);
+ Node *leftop = (Node *) lfirst(lefthand_item);
+ TargetEntry *te = (TargetEntry *) lfirst(tlist_item);
Node *rightop;
Operator tup;
@@ -574,8 +576,8 @@ convert_sublink_opers(List *lefthand, List *operOids,
ReleaseSysCache(tup);
- lefthand = lnext(lefthand);
- targetlist = lnext(targetlist);
+ lefthand_item = lnext(lefthand_item);
+ tlist_item = lnext(tlist_item);
}
return result;
@@ -591,7 +593,7 @@ static bool
subplan_is_hashable(SubLink *slink, SubPlan *node)
{
double subquery_size;
- List *opids;
+ ListCell *l;
/*
* The sublink type must be "= ANY" --- that is, an IN operator. (We
@@ -602,7 +604,7 @@ subplan_is_hashable(SubLink *slink, SubPlan *node)
if (slink->subLinkType != ANY_SUBLINK)
return false;
if (length(slink->operName) != 1 ||
- strcmp(strVal(lfirst(slink->operName)), "=") != 0)
+ strcmp(strVal(linitial(slink->operName)), "=") != 0)
return false;
/*
@@ -636,9 +638,9 @@ subplan_is_hashable(SubLink *slink, SubPlan *node)
* different sets of operators with the hash table, but there is no
* obvious usefulness to that at present.)
*/
- foreach(opids, slink->operOids)
+ foreach(l, slink->operOids)
{
- Oid opid = lfirsto(opids);
+ Oid opid = lfirsto(l);
HeapTuple tup;
Form_pg_operator optup;
@@ -690,7 +692,7 @@ convert_IN_to_join(Query *parse, SubLink *sublink)
if (sublink->subLinkType != ANY_SUBLINK)
return NULL;
if (length(sublink->operName) != 1 ||
- strcmp(strVal(lfirst(sublink->operName)), "=") != 0)
+ strcmp(strVal(linitial(sublink->operName)), "=") != 0)
return NULL;
/*
@@ -859,8 +861,8 @@ process_sublinks_mutator(Node *node, bool *isTopQual)
*/
if (and_clause(node))
{
- List *newargs = NIL;
- List *l;
+ List *newargs = NIL;
+ ListCell *l;
/* Still at qual top-level */
locTopQual = *isTopQual;
@@ -884,8 +886,8 @@ process_sublinks_mutator(Node *node, bool *isTopQual)
if (or_clause(node))
{
- List *newargs = NIL;
- List *l;
+ List *newargs = NIL;
+ ListCell *l;
foreach(l, ((BoolExpr *) node)->args)
{
@@ -918,7 +920,7 @@ SS_finalize_plan(Plan *plan, List *rtable)
Bitmapset *outer_params = NULL;
Bitmapset *valid_params = NULL;
int paramid;
- List *lst;
+ ListCell *l;
/*
* First, scan the param list to discover the sets of params that are
@@ -926,9 +928,9 @@ SS_finalize_plan(Plan *plan, List *rtable)
* this once to save time in the per-plan recursion steps.
*/
paramid = 0;
- foreach(lst, PlannerParamList)
+ foreach(l, PlannerParamList)
{
- PlannerParamItem *pitem = (PlannerParamItem *) lfirst(lst);
+ PlannerParamItem *pitem = (PlannerParamItem *) lfirst(l);
if (pitem->abslevel < PlannerQueryLevel)
{
@@ -966,7 +968,6 @@ finalize_plan(Plan *plan, List *rtable,
Bitmapset *outer_params, Bitmapset *valid_params)
{
finalize_primnode_context context;
- List *lst;
if (plan == NULL)
return NULL;
@@ -1033,14 +1034,18 @@ finalize_plan(Plan *plan, List *rtable,
break;
case T_Append:
- foreach(lst, ((Append *) plan)->appendplans)
{
- context.paramids =
- bms_add_members(context.paramids,
- finalize_plan((Plan *) lfirst(lst),
- rtable,
- outer_params,
- valid_params));
+ ListCell *l;
+
+ foreach(l, ((Append *) plan)->appendplans)
+ {
+ context.paramids =
+ bms_add_members(context.paramids,
+ finalize_plan((Plan *) lfirst(l),
+ rtable,
+ outer_params,
+ valid_params));
+ }
}
break;
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 0ddf1ccd67f..f916d54602d 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.17 2004/05/10 22:44:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.18 2004/05/26 04:41:26 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -97,11 +97,11 @@ pull_up_IN_clauses(Query *parse, Node *node)
if (and_clause(node))
{
List *newclauses = NIL;
- List *oldclauses;
+ ListCell *l;
- foreach(oldclauses, ((BoolExpr *) node)->args)
+ foreach(l, ((BoolExpr *) node)->args)
{
- Node *oldclause = lfirst(oldclauses);
+ Node *oldclause = (Node *) lfirst(l);
newclauses = lappend(newclauses,
pull_up_IN_clauses(parse,
@@ -162,7 +162,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
{
int rtoffset;
List *subtlist;
- List *rt;
+ ListCell *rt;
/*
* Need a modifiable copy of the subquery to hack on. Even if
@@ -314,7 +314,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
+ ListCell *l;
foreach(l, f->fromlist)
lfirst(l) = pull_up_subqueries(parse, lfirst(l),
@@ -447,7 +447,7 @@ is_simple_subquery(Query *subquery)
static bool
has_nullable_targetlist(Query *subquery)
{
- List *l;
+ ListCell *l;
foreach(l, subquery->targetList)
{
@@ -488,7 +488,7 @@ resolvenew_in_jointree(Node *jtnode, int varno,
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
+ ListCell *l;
foreach(l, f->fromlist)
resolvenew_in_jointree(lfirst(l), varno, rte, subtlist);
@@ -588,7 +588,7 @@ reduce_outer_joins_pass1(Node *jtnode)
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
+ ListCell *l;
foreach(l, f->fromlist)
{
@@ -653,8 +653,8 @@ reduce_outer_joins_pass2(Node *jtnode,
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
- List *s;
+ ListCell *l;
+ ListCell *s;
Relids pass_nonnullable;
/* Scan quals to see if we can add any nonnullability constraints */
@@ -662,15 +662,14 @@ reduce_outer_joins_pass2(Node *jtnode,
pass_nonnullable = bms_add_members(pass_nonnullable,
nonnullable_rels);
/* And recurse --- but only into interesting subtrees */
- s = state->sub_states;
- foreach(l, f->fromlist)
+ Assert(length(f->fromlist) == length(state->sub_states));
+ forboth(l, f->fromlist, s, state->sub_states)
{
reduce_outer_joins_state *sub_state = lfirst(s);
if (sub_state->contains_outer)
reduce_outer_joins_pass2(lfirst(l), sub_state, parse,
pass_nonnullable);
- s = lnext(s);
}
bms_free(pass_nonnullable);
}
@@ -679,7 +678,7 @@ reduce_outer_joins_pass2(Node *jtnode,
JoinExpr *j = (JoinExpr *) jtnode;
int rtindex = j->rtindex;
JoinType jointype = j->jointype;
- reduce_outer_joins_state *left_state = lfirst(state->sub_states);
+ reduce_outer_joins_state *left_state = linitial(state->sub_states);
reduce_outer_joins_state *right_state = lsecond(state->sub_states);
/* Can we simplify this join? */
@@ -798,7 +797,7 @@ find_nonnullable_rels(Node *node, bool top_level)
}
else if (IsA(node, List))
{
- List *l;
+ ListCell *l;
foreach(l, (List *) node)
{
@@ -898,7 +897,7 @@ simplify_jointree(Query *parse, Node *jtnode)
{
FromExpr *f = (FromExpr *) jtnode;
List *newlist = NIL;
- List *l;
+ ListCell *l;
foreach(l, f->fromlist)
{
@@ -918,7 +917,16 @@ simplify_jointree(Query *parse, Node *jtnode)
*/
FromExpr *subf = (FromExpr *) child;
int childlen = length(subf->fromlist);
- int myothers = length(newlist) + length(lnext(l));
+ int myothers;
+ ListCell *l2;
+
+ /*
+ * XXX: This is a quick hack, not sure of the proper
+ * fix.
+ */
+ myothers = length(newlist);
+ for_each_cell(l2, lnext(l))
+ myothers++;
if (childlen <= 1 ||
(childlen + myothers) <= from_collapse_limit)
@@ -1022,7 +1030,7 @@ simplify_jointree(Query *parse, Node *jtnode)
static void
fix_in_clause_relids(List *in_info_list, int varno, Relids subrelids)
{
- List *l;
+ ListCell *l;
foreach(l, in_info_list)
{
@@ -1060,7 +1068,7 @@ get_relids_in_jointree(Node *jtnode)
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
+ ListCell *l;
foreach(l, f->fromlist)
{
@@ -1119,7 +1127,7 @@ find_jointree_node_for_rel(Node *jtnode, int relid)
else if (IsA(jtnode, FromExpr))
{
FromExpr *f = (FromExpr *) jtnode;
- List *l;
+ ListCell *l;
foreach(l, f->fromlist)
{
diff --git a/src/backend/optimizer/prep/prepqual.c b/src/backend/optimizer/prep/prepqual.c
index ac107aade61..1cfafe5452b 100644
--- a/src/backend/optimizer/prep/prepqual.c
+++ b/src/backend/optimizer/prep/prepqual.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepqual.c,v 1.41 2003/12/30 21:49:19 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepqual.c,v 1.42 2004/05/26 04:41:26 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -144,7 +144,7 @@ flatten_andors_mutator(Node *node, void *context)
static void
flatten_andors_and_walker(FastList *out_list, List *andlist)
{
- List *arg;
+ ListCell *arg;
foreach(arg, andlist)
{
@@ -160,7 +160,7 @@ flatten_andors_and_walker(FastList *out_list, List *andlist)
static void
flatten_andors_or_walker(FastList *out_list, List *orlist)
{
- List *arg;
+ ListCell *arg;
foreach(arg, orlist)
{
@@ -193,7 +193,7 @@ pull_ands(List *andlist)
static void
pull_ands_walker(FastList *out_list, List *andlist)
{
- List *arg;
+ ListCell *arg;
foreach(arg, andlist)
{
@@ -226,7 +226,7 @@ pull_ors(List *orlist)
static void
pull_ors_walker(FastList *out_list, List *orlist)
{
- List *arg;
+ ListCell *arg;
foreach(arg, orlist)
{
@@ -258,7 +258,7 @@ find_nots(Expr *qual)
if (and_clause((Node *) qual))
{
FastList t_list;
- List *temp;
+ ListCell *temp;
FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args)
@@ -268,7 +268,7 @@ find_nots(Expr *qual)
else if (or_clause((Node *) qual))
{
FastList t_list;
- List *temp;
+ ListCell *temp;
FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args)
@@ -324,7 +324,7 @@ push_nots(Expr *qual)
*--------------------
*/
FastList t_list;
- List *temp;
+ ListCell *temp;
FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args)
@@ -334,7 +334,7 @@ push_nots(Expr *qual)
else if (or_clause((Node *) qual))
{
FastList t_list;
- List *temp;
+ ListCell *temp;
FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args)
@@ -398,7 +398,7 @@ find_duplicate_ors(Expr *qual)
if (or_clause((Node *) qual))
{
List *orlist = NIL;
- List *temp;
+ ListCell *temp;
/* Recurse */
foreach(temp, ((BoolExpr *) qual)->args)
@@ -412,7 +412,7 @@ find_duplicate_ors(Expr *qual)
else if (and_clause((Node *) qual))
{
List *andlist = NIL;
- List *temp;
+ ListCell *temp;
/* Recurse */
foreach(temp, ((BoolExpr *) qual)->args)
@@ -441,13 +441,12 @@ process_duplicate_ors(List *orlist)
int num_subclauses = 0;
List *winners;
List *neworlist;
- List *temp;
- List *temp2;
+ ListCell *temp;
if (orlist == NIL)
return NULL; /* probably can't happen */
- if (lnext(orlist) == NIL)
- return lfirst(orlist); /* single-expression OR (can this happen?) */
+ if (length(orlist) == 1) /* single-expression OR (can this happen?) */
+ return linitial(orlist);
/*
* Choose the shortest AND clause as the reference list --- obviously,
@@ -457,7 +456,7 @@ process_duplicate_ors(List *orlist)
*/
foreach(temp, orlist)
{
- Expr *clause = lfirst(temp);
+ Expr *clause = (Expr *) lfirst(temp);
if (and_clause((Node *) clause))
{
@@ -489,12 +488,13 @@ process_duplicate_ors(List *orlist)
winners = NIL;
foreach(temp, reference)
{
- Expr *refclause = lfirst(temp);
+ Expr *refclause = (Expr *) lfirst(temp);
bool win = true;
+ ListCell *temp2;
foreach(temp2, orlist)
{
- Expr *clause = lfirst(temp2);
+ Expr *clause = (Expr *) lfirst(temp2);
if (and_clause((Node *) clause))
{
@@ -537,7 +537,7 @@ process_duplicate_ors(List *orlist)
neworlist = NIL;
foreach(temp, orlist)
{
- Expr *clause = lfirst(temp);
+ Expr *clause = (Expr *) lfirst(temp);
if (and_clause((Node *) clause))
{
@@ -546,8 +546,8 @@ process_duplicate_ors(List *orlist)
subclauses = set_difference(subclauses, winners);
if (subclauses != NIL)
{
- if (lnext(subclauses) == NIL)
- neworlist = lappend(neworlist, lfirst(subclauses));
+ if (length(subclauses) == 1)
+ neworlist = lappend(neworlist, linitial(subclauses));
else
neworlist = lappend(neworlist, make_andclause(subclauses));
}
@@ -577,8 +577,8 @@ process_duplicate_ors(List *orlist)
*/
if (neworlist != NIL)
{
- if (lnext(neworlist) == NIL)
- winners = lappend(winners, lfirst(neworlist));
+ if (length(neworlist) == 1)
+ winners = lappend(winners, linitial(neworlist));
else
winners = lappend(winners, make_orclause(pull_ors(neworlist)));
}
@@ -587,8 +587,8 @@ process_duplicate_ors(List *orlist)
* And return the constructed AND clause, again being wary of a single
* element and AND/OR flatness.
*/
- if (lnext(winners) == NIL)
- return (Expr *) lfirst(winners);
+ if (length(winners) == 1)
+ return (Expr *) linitial(winners);
else
return make_andclause(pull_ands(winners));
}
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);
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index 25dfc2611e8..41809bd69e0 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.110 2004/05/11 22:43:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.111 2004/05/26 04:41:26 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -420,15 +420,19 @@ generate_setop_tlist(List *colTypes, int flag,
{
List *tlist = NIL;
int resno = 1;
- List *i;
+ ListCell *i,
+ *j,
+ *k;
Resdom *resdom;
Node *expr;
+ j = list_head(input_tlist);
+ k = list_head(refnames_tlist);
foreach(i, colTypes)
{
Oid colType = lfirsto(i);
- TargetEntry *inputtle = (TargetEntry *) lfirst(input_tlist);
- TargetEntry *reftle = (TargetEntry *) lfirst(refnames_tlist);
+ TargetEntry *inputtle = (TargetEntry *) lfirst(j);
+ TargetEntry *reftle = (TargetEntry *) lfirst(k);
int32 colTypmod;
Assert(inputtle->resdom->resno == resno);
@@ -476,8 +480,8 @@ generate_setop_tlist(List *colTypes, int flag,
pstrdup(reftle->resdom->resname),
false);
tlist = lappend(tlist, makeTargetEntry(resdom, (Expr *) expr));
- input_tlist = lnext(input_tlist);
- refnames_tlist = lnext(refnames_tlist);
+ j = lnext(j);
+ k = lnext(k);
}
if (flag >= 0)
@@ -518,11 +522,12 @@ generate_append_tlist(List *colTypes, bool flag,
{
List *tlist = NIL;
int resno = 1;
- List *curColType;
+ ListCell *curColType;
+ ListCell *ref_tl_item;
int colindex;
Resdom *resdom;
Node *expr;
- List *planl;
+ ListCell *planl;
int32 *colTypmods;
/*
@@ -536,9 +541,9 @@ generate_append_tlist(List *colTypes, bool flag,
foreach(planl, input_plans)
{
Plan *subplan = (Plan *) lfirst(planl);
- List *subtlist;
+ ListCell *subtlist;
- curColType = colTypes;
+ curColType = list_head(colTypes);
colindex = 0;
foreach(subtlist, subplan->targetlist)
{
@@ -546,11 +551,11 @@ generate_append_tlist(List *colTypes, bool flag,
if (subtle->resdom->resjunk)
continue;
- Assert(curColType != NIL);
- if (subtle->resdom->restype == lfirsto(curColType))
+ Assert(curColType != NULL);
+ if (subtle->resdom->restype == lfirst_oid(curColType))
{
/* If first subplan, copy the typmod; else compare */
- if (planl == input_plans)
+ if (planl == list_head(input_plans))
colTypmods[colindex] = subtle->resdom->restypmod;
else if (subtle->resdom->restypmod != colTypmods[colindex])
colTypmods[colindex] = -1;
@@ -563,18 +568,18 @@ generate_append_tlist(List *colTypes, bool flag,
curColType = lnext(curColType);
colindex++;
}
- Assert(curColType == NIL);
+ Assert(curColType == NULL);
}
/*
* Now we can build the tlist for the Append.
*/
colindex = 0;
- foreach(curColType, colTypes)
+ forboth(curColType, colTypes, ref_tl_item, refnames_tlist)
{
Oid colType = lfirsto(curColType);
int32 colTypmod = colTypmods[colindex++];
- TargetEntry *reftle = (TargetEntry *) lfirst(refnames_tlist);
+ TargetEntry *reftle = (TargetEntry *) lfirst(ref_tl_item);
Assert(reftle->resdom->resno == resno);
Assert(!reftle->resdom->resjunk);
@@ -589,7 +594,6 @@ generate_append_tlist(List *colTypes, bool flag,
pstrdup(reftle->resdom->resname),
false);
tlist = lappend(tlist, makeTargetEntry(resdom, (Expr *) expr));
- refnames_tlist = lnext(refnames_tlist);
}
if (flag)
@@ -623,11 +627,12 @@ generate_append_tlist(List *colTypes, bool flag,
static bool
tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)
{
- List *i;
+ ListCell *l;
+ ListCell *curColType = list_head(colTypes);
- foreach(i, tlist)
+ foreach(l, tlist)
{
- TargetEntry *tle = (TargetEntry *) lfirst(i);
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
if (tle->resdom->resjunk)
{
@@ -636,14 +641,14 @@ tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)
}
else
{
- if (colTypes == NIL)
+ if (curColType == NULL)
return false;
- if (tle->resdom->restype != lfirsto(colTypes))
+ if (tle->resdom->restype != lfirst_oid(curColType))
return false;
- colTypes = lnext(colTypes);
+ curColType = lnext(curColType);
}
}
- if (colTypes != NIL)
+ if (curColType != NULL)
return false;
return true;
}
@@ -667,10 +672,10 @@ find_all_inheritors(Oid parentrel)
*/
while (unexamined_relids != NIL)
{
- Oid currentrel = lfirsto(unexamined_relids);
+ Oid currentrel = linitial_oid(unexamined_relids);
List *currentchildren;
- unexamined_relids = lnext(unexamined_relids);
+ unexamined_relids = list_delete_first(unexamined_relids);
examined_relids = lappendo(examined_relids, currentrel);
currentchildren = find_inheritance_children(currentrel);
@@ -719,7 +724,7 @@ expand_inherited_rtentry(Query *parse, Index rti, bool dup_parent)
Oid parentOID;
List *inhOIDs;
List *inhRTIs;
- List *l;
+ ListCell *l;
/* Does RT entry allow inheritance? */
if (!rte->inh)
@@ -739,7 +744,7 @@ expand_inherited_rtentry(Query *parse, Index rti, bool dup_parent)
* case. This could happen despite above has_subclass() check, if
* table once had a child but no longer does.
*/
- if (lnext(inhOIDs) == NIL)
+ if (length(inhOIDs) < 2)
return NIL;
/* OK, it's an inheritance set; expand it */
if (dup_parent)
@@ -1020,7 +1025,7 @@ static List *
adjust_inherited_tlist(List *tlist, Oid old_relid, Oid new_relid)
{
bool changed_it = false;
- List *tl;
+ ListCell *tl;
List *new_tlist;
bool more;
int attrno;
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)
{