Commit e590ceec authored by Tom Lane's avatar Tom Lane

Just about there on de-FastList-ification.

parent 962a94bb
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.160 2004/05/30 23:40:28 neilc Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.161 2004/06/01 04:47:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -237,7 +237,7 @@ create_index_paths(Query *root, RelOptInfo *rel) ...@@ -237,7 +237,7 @@ create_index_paths(Query *root, RelOptInfo *rel)
static List * static List *
group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index) group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index)
{ {
FastList clausegroup_list; List *clausegroup_list = NIL;
List *restrictinfo_list = rel->baserestrictinfo; List *restrictinfo_list = rel->baserestrictinfo;
int indexcol = 0; int indexcol = 0;
Oid *classes = index->classlist; Oid *classes = index->classlist;
...@@ -245,14 +245,12 @@ group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index) ...@@ -245,14 +245,12 @@ group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index)
if (restrictinfo_list == NIL) if (restrictinfo_list == NIL)
return NIL; return NIL;
FastListInit(&clausegroup_list);
do do
{ {
Oid curClass = classes[0]; Oid curClass = classes[0];
FastList clausegroup; List *clausegroup = NIL;
ListCell *l; ListCell *l;
FastListInit(&clausegroup);
foreach(l, restrictinfo_list) foreach(l, restrictinfo_list)
{ {
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l); RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
...@@ -262,24 +260,24 @@ group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index) ...@@ -262,24 +260,24 @@ group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index)
indexcol, indexcol,
curClass, curClass,
rinfo)) rinfo))
FastAppend(&clausegroup, rinfo); clausegroup = lappend(clausegroup, rinfo);
} }
/* /*
* If no clauses match this key, we're done; we don't want to look * If no clauses match this key, we're done; we don't want to look
* at keys to its right. * at keys to its right.
*/ */
if (FastListValue(&clausegroup) == NIL) if (clausegroup == NIL)
break; break;
FastAppend(&clausegroup_list, FastListValue(&clausegroup)); clausegroup_list = lappend(clausegroup_list, clausegroup);
indexcol++; indexcol++;
classes++; classes++;
} while (!DoneMatchingIndexKeys(classes)); } while (!DoneMatchingIndexKeys(classes));
return FastListValue(&clausegroup_list); return clausegroup_list;
} }
/* /*
...@@ -301,21 +299,18 @@ group_clauses_by_indexkey_for_join(Query *root, ...@@ -301,21 +299,18 @@ group_clauses_by_indexkey_for_join(Query *root,
Relids outer_relids, Relids outer_relids,
JoinType jointype, bool isouterjoin) JoinType jointype, bool isouterjoin)
{ {
FastList clausegroup_list; List *clausegroup_list = NIL;
bool jfound = false; bool jfound = false;
int indexcol = 0; int indexcol = 0;
Oid *classes = index->classlist; Oid *classes = index->classlist;
FastListInit(&clausegroup_list);
do do
{ {
Oid curClass = classes[0]; Oid curClass = classes[0];
FastList clausegroup; List *clausegroup = NIL;
int numsources; int numsources;
ListCell *l; ListCell *l;
FastListInit(&clausegroup);
/* /*
* We can always use plain restriction clauses for the rel. We scan * We can always use plain restriction clauses for the rel. We scan
* these first because we want them first in the clausegroup list * these first because we want them first in the clausegroup list
...@@ -337,11 +332,11 @@ group_clauses_by_indexkey_for_join(Query *root, ...@@ -337,11 +332,11 @@ group_clauses_by_indexkey_for_join(Query *root,
indexcol, indexcol,
curClass, curClass,
rinfo)) rinfo))
FastAppend(&clausegroup, rinfo); clausegroup = lappend(clausegroup, rinfo);
} }
/* found anything in base restrict list? */ /* found anything in base restrict list? */
numsources = (FastListValue(&clausegroup) != NIL) ? 1 : 0; numsources = (clausegroup != NIL) ? 1 : 0;
/* Look for joinclauses that are usable with given outer_relids */ /* Look for joinclauses that are usable with given outer_relids */
foreach(l, rel->joininfo) foreach(l, rel->joininfo)
...@@ -367,7 +362,7 @@ group_clauses_by_indexkey_for_join(Query *root, ...@@ -367,7 +362,7 @@ group_clauses_by_indexkey_for_join(Query *root,
curClass, curClass,
rinfo)) rinfo))
{ {
FastAppend(&clausegroup, rinfo); clausegroup = lappend(clausegroup, rinfo);
if (!jfoundhere) if (!jfoundhere)
{ {
jfoundhere = true; jfoundhere = true;
...@@ -384,22 +379,19 @@ group_clauses_by_indexkey_for_join(Query *root, ...@@ -384,22 +379,19 @@ group_clauses_by_indexkey_for_join(Query *root,
*/ */
if (numsources > 1) if (numsources > 1)
{ {
List *nl; clausegroup = remove_redundant_join_clauses(root,
clausegroup,
nl = remove_redundant_join_clauses(root, jointype);
FastListValue(&clausegroup),
jointype);
FastListFromList(&clausegroup, nl);
} }
/* /*
* If no clauses match this key, we're done; we don't want to look * If no clauses match this key, we're done; we don't want to look
* at keys to its right. * at keys to its right.
*/ */
if (FastListValue(&clausegroup) == NIL) if (clausegroup == NIL)
break; break;
FastAppend(&clausegroup_list, FastListValue(&clausegroup)); clausegroup_list = lappend(clausegroup_list, clausegroup);
indexcol++; indexcol++;
classes++; classes++;
...@@ -410,7 +402,7 @@ group_clauses_by_indexkey_for_join(Query *root, ...@@ -410,7 +402,7 @@ group_clauses_by_indexkey_for_join(Query *root,
if (!jfound) if (!jfound)
return NIL; return NIL;
return FastListValue(&clausegroup_list); return clausegroup_list;
} }
...@@ -438,20 +430,17 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel, ...@@ -438,20 +430,17 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
IndexOptInfo *index, IndexOptInfo *index,
Expr *orsubclause) Expr *orsubclause)
{ {
FastList clausegroup_list; List *clausegroup_list = NIL;
bool matched = false; bool matched = false;
int indexcol = 0; int indexcol = 0;
Oid *classes = index->classlist; Oid *classes = index->classlist;
FastListInit(&clausegroup_list);
do do
{ {
Oid curClass = classes[0]; Oid curClass = classes[0];
FastList clausegroup; List *clausegroup = NIL;
ListCell *item; ListCell *item;
FastListInit(&clausegroup);
/* Try to match the OR subclause to the index key */ /* Try to match the OR subclause to the index key */
if (IsA(orsubclause, RestrictInfo)) if (IsA(orsubclause, RestrictInfo))
{ {
...@@ -459,7 +448,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel, ...@@ -459,7 +448,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
indexcol, curClass, indexcol, curClass,
(RestrictInfo *) orsubclause)) (RestrictInfo *) orsubclause))
{ {
FastAppend(&clausegroup, orsubclause); clausegroup = lappend(clausegroup, orsubclause);
matched = true; matched = true;
} }
} }
...@@ -474,7 +463,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel, ...@@ -474,7 +463,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
indexcol, curClass, indexcol, curClass,
subsubclause)) subsubclause))
{ {
FastAppend(&clausegroup, subsubclause); clausegroup = lappend(clausegroup, subsubclause);
matched = true; matched = true;
} }
} }
...@@ -487,7 +476,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel, ...@@ -487,7 +476,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
* XXX should we always search the top-level list? Slower but * XXX should we always search the top-level list? Slower but
* could sometimes yield a better plan. * could sometimes yield a better plan.
*/ */
if (FastListValue(&clausegroup) == NIL) if (clausegroup == NIL)
{ {
foreach(item, rel->baserestrictinfo) foreach(item, rel->baserestrictinfo)
{ {
...@@ -496,7 +485,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel, ...@@ -496,7 +485,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
if (match_clause_to_indexcol(rel, index, if (match_clause_to_indexcol(rel, index,
indexcol, curClass, indexcol, curClass,
rinfo)) rinfo))
FastAppend(&clausegroup, rinfo); clausegroup = lappend(clausegroup, rinfo);
} }
} }
...@@ -504,10 +493,10 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel, ...@@ -504,10 +493,10 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
* If still no clauses match this key, we're done; we don't want * If still no clauses match this key, we're done; we don't want
* to look at keys to its right. * to look at keys to its right.
*/ */
if (FastListValue(&clausegroup) == NIL) if (clausegroup == NIL)
break; break;
FastAppend(&clausegroup_list, FastListValue(&clausegroup)); clausegroup_list = lappend(clausegroup_list, clausegroup);
indexcol++; indexcol++;
classes++; classes++;
...@@ -517,7 +506,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel, ...@@ -517,7 +506,7 @@ group_clauses_by_indexkey_for_or(RelOptInfo *rel,
if (!matched) if (!matched)
return NIL; return NIL;
return FastListValue(&clausegroup_list); return clausegroup_list;
} }
...@@ -2011,14 +2000,13 @@ match_special_index_operator(Expr *clause, Oid opclass, ...@@ -2011,14 +2000,13 @@ match_special_index_operator(Expr *clause, Oid opclass,
List * List *
expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups) expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
{ {
FastList resultquals; List *resultquals = NIL;
ListCell *clausegroup_item; ListCell *clausegroup_item;
Oid *classes = index->classlist; Oid *classes = index->classlist;
if (clausegroups == NIL) if (clausegroups == NIL)
return NIL; return NIL;
FastListInit(&resultquals);
clausegroup_item = list_head(clausegroups); clausegroup_item = list_head(clausegroups);
do do
{ {
...@@ -2029,17 +2017,18 @@ expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups) ...@@ -2029,17 +2017,18 @@ expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
{ {
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l); RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
FastConc(&resultquals, resultquals = list_concat(resultquals,
expand_indexqual_condition(rinfo, curClass)); expand_indexqual_condition(rinfo,
curClass));
} }
clausegroup_item = lnext(clausegroup_item); clausegroup_item = lnext(clausegroup_item);
classes++; classes++;
} while (clausegroup_item != NULL && !DoneMatchingIndexKeys(classes)); } while (clausegroup_item != NULL && !DoneMatchingIndexKeys(classes));
Assert(clausegroup_item == NULL); /* else more groups than indexkeys... */ Assert(clausegroup_item == NULL); /* else more groups than indexkeys */
return FastListValue(&resultquals); return resultquals;
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.59 2004/05/30 23:40:28 neilc Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.60 2004/06/01 04:47:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -243,20 +243,14 @@ best_or_subclause_indexes(Query *root, ...@@ -243,20 +243,14 @@ best_or_subclause_indexes(Query *root,
RelOptInfo *rel, RelOptInfo *rel,
List *subclauses) List *subclauses)
{ {
FastList infos; List *infos = NIL;
FastList clauses; List *clauses = NIL;
FastList quals; List *quals = NIL;
Cost path_startup_cost; Cost path_startup_cost = 0;
Cost path_total_cost; Cost path_total_cost = 0;
ListCell *slist; ListCell *slist;
IndexPath *pathnode; IndexPath *pathnode;
FastListInit(&infos);
FastListInit(&clauses);
FastListInit(&quals);
path_startup_cost = 0;
path_total_cost = 0;
/* Gather info for each OR subclause */ /* Gather info for each OR subclause */
foreach(slist, subclauses) foreach(slist, subclauses)
{ {
...@@ -273,9 +267,9 @@ best_or_subclause_indexes(Query *root, ...@@ -273,9 +267,9 @@ best_or_subclause_indexes(Query *root,
&best_startup_cost, &best_total_cost)) &best_startup_cost, &best_total_cost))
return NULL; /* failed to match this subclause */ return NULL; /* failed to match this subclause */
FastAppend(&infos, best_indexinfo); infos = lappend(infos, best_indexinfo);
FastAppend(&clauses, best_indexclauses); clauses = lappend(clauses, best_indexclauses);
FastAppend(&quals, best_indexquals); quals = lappend(quals, best_indexquals);
/* /*
* Path startup_cost is the startup cost for the first index scan only; * Path startup_cost is the startup cost for the first index scan only;
* startup costs for later scans will be paid later on, so they just * startup costs for later scans will be paid later on, so they just
...@@ -303,9 +297,9 @@ best_or_subclause_indexes(Query *root, ...@@ -303,9 +297,9 @@ best_or_subclause_indexes(Query *root,
*/ */
pathnode->path.pathkeys = NIL; pathnode->path.pathkeys = NIL;
pathnode->indexinfo = FastListValue(&infos); pathnode->indexinfo = infos;
pathnode->indexclauses = FastListValue(&clauses); pathnode->indexclauses = clauses;
pathnode->indexquals = FastListValue(&quals); pathnode->indexquals = quals;
/* It's not an innerjoin path. */ /* It's not an innerjoin path. */
pathnode->isjoininner = false; pathnode->isjoininner = false;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepqual.c,v 1.43 2004/05/30 23:40:29 neilc Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepqual.c,v 1.44 2004/06/01 04:47:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,12 +22,8 @@ ...@@ -22,12 +22,8 @@
static Node *flatten_andors_mutator(Node *node, void *context); static Node *flatten_andors_mutator(Node *node, void *context);
static void flatten_andors_and_walker(FastList *out_list, List *andlist);
static void flatten_andors_or_walker(FastList *out_list, List *orlist);
static List *pull_ands(List *andlist); static List *pull_ands(List *andlist);
static void pull_ands_walker(FastList *out_list, List *andlist);
static List *pull_ors(List *orlist); static List *pull_ors(List *orlist);
static void pull_ors_walker(FastList *out_list, List *orlist);
static Expr *find_nots(Expr *qual); static Expr *find_nots(Expr *qual);
static Expr *push_nots(Expr *qual); static Expr *push_nots(Expr *qual);
static Expr *find_duplicate_ors(Expr *qual); static Expr *find_duplicate_ors(Expr *qual);
...@@ -122,57 +118,55 @@ flatten_andors_mutator(Node *node, void *context) ...@@ -122,57 +118,55 @@ flatten_andors_mutator(Node *node, void *context)
if (bexpr->boolop == AND_EXPR) if (bexpr->boolop == AND_EXPR)
{ {
FastList out_list; List *out_list = NIL;
ListCell *arg;
FastListInit(&out_list); foreach(arg, bexpr->args)
flatten_andors_and_walker(&out_list, bexpr->args); {
return (Node *) make_andclause(FastListValue(&out_list)); Node *subexpr = flatten_andors((Node *) lfirst(arg));
/*
* Note: we can destructively concat the subexpression's
* arglist because we know the recursive invocation of
* flatten_andors will have built a new arglist not shared
* with any other expr. Otherwise we'd need a list_copy here.
*/
if (and_clause(subexpr))
out_list = list_concat(out_list,
((BoolExpr *) subexpr)->args);
else
out_list = lappend(out_list, subexpr);
}
return (Node *) make_andclause(out_list);
} }
if (bexpr->boolop == OR_EXPR) if (bexpr->boolop == OR_EXPR)
{ {
FastList out_list; List *out_list = NIL;
ListCell *arg;
FastListInit(&out_list); foreach(arg, bexpr->args)
flatten_andors_or_walker(&out_list, bexpr->args); {
return (Node *) make_orclause(FastListValue(&out_list)); Node *subexpr = flatten_andors((Node *) lfirst(arg));
/*
* Note: we can destructively concat the subexpression's
* arglist because we know the recursive invocation of
* flatten_andors will have built a new arglist not shared
* with any other expr. Otherwise we'd need a list_copy here.
*/
if (or_clause(subexpr))
out_list = list_concat(out_list,
((BoolExpr *) subexpr)->args);
else
out_list = lappend(out_list, subexpr);
}
return (Node *) make_orclause(out_list);
} }
/* else it's a NOT clause, fall through */ /* else it's a NOT clause, fall through */
} }
return expression_tree_mutator(node, flatten_andors_mutator, context); return expression_tree_mutator(node, flatten_andors_mutator, context);
} }
static void
flatten_andors_and_walker(FastList *out_list, List *andlist)
{
ListCell *arg;
foreach(arg, andlist)
{
Node *subexpr = (Node *) lfirst(arg);
if (and_clause(subexpr))
flatten_andors_and_walker(out_list, ((BoolExpr *) subexpr)->args);
else
FastAppend(out_list, flatten_andors(subexpr));
}
}
static void
flatten_andors_or_walker(FastList *out_list, List *orlist)
{
ListCell *arg;
foreach(arg, orlist)
{
Node *subexpr = (Node *) lfirst(arg);
if (or_clause(subexpr))
flatten_andors_or_walker(out_list, ((BoolExpr *) subexpr)->args);
else
FastAppend(out_list, flatten_andors(subexpr));
}
}
/* /*
* pull_ands * pull_ands
* Recursively flatten nested AND clauses into a single and-clause list. * Recursively flatten nested AND clauses into a single and-clause list.
...@@ -183,27 +177,26 @@ flatten_andors_or_walker(FastList *out_list, List *orlist) ...@@ -183,27 +177,26 @@ flatten_andors_or_walker(FastList *out_list, List *orlist)
static List * static List *
pull_ands(List *andlist) pull_ands(List *andlist)
{ {
FastList out_list; List *out_list = NIL;
FastListInit(&out_list);
pull_ands_walker(&out_list, andlist);
return FastListValue(&out_list);
}
static void
pull_ands_walker(FastList *out_list, List *andlist)
{
ListCell *arg; ListCell *arg;
foreach(arg, andlist) foreach(arg, andlist)
{ {
Node *subexpr = (Node *) lfirst(arg); Node *subexpr = (Node *) lfirst(arg);
/*
* Note: we can destructively concat the subexpression's arglist
* because we know the recursive invocation of pull_ands will have
* built a new arglist not shared with any other expr. Otherwise
* we'd need a list_copy here.
*/
if (and_clause(subexpr)) if (and_clause(subexpr))
pull_ands_walker(out_list, ((BoolExpr *) subexpr)->args); out_list = list_concat(out_list,
pull_ands(((BoolExpr *) subexpr)->args));
else else
FastAppend(out_list, subexpr); out_list = lappend(out_list, subexpr);
} }
return out_list;
} }
/* /*
...@@ -216,27 +209,26 @@ pull_ands_walker(FastList *out_list, List *andlist) ...@@ -216,27 +209,26 @@ pull_ands_walker(FastList *out_list, List *andlist)
static List * static List *
pull_ors(List *orlist) pull_ors(List *orlist)
{ {
FastList out_list; List *out_list = NIL;
FastListInit(&out_list);
pull_ors_walker(&out_list, orlist);
return FastListValue(&out_list);
}
static void
pull_ors_walker(FastList *out_list, List *orlist)
{
ListCell *arg; ListCell *arg;
foreach(arg, orlist) foreach(arg, orlist)
{ {
Node *subexpr = (Node *) lfirst(arg); Node *subexpr = (Node *) lfirst(arg);
/*
* Note: we can destructively concat the subexpression's arglist
* because we know the recursive invocation of pull_ors will have
* built a new arglist not shared with any other expr. Otherwise
* we'd need a list_copy here.
*/
if (or_clause(subexpr)) if (or_clause(subexpr))
pull_ors_walker(out_list, ((BoolExpr *) subexpr)->args); out_list = list_concat(out_list,
pull_ors(((BoolExpr *) subexpr)->args));
else else
FastAppend(out_list, subexpr); out_list = lappend(out_list, subexpr);
} }
return out_list;
} }
...@@ -257,23 +249,21 @@ find_nots(Expr *qual) ...@@ -257,23 +249,21 @@ find_nots(Expr *qual)
if (and_clause((Node *) qual)) if (and_clause((Node *) qual))
{ {
FastList t_list; List *t_list = NIL;
ListCell *temp; ListCell *temp;
FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args) foreach(temp, ((BoolExpr *) qual)->args)
FastAppend(&t_list, find_nots(lfirst(temp))); t_list = lappend(t_list, find_nots(lfirst(temp)));
return make_andclause(pull_ands(FastListValue(&t_list))); return make_andclause(pull_ands(t_list));
} }
else if (or_clause((Node *) qual)) else if (or_clause((Node *) qual))
{ {
FastList t_list; List *t_list = NIL;
ListCell *temp; ListCell *temp;
FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args) foreach(temp, ((BoolExpr *) qual)->args)
FastAppend(&t_list, find_nots(lfirst(temp))); t_list = lappend(t_list, find_nots(lfirst(temp)));
return make_orclause(pull_ors(FastListValue(&t_list))); return make_orclause(pull_ors(t_list));
} }
else if (not_clause((Node *) qual)) else if (not_clause((Node *) qual))
return push_nots(get_notclausearg(qual)); return push_nots(get_notclausearg(qual));
...@@ -323,23 +313,21 @@ push_nots(Expr *qual) ...@@ -323,23 +313,21 @@ push_nots(Expr *qual)
* i.e., swap AND for OR and negate all the subclauses. * i.e., swap AND for OR and negate all the subclauses.
*-------------------- *--------------------
*/ */
FastList t_list; List *t_list = NIL;
ListCell *temp; ListCell *temp;
FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args) foreach(temp, ((BoolExpr *) qual)->args)
FastAppend(&t_list, push_nots(lfirst(temp))); t_list = lappend(t_list, push_nots(lfirst(temp)));
return make_orclause(pull_ors(FastListValue(&t_list))); return make_orclause(pull_ors(t_list));
} }
else if (or_clause((Node *) qual)) else if (or_clause((Node *) qual))
{ {
FastList t_list; List *t_list = NIL;
ListCell *temp; ListCell *temp;
FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args) foreach(temp, ((BoolExpr *) qual)->args)
FastAppend(&t_list, push_nots(lfirst(temp))); t_list = lappend(t_list, push_nots(lfirst(temp)));
return make_andclause(pull_ands(FastListValue(&t_list))); return make_andclause(pull_ands(t_list));
} }
else if (not_clause((Node *) qual)) else if (not_clause((Node *) qual))
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.172 2004/05/30 23:40:30 neilc Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.173 2004/06/01 04:47:45 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -846,24 +846,21 @@ is_pseudo_constant_clause_relids(Node *clause, Relids relids) ...@@ -846,24 +846,21 @@ is_pseudo_constant_clause_relids(Node *clause, Relids relids)
List * List *
pull_constant_clauses(List *quals, List **constantQual) pull_constant_clauses(List *quals, List **constantQual)
{ {
FastList constqual, List *constqual = NIL,
restqual; *restqual = NIL;
ListCell *q; ListCell *q;
FastListInit(&constqual);
FastListInit(&restqual);
foreach(q, quals) foreach(q, quals)
{ {
Node *qual = (Node *) lfirst(q); Node *qual = (Node *) lfirst(q);
if (is_pseudo_constant_clause(qual)) if (is_pseudo_constant_clause(qual))
FastAppend(&constqual, qual); constqual = lappend(constqual, qual);
else else
FastAppend(&restqual, qual); restqual = lappend(restqual, qual);
} }
*constantQual = FastListValue(&constqual); *constantQual = constqual;
return FastListValue(&restqual); return restqual;
} }
...@@ -1411,7 +1408,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1411,7 +1408,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
CaseExpr *caseexpr = (CaseExpr *) node; CaseExpr *caseexpr = (CaseExpr *) node;
CaseExpr *newcase; CaseExpr *newcase;
Node *newarg; Node *newarg;
FastList newargs; List *newargs;
Node *defresult; Node *defresult;
Const *const_input; Const *const_input;
ListCell *arg; ListCell *arg;
...@@ -1421,7 +1418,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1421,7 +1418,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
active_fns); active_fns);
/* Simplify the WHEN clauses */ /* Simplify the WHEN clauses */
FastListInit(&newargs); newargs = NIL;
foreach(arg, caseexpr->args) foreach(arg, caseexpr->args)
{ {
/* Simplify this alternative's condition and result */ /* Simplify this alternative's condition and result */
...@@ -1434,7 +1431,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1434,7 +1431,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
if (casewhen->expr == NULL || if (casewhen->expr == NULL ||
!IsA(casewhen->expr, Const)) !IsA(casewhen->expr, Const))
{ {
FastAppend(&newargs, casewhen); newargs = lappend(newargs, casewhen);
continue; continue;
} }
const_input = (Const *) casewhen->expr; const_input = (Const *) casewhen->expr;
...@@ -1446,13 +1443,13 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1446,13 +1443,13 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
* Found a TRUE condition. If it's the first (un-dropped) * Found a TRUE condition. If it's the first (un-dropped)
* alternative, the CASE reduces to just this alternative. * alternative, the CASE reduces to just this alternative.
*/ */
if (FastListValue(&newargs) == NIL) if (newargs == NIL)
return (Node *) casewhen->result; return (Node *) casewhen->result;
/* /*
* Otherwise, add it to the list, and drop all the rest. * Otherwise, add it to the list, and drop all the rest.
*/ */
FastAppend(&newargs, casewhen); newargs = lappend(newargs, casewhen);
break; break;
} }
...@@ -1464,13 +1461,13 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1464,13 +1461,13 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
* If no non-FALSE alternatives, CASE reduces to the default * If no non-FALSE alternatives, CASE reduces to the default
* result * result
*/ */
if (FastListValue(&newargs) == NIL) if (newargs == NIL)
return defresult; return defresult;
/* Otherwise we need a new CASE node */ /* Otherwise we need a new CASE node */
newcase = makeNode(CaseExpr); newcase = makeNode(CaseExpr);
newcase->casetype = caseexpr->casetype; newcase->casetype = caseexpr->casetype;
newcase->arg = (Expr *) newarg; newcase->arg = (Expr *) newarg;
newcase->args = FastListValue(&newargs); newcase->args = newargs;
newcase->defresult = (Expr *) defresult; newcase->defresult = (Expr *) defresult;
return (Node *) newcase; return (Node *) newcase;
} }
...@@ -1479,10 +1476,10 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1479,10 +1476,10 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
ArrayExpr *arrayexpr = (ArrayExpr *) node; ArrayExpr *arrayexpr = (ArrayExpr *) node;
ArrayExpr *newarray; ArrayExpr *newarray;
bool all_const = true; bool all_const = true;
FastList newelems; List *newelems;
ListCell *element; ListCell *element;
FastListInit(&newelems); newelems = NIL;
foreach(element, arrayexpr->elements) foreach(element, arrayexpr->elements)
{ {
Node *e; Node *e;
...@@ -1491,13 +1488,13 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1491,13 +1488,13 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
active_fns); active_fns);
if (!IsA(e, Const)) if (!IsA(e, Const))
all_const = false; all_const = false;
FastAppend(&newelems, e); newelems = lappend(newelems, e);
} }
newarray = makeNode(ArrayExpr); newarray = makeNode(ArrayExpr);
newarray->array_typeid = arrayexpr->array_typeid; newarray->array_typeid = arrayexpr->array_typeid;
newarray->element_typeid = arrayexpr->element_typeid; newarray->element_typeid = arrayexpr->element_typeid;
newarray->elements = FastListValue(&newelems); newarray->elements = newelems;
newarray->multidims = arrayexpr->multidims; newarray->multidims = arrayexpr->multidims;
if (all_const) if (all_const)
...@@ -1510,10 +1507,10 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1510,10 +1507,10 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
{ {
CoalesceExpr *coalesceexpr = (CoalesceExpr *) node; CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
CoalesceExpr *newcoalesce; CoalesceExpr *newcoalesce;
FastList newargs; List *newargs;
ListCell *arg; ListCell *arg;
FastListInit(&newargs); newargs = NIL;
foreach(arg, coalesceexpr->args) foreach(arg, coalesceexpr->args)
{ {
Node *e; Node *e;
...@@ -1530,15 +1527,15 @@ eval_const_expressions_mutator(Node *node, List *active_fns) ...@@ -1530,15 +1527,15 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
{ {
if (((Const *) e)->constisnull) if (((Const *) e)->constisnull)
continue; /* drop null constant */ continue; /* drop null constant */
if (FastListValue(&newargs) == NIL) if (newargs == NIL)
return e; /* first expr */ return e; /* first expr */
} }
FastAppend(&newargs, e); newargs = lappend(newargs, e);
} }
newcoalesce = makeNode(CoalesceExpr); newcoalesce = makeNode(CoalesceExpr);
newcoalesce->coalescetype = coalesceexpr->coalescetype; newcoalesce->coalescetype = coalesceexpr->coalescetype;
newcoalesce->args = FastListValue(&newargs); newcoalesce->args = newargs;
return (Node *) newcoalesce; return (Node *) newcoalesce;
} }
if (IsA(node, FieldSelect)) if (IsA(node, FieldSelect))
...@@ -2971,16 +2968,17 @@ expression_tree_mutator(Node *node, ...@@ -2971,16 +2968,17 @@ expression_tree_mutator(Node *node,
* NOTE: this would fail badly on a list with integer * NOTE: this would fail badly on a list with integer
* elements! * elements!
*/ */
FastList resultlist; List *resultlist;
ListCell *temp; ListCell *temp;
FastListInit(&resultlist); resultlist = NIL;
foreach(temp, (List *) node) foreach(temp, (List *) node)
{ {
FastAppend(&resultlist, resultlist = lappend(resultlist,
mutator((Node *) lfirst(temp), context)); mutator((Node *) lfirst(temp),
context));
} }
return (Node *) FastListValue(&resultlist); return (Node *) resultlist;
} }
break; break;
case T_FromExpr: case T_FromExpr:
...@@ -3063,7 +3061,7 @@ query_tree_mutator(Query *query, ...@@ -3063,7 +3061,7 @@ query_tree_mutator(Query *query,
void *context, void *context,
int flags) int flags)
{ {
FastList newrt; List *newrt;
ListCell *rt; ListCell *rt;
Assert(query != NULL && IsA(query, Query)); Assert(query != NULL && IsA(query, Query));
...@@ -3083,7 +3081,7 @@ query_tree_mutator(Query *query, ...@@ -3083,7 +3081,7 @@ query_tree_mutator(Query *query,
MUTATE(query->limitOffset, query->limitOffset, Node *); MUTATE(query->limitOffset, query->limitOffset, Node *);
MUTATE(query->limitCount, query->limitCount, Node *); MUTATE(query->limitCount, query->limitCount, Node *);
MUTATE(query->in_info_list, query->in_info_list, List *); MUTATE(query->in_info_list, query->in_info_list, List *);
FastListInit(&newrt); newrt = NIL;
foreach(rt, query->rtable) foreach(rt, query->rtable)
{ {
RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt); RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
...@@ -3113,9 +3111,9 @@ query_tree_mutator(Query *query, ...@@ -3113,9 +3111,9 @@ query_tree_mutator(Query *query,
MUTATE(newrte->funcexpr, rte->funcexpr, Node *); MUTATE(newrte->funcexpr, rte->funcexpr, Node *);
break; break;
} }
FastAppend(&newrt, newrte); newrt = lappend(newrt, newrte);
} }
query->rtable = FastListValue(&newrt); query->rtable = newrt;
return query; return query;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.93 2004/05/30 23:40:31 neilc Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.94 2004/06/01 04:47:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -192,12 +192,10 @@ build_physical_tlist(Query *root, RelOptInfo *rel) ...@@ -192,12 +192,10 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
Index varno = rel->relid; Index varno = rel->relid;
RangeTblEntry *rte = rt_fetch(varno, root->rtable); RangeTblEntry *rte = rt_fetch(varno, root->rtable);
Relation relation; Relation relation;
FastList tlist; List *tlist = NIL;
int attrno, int attrno,
numattrs; numattrs;
FastListInit(&tlist);
Assert(rte->rtekind == RTE_RELATION); Assert(rte->rtekind == RTE_RELATION);
relation = heap_open(rte->relid, AccessShareLock); relation = heap_open(rte->relid, AccessShareLock);
...@@ -211,11 +209,11 @@ build_physical_tlist(Query *root, RelOptInfo *rel) ...@@ -211,11 +209,11 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
if (att_tup->attisdropped) if (att_tup->attisdropped)
{ {
/* found a dropped col, so punt */ /* found a dropped col, so punt */
FastListInit(&tlist); tlist = NIL;
break; break;
} }
FastAppend(&tlist, tlist = lappend(tlist,
create_tl_element(makeVar(varno, create_tl_element(makeVar(varno,
attrno, attrno,
att_tup->atttypid, att_tup->atttypid,
...@@ -226,7 +224,7 @@ build_physical_tlist(Query *root, RelOptInfo *rel) ...@@ -226,7 +224,7 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
heap_close(relation, AccessShareLock); heap_close(relation, AccessShareLock);
return FastListValue(&tlist); return tlist;
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.58 2004/05/30 23:40:31 neilc Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.59 2004/06/01 04:47:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -43,7 +43,7 @@ typedef struct ...@@ -43,7 +43,7 @@ typedef struct
typedef struct typedef struct
{ {
FastList varlist; List *varlist;
bool includeUpperVars; bool includeUpperVars;
} pull_var_clause_context; } pull_var_clause_context;
...@@ -446,11 +446,11 @@ pull_var_clause(Node *node, bool includeUpperVars) ...@@ -446,11 +446,11 @@ pull_var_clause(Node *node, bool includeUpperVars)
{ {
pull_var_clause_context context; pull_var_clause_context context;
FastListInit(&context.varlist); context.varlist = NIL;
context.includeUpperVars = includeUpperVars; context.includeUpperVars = includeUpperVars;
pull_var_clause_walker(node, &context); pull_var_clause_walker(node, &context);
return FastListValue(&context.varlist); return context.varlist;
} }
static bool static bool
...@@ -461,7 +461,7 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context) ...@@ -461,7 +461,7 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context)
if (IsA(node, Var)) if (IsA(node, Var))
{ {
if (((Var *) node)->varlevelsup == 0 || context->includeUpperVars) if (((Var *) node)->varlevelsup == 0 || context->includeUpperVars)
FastAppend(&context->varlist, node); context->varlist = lappend(context->varlist, node);
return false; return false;
} }
return expression_tree_walker(node, pull_var_clause_walker, return expression_tree_walker(node, pull_var_clause_walker,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment