mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
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.
This commit is contained in:
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user