*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
static List *
group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index)
{
- FastList clausegroup_list;
+ List *clausegroup_list = NIL;
List *restrictinfo_list = rel->baserestrictinfo;
int indexcol = 0;
Oid *classes = index->classlist;
if (restrictinfo_list == NIL)
return NIL;
- FastListInit(&clausegroup_list);
do
{
Oid curClass = classes[0];
- FastList clausegroup;
+ List *clausegroup = NIL;
ListCell *l;
- FastListInit(&clausegroup);
foreach(l, restrictinfo_list)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
indexcol,
curClass,
rinfo))
- FastAppend(&clausegroup, rinfo);
+ clausegroup = lappend(clausegroup, rinfo);
}
/*
* If no clauses match this key, we're done; we don't want to look
* at keys to its right.
*/
- if (FastListValue(&clausegroup) == NIL)
+ if (clausegroup == NIL)
break;
- FastAppend(&clausegroup_list, FastListValue(&clausegroup));
+ clausegroup_list = lappend(clausegroup_list, clausegroup);
indexcol++;
classes++;
} while (!DoneMatchingIndexKeys(classes));
- return FastListValue(&clausegroup_list);
+ return clausegroup_list;
}
/*
Relids outer_relids,
JoinType jointype, bool isouterjoin)
{
- FastList clausegroup_list;
+ List *clausegroup_list = NIL;
bool jfound = false;
int indexcol = 0;
Oid *classes = index->classlist;
- FastListInit(&clausegroup_list);
do
{
Oid curClass = classes[0];
- FastList clausegroup;
+ List *clausegroup = NIL;
int numsources;
ListCell *l;
- FastListInit(&clausegroup);
-
/*
* We can always use plain restriction clauses for the rel. We scan
* these first because we want them first in the clausegroup list
indexcol,
curClass,
rinfo))
- FastAppend(&clausegroup, rinfo);
+ clausegroup = lappend(clausegroup, rinfo);
}
/* 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 */
foreach(l, rel->joininfo)
curClass,
rinfo))
{
- FastAppend(&clausegroup, rinfo);
+ clausegroup = lappend(clausegroup, rinfo);
if (!jfoundhere)
{
jfoundhere = true;
*/
if (numsources > 1)
{
- List *nl;
-
- nl = remove_redundant_join_clauses(root,
- FastListValue(&clausegroup),
- jointype);
- FastListFromList(&clausegroup, nl);
+ clausegroup = remove_redundant_join_clauses(root,
+ clausegroup,
+ jointype);
}
/*
* If no clauses match this key, we're done; we don't want to look
* at keys to its right.
*/
- if (FastListValue(&clausegroup) == NIL)
+ if (clausegroup == NIL)
break;
- FastAppend(&clausegroup_list, FastListValue(&clausegroup));
+ clausegroup_list = lappend(clausegroup_list, clausegroup);
indexcol++;
classes++;
if (!jfound)
return NIL;
- return FastListValue(&clausegroup_list);
+ return clausegroup_list;
}
IndexOptInfo *index,
Expr *orsubclause)
{
- FastList clausegroup_list;
+ List *clausegroup_list = NIL;
bool matched = false;
int indexcol = 0;
Oid *classes = index->classlist;
- FastListInit(&clausegroup_list);
do
{
Oid curClass = classes[0];
- FastList clausegroup;
+ List *clausegroup = NIL;
ListCell *item;
- FastListInit(&clausegroup);
-
/* Try to match the OR subclause to the index key */
if (IsA(orsubclause, RestrictInfo))
{
indexcol, curClass,
(RestrictInfo *) orsubclause))
{
- FastAppend(&clausegroup, orsubclause);
+ clausegroup = lappend(clausegroup, orsubclause);
matched = true;
}
}
indexcol, curClass,
subsubclause))
{
- FastAppend(&clausegroup, subsubclause);
+ clausegroup = lappend(clausegroup, subsubclause);
matched = true;
}
}
* XXX should we always search the top-level list? Slower but
* could sometimes yield a better plan.
*/
- if (FastListValue(&clausegroup) == NIL)
+ if (clausegroup == NIL)
{
foreach(item, rel->baserestrictinfo)
{
if (match_clause_to_indexcol(rel, index,
indexcol, curClass,
rinfo))
- FastAppend(&clausegroup, rinfo);
+ clausegroup = lappend(clausegroup, rinfo);
}
}
* If still no clauses match this key, we're done; we don't want
* to look at keys to its right.
*/
- if (FastListValue(&clausegroup) == NIL)
+ if (clausegroup == NIL)
break;
- FastAppend(&clausegroup_list, FastListValue(&clausegroup));
+ clausegroup_list = lappend(clausegroup_list, clausegroup);
indexcol++;
classes++;
if (!matched)
return NIL;
- return FastListValue(&clausegroup_list);
+ return clausegroup_list;
}
List *
expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
{
- FastList resultquals;
+ List *resultquals = NIL;
ListCell *clausegroup_item;
Oid *classes = index->classlist;
if (clausegroups == NIL)
return NIL;
- FastListInit(&resultquals);
clausegroup_item = list_head(clausegroups);
do
{
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
- FastConc(&resultquals,
- expand_indexqual_condition(rinfo, curClass));
+ resultquals = list_concat(resultquals,
+ expand_indexqual_condition(rinfo,
+ curClass));
}
clausegroup_item = lnext(clausegroup_item);
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;
}
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
RelOptInfo *rel,
List *subclauses)
{
- FastList infos;
- FastList clauses;
- FastList quals;
- Cost path_startup_cost;
- Cost path_total_cost;
+ List *infos = NIL;
+ List *clauses = NIL;
+ List *quals = NIL;
+ Cost path_startup_cost = 0;
+ Cost path_total_cost = 0;
ListCell *slist;
IndexPath *pathnode;
- FastListInit(&infos);
- FastListInit(&clauses);
- FastListInit(&quals);
- path_startup_cost = 0;
- path_total_cost = 0;
-
/* Gather info for each OR subclause */
foreach(slist, subclauses)
{
&best_startup_cost, &best_total_cost))
return NULL; /* failed to match this subclause */
- FastAppend(&infos, best_indexinfo);
- FastAppend(&clauses, best_indexclauses);
- FastAppend(&quals, best_indexquals);
+ infos = lappend(infos, best_indexinfo);
+ clauses = lappend(clauses, best_indexclauses);
+ quals = lappend(quals, best_indexquals);
/*
* 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
*/
pathnode->path.pathkeys = NIL;
- pathnode->indexinfo = FastListValue(&infos);
- pathnode->indexclauses = FastListValue(&clauses);
- pathnode->indexquals = FastListValue(&quals);
+ pathnode->indexinfo = infos;
+ pathnode->indexclauses = clauses;
+ pathnode->indexquals = quals;
/* It's not an innerjoin path. */
pathnode->isjoininner = false;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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 void pull_ands_walker(FastList *out_list, List *andlist);
static List *pull_ors(List *orlist);
-static void pull_ors_walker(FastList *out_list, List *orlist);
static Expr *find_nots(Expr *qual);
static Expr *push_nots(Expr *qual);
static Expr *find_duplicate_ors(Expr *qual);
if (bexpr->boolop == AND_EXPR)
{
- FastList out_list;
+ List *out_list = NIL;
+ ListCell *arg;
- FastListInit(&out_list);
- flatten_andors_and_walker(&out_list, bexpr->args);
- return (Node *) make_andclause(FastListValue(&out_list));
+ foreach(arg, bexpr->args)
+ {
+ 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)
{
- FastList out_list;
+ List *out_list = NIL;
+ ListCell *arg;
- FastListInit(&out_list);
- flatten_andors_or_walker(&out_list, bexpr->args);
- return (Node *) make_orclause(FastListValue(&out_list));
+ foreach(arg, bexpr->args)
+ {
+ 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 */
}
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
* Recursively flatten nested AND clauses into a single and-clause list.
static List *
pull_ands(List *andlist)
{
- FastList out_list;
-
- FastListInit(&out_list);
- pull_ands_walker(&out_list, andlist);
- return FastListValue(&out_list);
-}
-
-static void
-pull_ands_walker(FastList *out_list, List *andlist)
-{
+ List *out_list = NIL;
ListCell *arg;
foreach(arg, andlist)
{
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))
- pull_ands_walker(out_list, ((BoolExpr *) subexpr)->args);
+ out_list = list_concat(out_list,
+ pull_ands(((BoolExpr *) subexpr)->args));
else
- FastAppend(out_list, subexpr);
+ out_list = lappend(out_list, subexpr);
}
+ return out_list;
}
/*
static List *
pull_ors(List *orlist)
{
- FastList out_list;
-
- FastListInit(&out_list);
- pull_ors_walker(&out_list, orlist);
- return FastListValue(&out_list);
-}
-
-static void
-pull_ors_walker(FastList *out_list, List *orlist)
-{
+ List *out_list = NIL;
ListCell *arg;
foreach(arg, orlist)
{
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))
- pull_ors_walker(out_list, ((BoolExpr *) subexpr)->args);
+ out_list = list_concat(out_list,
+ pull_ors(((BoolExpr *) subexpr)->args));
else
- FastAppend(out_list, subexpr);
+ out_list = lappend(out_list, subexpr);
}
+ return out_list;
}
if (and_clause((Node *) qual))
{
- FastList t_list;
+ List *t_list = NIL;
ListCell *temp;
- FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args)
- FastAppend(&t_list, find_nots(lfirst(temp)));
- return make_andclause(pull_ands(FastListValue(&t_list)));
+ t_list = lappend(t_list, find_nots(lfirst(temp)));
+ return make_andclause(pull_ands(t_list));
}
else if (or_clause((Node *) qual))
{
- FastList t_list;
+ List *t_list = NIL;
ListCell *temp;
- FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args)
- FastAppend(&t_list, find_nots(lfirst(temp)));
- return make_orclause(pull_ors(FastListValue(&t_list)));
+ t_list = lappend(t_list, find_nots(lfirst(temp)));
+ return make_orclause(pull_ors(t_list));
}
else if (not_clause((Node *) qual))
return push_nots(get_notclausearg(qual));
* i.e., swap AND for OR and negate all the subclauses.
*--------------------
*/
- FastList t_list;
+ List *t_list = NIL;
ListCell *temp;
- FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args)
- FastAppend(&t_list, push_nots(lfirst(temp)));
- return make_orclause(pull_ors(FastListValue(&t_list)));
+ t_list = lappend(t_list, push_nots(lfirst(temp)));
+ return make_orclause(pull_ors(t_list));
}
else if (or_clause((Node *) qual))
{
- FastList t_list;
+ List *t_list = NIL;
ListCell *temp;
- FastListInit(&t_list);
foreach(temp, ((BoolExpr *) qual)->args)
- FastAppend(&t_list, push_nots(lfirst(temp)));
- return make_andclause(pull_ands(FastListValue(&t_list)));
+ t_list = lappend(t_list, push_nots(lfirst(temp)));
+ return make_andclause(pull_ands(t_list));
}
else if (not_clause((Node *) qual))
{
*
*
* 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
* AUTHOR DATE MAJOR EVENT
List *
pull_constant_clauses(List *quals, List **constantQual)
{
- FastList constqual,
- restqual;
+ List *constqual = NIL,
+ *restqual = NIL;
ListCell *q;
- FastListInit(&constqual);
- FastListInit(&restqual);
-
foreach(q, quals)
{
Node *qual = (Node *) lfirst(q);
if (is_pseudo_constant_clause(qual))
- FastAppend(&constqual, qual);
+ constqual = lappend(constqual, qual);
else
- FastAppend(&restqual, qual);
+ restqual = lappend(restqual, qual);
}
- *constantQual = FastListValue(&constqual);
- return FastListValue(&restqual);
+ *constantQual = constqual;
+ return restqual;
}
CaseExpr *caseexpr = (CaseExpr *) node;
CaseExpr *newcase;
Node *newarg;
- FastList newargs;
+ List *newargs;
Node *defresult;
Const *const_input;
ListCell *arg;
active_fns);
/* Simplify the WHEN clauses */
- FastListInit(&newargs);
+ newargs = NIL;
foreach(arg, caseexpr->args)
{
/* Simplify this alternative's condition and result */
if (casewhen->expr == NULL ||
!IsA(casewhen->expr, Const))
{
- FastAppend(&newargs, casewhen);
+ newargs = lappend(newargs, casewhen);
continue;
}
const_input = (Const *) casewhen->expr;
* Found a TRUE condition. If it's the first (un-dropped)
* alternative, the CASE reduces to just this alternative.
*/
- if (FastListValue(&newargs) == NIL)
+ if (newargs == NIL)
return (Node *) casewhen->result;
/*
* Otherwise, add it to the list, and drop all the rest.
*/
- FastAppend(&newargs, casewhen);
+ newargs = lappend(newargs, casewhen);
break;
}
* If no non-FALSE alternatives, CASE reduces to the default
* result
*/
- if (FastListValue(&newargs) == NIL)
+ if (newargs == NIL)
return defresult;
/* Otherwise we need a new CASE node */
newcase = makeNode(CaseExpr);
newcase->casetype = caseexpr->casetype;
newcase->arg = (Expr *) newarg;
- newcase->args = FastListValue(&newargs);
+ newcase->args = newargs;
newcase->defresult = (Expr *) defresult;
return (Node *) newcase;
}
ArrayExpr *arrayexpr = (ArrayExpr *) node;
ArrayExpr *newarray;
bool all_const = true;
- FastList newelems;
+ List *newelems;
ListCell *element;
- FastListInit(&newelems);
+ newelems = NIL;
foreach(element, arrayexpr->elements)
{
Node *e;
active_fns);
if (!IsA(e, Const))
all_const = false;
- FastAppend(&newelems, e);
+ newelems = lappend(newelems, e);
}
newarray = makeNode(ArrayExpr);
newarray->array_typeid = arrayexpr->array_typeid;
newarray->element_typeid = arrayexpr->element_typeid;
- newarray->elements = FastListValue(&newelems);
+ newarray->elements = newelems;
newarray->multidims = arrayexpr->multidims;
if (all_const)
{
CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
CoalesceExpr *newcoalesce;
- FastList newargs;
+ List *newargs;
ListCell *arg;
- FastListInit(&newargs);
+ newargs = NIL;
foreach(arg, coalesceexpr->args)
{
Node *e;
{
if (((Const *) e)->constisnull)
continue; /* drop null constant */
- if (FastListValue(&newargs) == NIL)
+ if (newargs == NIL)
return e; /* first expr */
}
- FastAppend(&newargs, e);
+ newargs = lappend(newargs, e);
}
newcoalesce = makeNode(CoalesceExpr);
newcoalesce->coalescetype = coalesceexpr->coalescetype;
- newcoalesce->args = FastListValue(&newargs);
+ newcoalesce->args = newargs;
return (Node *) newcoalesce;
}
if (IsA(node, FieldSelect))
* NOTE: this would fail badly on a list with integer
* elements!
*/
- FastList resultlist;
+ List *resultlist;
ListCell *temp;
- FastListInit(&resultlist);
+ resultlist = NIL;
foreach(temp, (List *) node)
{
- FastAppend(&resultlist,
- mutator((Node *) lfirst(temp), context));
+ resultlist = lappend(resultlist,
+ mutator((Node *) lfirst(temp),
+ context));
}
- return (Node *) FastListValue(&resultlist);
+ return (Node *) resultlist;
}
break;
case T_FromExpr:
void *context,
int flags)
{
- FastList newrt;
+ List *newrt;
ListCell *rt;
Assert(query != NULL && IsA(query, Query));
MUTATE(query->limitOffset, query->limitOffset, Node *);
MUTATE(query->limitCount, query->limitCount, Node *);
MUTATE(query->in_info_list, query->in_info_list, List *);
- FastListInit(&newrt);
+ newrt = NIL;
foreach(rt, query->rtable)
{
RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
MUTATE(newrte->funcexpr, rte->funcexpr, Node *);
break;
}
- FastAppend(&newrt, newrte);
+ newrt = lappend(newrt, newrte);
}
- query->rtable = FastListValue(&newrt);
+ query->rtable = newrt;
return query;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
Index varno = rel->relid;
RangeTblEntry *rte = rt_fetch(varno, root->rtable);
Relation relation;
- FastList tlist;
+ List *tlist = NIL;
int attrno,
numattrs;
- FastListInit(&tlist);
-
Assert(rte->rtekind == RTE_RELATION);
relation = heap_open(rte->relid, AccessShareLock);
if (att_tup->attisdropped)
{
/* found a dropped col, so punt */
- FastListInit(&tlist);
+ tlist = NIL;
break;
}
- FastAppend(&tlist,
+ tlist = lappend(tlist,
create_tl_element(makeVar(varno,
attrno,
att_tup->atttypid,
heap_close(relation, AccessShareLock);
- return FastListValue(&tlist);
+ return tlist;
}
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
typedef struct
{
- FastList varlist;
+ List *varlist;
bool includeUpperVars;
} pull_var_clause_context;
{
pull_var_clause_context context;
- FastListInit(&context.varlist);
+ context.varlist = NIL;
context.includeUpperVars = includeUpperVars;
pull_var_clause_walker(node, &context);
- return FastListValue(&context.varlist);
+ return context.varlist;
}
static bool
if (IsA(node, Var))
{
if (((Var *) node)->varlevelsup == 0 || context->includeUpperVars)
- FastAppend(&context->varlist, node);
+ context->varlist = lappend(context->varlist, node);
return false;
}
return expression_tree_walker(node, pull_var_clause_walker,