*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.52 2003/08/04 02:40:01 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.59 2004/06/01 03:03:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
void
build_base_rel(Query *root, int relid)
{
- List *rels;
+ ListCell *l;
RelOptInfo *rel;
/* Rel should not exist already */
- foreach(rels, root->base_rel_list)
+ foreach(l, root->base_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
elog(ERROR, "rel already exists");
}
/* It should not exist as an "other" rel, either */
- foreach(rels, root->other_rel_list)
+ foreach(l, root->other_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
elog(ERROR, "rel already exists as \"other\" rel");
}
RelOptInfo *
build_other_rel(Query *root, int relid)
{
- List *rels;
+ ListCell *l;
RelOptInfo *rel;
/* Already made? */
- foreach(rels, root->other_rel_list)
+ foreach(l, root->other_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
return rel;
}
/* It should not exist as a base rel */
- foreach(rels, root->base_rel_list)
+ foreach(l, root->base_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
elog(ERROR, "rel already exists as base rel");
}
rel->relids = bms_make_singleton(relid);
rel->rows = 0;
rel->width = 0;
- FastListInit(&rel->reltargetlist);
+ rel->reltargetlist = NIL;
rel->pathlist = NIL;
rel->cheapest_startup_path = NULL;
rel->cheapest_total_path = NULL;
rel->cheapest_unique_path = NULL;
- rel->pruneable = true;
rel->relid = relid;
rel->rtekind = rte->rtekind;
/* min_attr, max_attr, attr_needed, attr_widths are set below */
case RTE_SUBQUERY:
case RTE_FUNCTION:
/* Subquery or function --- need only set up attr range */
- rel->min_attr = 1;
- rel->max_attr = length(rte->eref->colnames);
+ /* Note: 0 is included in range to support whole-row Vars */
+ rel->min_attr = 0;
+ rel->max_attr = list_length(rte->eref->colnames);
break;
default:
elog(ERROR, "unrecognized RTE kind: %d",
break;
}
- if (rel->max_attr >= rel->min_attr)
- {
- rel->attr_needed = (Relids *)
- palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
- rel->attr_widths = (int32 *)
- palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
- }
- else
- {
- rel->attr_needed = NULL;
- rel->attr_widths = NULL;
- }
+ Assert(rel->max_attr >= rel->min_attr);
+ rel->attr_needed = (Relids *)
+ palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
+ rel->attr_widths = (int32 *)
+ palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
return rel;
}
RelOptInfo *
find_base_rel(Query *root, int relid)
{
- List *rels;
+ ListCell *l;
RelOptInfo *rel;
- foreach(rels, root->base_rel_list)
+ foreach(l, root->base_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
return rel;
}
- foreach(rels, root->other_rel_list)
+ foreach(l, root->other_rel_list)
{
- rel = (RelOptInfo *) lfirst(rels);
+ rel = (RelOptInfo *) lfirst(l);
if (relid == rel->relid)
return rel;
}
* find_join_rel
* Returns relation entry corresponding to 'relids' (a set of RT indexes),
* or NULL if none exists. This is for join relations.
- *
- * Note: there is probably no good reason for this to be called from
- * anywhere except build_join_rel, but keep it as a separate routine
- * just in case.
*/
-static RelOptInfo *
+RelOptInfo *
find_join_rel(Query *root, Relids relids)
{
- List *joinrels;
+ ListCell *l;
- foreach(joinrels, root->join_rel_list)
+ foreach(l, root->join_rel_list)
{
- RelOptInfo *rel = (RelOptInfo *) lfirst(joinrels);
+ RelOptInfo *rel = (RelOptInfo *) lfirst(l);
if (bms_equal(rel->relids, relids))
return rel;
joinrel->relids = bms_copy(joinrelids);
joinrel->rows = 0;
joinrel->width = 0;
- FastListInit(&joinrel->reltargetlist);
+ joinrel->reltargetlist = NIL;
joinrel->pathlist = NIL;
joinrel->cheapest_startup_path = NULL;
joinrel->cheapest_total_path = NULL;
joinrel->cheapest_unique_path = NULL;
- joinrel->pruneable = true;
joinrel->relid = 0; /* indicates not a baserel */
joinrel->rtekind = RTE_JOIN;
joinrel->min_attr = 0;
build_joinrel_tlist(Query *root, RelOptInfo *joinrel)
{
Relids relids = joinrel->relids;
- List *rels;
- List *vars;
+ ListCell *rels;
- FastListInit(&joinrel->reltargetlist);
+ joinrel->reltargetlist = NIL;
joinrel->width = 0;
foreach(rels, root->base_rel_list)
{
RelOptInfo *baserel = (RelOptInfo *) lfirst(rels);
+ ListCell *vars;
if (!bms_is_member(baserel->relid, relids))
continue;
- foreach(vars, FastListValue(&baserel->reltargetlist))
+ foreach(vars, baserel->reltargetlist)
{
Var *var = (Var *) lfirst(vars);
int ndx = var->varattno - baserel->min_attr;
if (bms_nonempty_difference(baserel->attr_needed[ndx], relids))
{
- FastAppend(&joinrel->reltargetlist, var);
+ joinrel->reltargetlist = lappend(joinrel->reltargetlist, var);
Assert(baserel->attr_widths[ndx] > 0);
joinrel->width += baserel->attr_widths[ndx];
}
/*
* Collect all the clauses that syntactically belong at this level.
*/
- rlist = nconc(subbuild_joinrel_restrictlist(joinrel,
- outer_rel->joininfo),
- subbuild_joinrel_restrictlist(joinrel,
- inner_rel->joininfo));
+ rlist = list_concat(subbuild_joinrel_restrictlist(joinrel,
+ outer_rel->joininfo),
+ subbuild_joinrel_restrictlist(joinrel,
+ inner_rel->joininfo));
/*
* Eliminate duplicate and redundant clauses.
*/
result = remove_redundant_join_clauses(root, rlist, jointype);
- freeList(rlist);
+ list_free(rlist);
return result;
}
List *joininfo_list)
{
List *restrictlist = NIL;
- List *xjoininfo;
+ ListCell *xjoininfo;
foreach(xjoininfo, joininfo_list)
{
* We must copy the list to avoid disturbing the input relation,
* but we can use a shallow copy.
*/
- restrictlist = nconc(restrictlist,
- listCopy(joininfo->jinfo_restrictinfo));
+ restrictlist = list_concat(restrictlist,
+ list_copy(joininfo->jinfo_restrictinfo));
}
else
{
subbuild_joinrel_joinlist(RelOptInfo *joinrel,
List *joininfo_list)
{
- List *xjoininfo;
+ ListCell *xjoininfo;
foreach(xjoininfo, joininfo_list)
{
new_joininfo = make_joininfo_node(joinrel, new_unjoined_relids);
new_joininfo->jinfo_restrictinfo =
- set_ptrUnion(new_joininfo->jinfo_restrictinfo,
- joininfo->jinfo_restrictinfo);
+ list_union_ptr(new_joininfo->jinfo_restrictinfo,
+ joininfo->jinfo_restrictinfo);
}
}
}