]> granicus.if.org Git - postgresql/blobdiff - src/backend/optimizer/util/relnode.c
Desultory de-FastList-ification. RelOptInfo.reltargetlist is back to
[postgresql] / src / backend / optimizer / util / relnode.c
index 9a4a2069765f28d2ef9c439b5fb86ed90c67de2f..36e688135a8cb9c1ea1c5f2b3ce1c7e96eacd414 100644 (file)
@@ -3,12 +3,12 @@
  * relnode.c
  *       Relation-node lookup/construction routines
  *
- * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.50 2003/07/25 00:01:08 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.59 2004/06/01 03:03:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -47,21 +47,21 @@ static void subbuild_joinrel_joinlist(RelOptInfo *joinrel,
 void
 build_base_rel(Query *root, int relid)
 {
-       List       *rels;
+       ListCell   *l;
        RelOptInfo *rel;
 
        /* Rel should not exist already */
-       foreach(rels, root->base_rel_list)
+       foreach(l, root->base_rel_list)
        {
-               rel = (RelOptInfo *) lfirst(rels);
+               rel = (RelOptInfo *) lfirst(l);
                if (relid == rel->relid)
                        elog(ERROR, "rel already exists");
        }
 
        /* It should not exist as an "other" rel, either */
-       foreach(rels, root->other_rel_list)
+       foreach(l, root->other_rel_list)
        {
-               rel = (RelOptInfo *) lfirst(rels);
+               rel = (RelOptInfo *) lfirst(l);
                if (relid == rel->relid)
                        elog(ERROR, "rel already exists as \"other\" rel");
        }
@@ -82,21 +82,21 @@ build_base_rel(Query *root, int relid)
 RelOptInfo *
 build_other_rel(Query *root, int relid)
 {
-       List       *rels;
+       ListCell   *l;
        RelOptInfo *rel;
 
        /* Already made? */
-       foreach(rels, root->other_rel_list)
+       foreach(l, root->other_rel_list)
        {
-               rel = (RelOptInfo *) lfirst(rels);
+               rel = (RelOptInfo *) lfirst(l);
                if (relid == rel->relid)
                        return rel;
        }
 
        /* It should not exist as a base rel */
-       foreach(rels, root->base_rel_list)
+       foreach(l, root->base_rel_list)
        {
-               rel = (RelOptInfo *) lfirst(rels);
+               rel = (RelOptInfo *) lfirst(l);
                if (relid == rel->relid)
                        elog(ERROR, "rel already exists as base rel");
        }
@@ -130,12 +130,11 @@ make_base_rel(Query *root, int relid)
        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 */
@@ -161,8 +160,9 @@ make_base_rel(Query *root, int relid)
                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",
@@ -170,18 +170,11 @@ make_base_rel(Query *root, int relid)
                        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;
 }
@@ -194,19 +187,19 @@ make_base_rel(Query *root, int relid)
 RelOptInfo *
 find_base_rel(Query *root, int relid)
 {
-       List       *rels;
+       ListCell   *l;
        RelOptInfo *rel;
 
-       foreach(rels, root->base_rel_list)
+       foreach(l, root->base_rel_list)
        {
-               rel = (RelOptInfo *) lfirst(rels);
+               rel = (RelOptInfo *) lfirst(l);
                if (relid == rel->relid)
                        return rel;
        }
 
-       foreach(rels, root->other_rel_list)
+       foreach(l, root->other_rel_list)
        {
-               rel = (RelOptInfo *) lfirst(rels);
+               rel = (RelOptInfo *) lfirst(l);
                if (relid == rel->relid)
                        return rel;
        }
@@ -220,19 +213,15 @@ find_base_rel(Query *root, int relid)
  * 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;
@@ -296,12 +285,11 @@ build_join_rel(Query *root,
        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;
@@ -322,7 +310,8 @@ build_join_rel(Query *root,
 
        /*
         * Create a new tlist containing just the vars that need to be output
-        * from this join (ie, are needed for higher joinclauses or final output).
+        * from this join (ie, are needed for higher joinclauses or final
+        * output).
         */
        build_joinrel_tlist(root, joinrel);
 
@@ -374,27 +363,27 @@ static void
 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;
+                       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];
                        }
@@ -457,10 +446,10 @@ build_joinrel_restrictlist(Query *root,
        /*
         * 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.
@@ -473,7 +462,7 @@ build_joinrel_restrictlist(Query *root,
         */
        result = remove_redundant_join_clauses(root, rlist, jointype);
 
-       freeList(rlist);
+       list_free(rlist);
 
        return result;
 }
@@ -492,7 +481,7 @@ subbuild_joinrel_restrictlist(RelOptInfo *joinrel,
                                                          List *joininfo_list)
 {
        List       *restrictlist = NIL;
-       List       *xjoininfo;
+       ListCell   *xjoininfo;
 
        foreach(xjoininfo, joininfo_list)
        {
@@ -507,8 +496,8 @@ subbuild_joinrel_restrictlist(RelOptInfo *joinrel,
                         * 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
                {
@@ -526,7 +515,7 @@ static void
 subbuild_joinrel_joinlist(RelOptInfo *joinrel,
                                                  List *joininfo_list)
 {
-       List       *xjoininfo;
+       ListCell   *xjoininfo;
 
        foreach(xjoininfo, joininfo_list)
        {
@@ -560,8 +549,8 @@ subbuild_joinrel_joinlist(RelOptInfo *joinrel,
 
                        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);
                }
        }
 }