]> granicus.if.org Git - postgresql/blobdiff - src/backend/optimizer/plan/initsplan.c
Remove planner's private fields from Query struct, and put them into
[postgresql] / src / backend / optimizer / plan / initsplan.c
index f8a4bfaaac48504f1e0e7e9f6418840c9ab0fc53..c5b027637988da2cf87f702aa38540dc1610dd1d 100644 (file)
@@ -3,12 +3,12 @@
  * initsplan.c
  *       Target list, qualification, joininfo initialization routines
  *
- * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.99 2004/05/26 04:41:24 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.106 2005/06/05 22:32:55 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "utils/syscache.h"
 
 
-static void mark_baserels_for_outer_join(Query *root, Relids rels,
+static void mark_baserels_for_outer_join(PlannerInfo *root, Relids rels,
                                                         Relids outerrels);
-static void distribute_qual_to_rels(Query *root, Node *clause,
+static void distribute_qual_to_rels(PlannerInfo *root, Node *clause,
                                                bool is_pushed_down,
                                                bool isdeduced,
                                                Relids outerjoin_nonnullable,
                                                Relids qualscope);
-static void add_vars_to_targetlist(Query *root, List *vars,
+static void add_vars_to_targetlist(PlannerInfo *root, List *vars,
                                           Relids where_needed);
-static bool qual_is_redundant(Query *root, RestrictInfo *restrictinfo,
+static bool qual_is_redundant(PlannerInfo *root, RestrictInfo *restrictinfo,
                                  List *restrictlist);
 static void check_mergejoinable(RestrictInfo *restrictinfo);
 static void check_hashjoinable(RestrictInfo *restrictinfo);
@@ -68,7 +68,7 @@ static void check_hashjoinable(RestrictInfo *restrictinfo);
  * will be used later to build rels for inheritance children.
  */
 void
-add_base_rels_to_query(Query *root, Node *jtnode)
+add_base_rels_to_query(PlannerInfo *root, Node *jtnode)
 {
        if (jtnode == NULL)
                return;
@@ -114,14 +114,14 @@ add_base_rels_to_query(Query *root, Node *jtnode)
  * propagate up through all join plan steps.
  */
 void
-build_base_rel_tlists(Query *root, List *final_tlist)
+build_base_rel_tlists(PlannerInfo *root, List *final_tlist)
 {
        List       *tlist_vars = pull_var_clause((Node *) final_tlist, false);
 
        if (tlist_vars != NIL)
        {
                add_vars_to_targetlist(root, tlist_vars, bms_make_singleton(0));
-               freeList(tlist_vars);
+               list_free(tlist_vars);
        }
 }
 
@@ -133,7 +133,7 @@ build_base_rel_tlists(Query *root, List *final_tlist)
  *       where_needed includes "relation 0").
  */
 static void
-add_vars_to_targetlist(Query *root, List *vars, Relids where_needed)
+add_vars_to_targetlist(PlannerInfo *root, List *vars, Relids where_needed)
 {
        ListCell   *temp;
 
@@ -151,7 +151,7 @@ add_vars_to_targetlist(Query *root, List *vars, Relids where_needed)
                {
                        /* Variable not yet requested, so add to reltargetlist */
                        /* XXX is copyObject necessary here? */
-                       FastAppend(&rel->reltargetlist, copyObject(var));
+                       rel->reltargetlist = lappend(rel->reltargetlist, copyObject(var));
                }
                rel->attr_needed[attrno] = bms_add_members(rel->attr_needed[attrno],
                                                                                                   where_needed);
@@ -189,7 +189,7 @@ add_vars_to_targetlist(Query *root, List *vars, Relids where_needed)
  * internal convenience; no outside callers pay attention to the result.
  */
 Relids
-distribute_quals_to_rels(Query *root, Node *jtnode)
+distribute_quals_to_rels(PlannerInfo *root, Node *jtnode)
 {
        Relids          result = NULL;
 
@@ -306,7 +306,7 @@ distribute_quals_to_rels(Query *root, Node *jtnode)
  *       Mark all base rels listed in 'rels' as having the given outerjoinset.
  */
 static void
-mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
+mark_baserels_for_outer_join(PlannerInfo *root, Relids rels, Relids outerrels)
 {
        Relids          tmprelids;
        int                     relno;
@@ -323,20 +323,20 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
                Assert(bms_is_subset(rel->outerjoinset, outerrels));
 
                /*
-                * Presently the executor cannot support FOR UPDATE marking of
+                * Presently the executor cannot support FOR UPDATE/SHARE marking of
                 * rels appearing on the nullable side of an outer join. (It's
                 * somewhat unclear what that would mean, anyway: what should we
                 * mark when a result row is generated from no element of the
-                * nullable relation?)  So, complain if target rel is FOR UPDATE.
+                * nullable relation?)  So, complain if target rel is FOR UPDATE/SHARE.
                 * It's sufficient to make this check once per rel, so do it only
                 * if rel wasn't already known nullable.
                 */
                if (rel->outerjoinset == NULL)
                {
-                       if (intMember(relno, root->rowMarks))
+                       if (list_member_int(root->parse->rowMarks, relno))
                                ereport(ERROR,
                                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                                errmsg("SELECT FOR UPDATE cannot be applied to the nullable side of an outer join")));
+                                                errmsg("SELECT FOR UPDATE/SHARE cannot be applied to the nullable side of an outer join")));
                }
 
                rel->outerjoinset = outerrels;
@@ -367,7 +367,7 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
  * 'is_pushed_down' will be TRUE.
  */
 static void
-distribute_qual_to_rels(Query *root, Node *clause,
+distribute_qual_to_rels(PlannerInfo *root, Node *clause,
                                                bool is_pushed_down,
                                                bool isdeduced,
                                                Relids outerjoin_nonnullable,
@@ -451,8 +451,9 @@ distribute_qual_to_rels(Query *root, Node *clause,
                 * tree.
                 *
                 * We also need to determine whether the qual is "valid everywhere",
-                * which is true if the qual mentions no variables that are involved
-                * in lower-level outer joins (this may be an overly strong test).
+                * which is true if the qual mentions no variables that are
+                * involved in lower-level outer joins (this may be an overly
+                * strong test).
                 */
                Relids          addrelids = NULL;
                Relids          tmprelids;
@@ -585,7 +586,7 @@ distribute_qual_to_rels(Query *root, Node *clause,
                         */
                        vars = pull_var_clause(clause, false);
                        add_vars_to_targetlist(root, vars, relids);
-                       freeList(vars);
+                       list_free(vars);
                        break;
                default:
 
@@ -625,7 +626,7 @@ distribute_qual_to_rels(Query *root, Node *clause,
  * for more details.
  */
 void
-process_implied_equality(Query *root,
+process_implied_equality(PlannerInfo *root,
                                                 Node *item1, Node *item2,
                                                 Oid sortop1, Oid sortop2,
                                                 Relids item1_relids, Relids item2_relids,
@@ -705,8 +706,8 @@ process_implied_equality(Query *root,
                                if (membership == BMS_SINGLETON)
                                {
                                        /* delete it from local restrictinfo list */
-                                       rel1->baserestrictinfo = lremove(restrictinfo,
-                                                                                                rel1->baserestrictinfo);
+                                       rel1->baserestrictinfo = list_delete_ptr(rel1->baserestrictinfo,
+                                                                                                                  restrictinfo);
                                }
                                else
                                {
@@ -728,7 +729,7 @@ process_implied_equality(Query *root,
         */
        ltype = exprType(item1);
        rtype = exprType(item2);
-       eq_operator = compatible_oper(makeList1(makeString("=")),
+       eq_operator = compatible_oper(list_make1(makeString("=")),
                                                                  ltype, rtype, true);
        if (!HeapTupleIsValid(eq_operator))
        {
@@ -795,7 +796,7 @@ process_implied_equality(Query *root,
  * all the "var = const" quals.
  */
 static bool
-qual_is_redundant(Query *root,
+qual_is_redundant(PlannerInfo *root,
                                  RestrictInfo *restrictinfo,
                                  List *restrictlist)
 {
@@ -854,11 +855,11 @@ qual_is_redundant(Query *root,
         * done.  We give up when we can't expand the equalexprs list any
         * more.
         */
-       equalexprs = makeList1(newleft);
+       equalexprs = list_make1(newleft);
        do
        {
                someadded = false;
-               /* cannot use foreach here because of possible lremove */
+               /* cannot use foreach here because of possible list_delete */
                olditem = list_head(oldquals);
                while (olditem)
                {
@@ -867,12 +868,12 @@ qual_is_redundant(Query *root,
                        Node       *oldright = get_rightop(oldrinfo->clause);
                        Node       *newguy = NULL;
 
-                       /* must advance olditem before lremove possibly pfree's it */
+                       /* must advance olditem before list_delete possibly pfree's it */
                        olditem = lnext(olditem);
 
-                       if (member(oldleft, equalexprs))
+                       if (list_member(equalexprs, oldleft))
                                newguy = oldright;
-                       else if (member(oldright, equalexprs))
+                       else if (list_member(equalexprs, oldright))
                                newguy = oldleft;
                        else
                                continue;
@@ -884,7 +885,7 @@ qual_is_redundant(Query *root,
                        /*
                         * Remove this qual from list, since we don't need it anymore.
                         */
-                       oldquals = lremove(oldrinfo, oldquals);
+                       oldquals = list_delete_ptr(oldquals, oldrinfo);
                }
        } while (someadded);
 
@@ -917,7 +918,7 @@ check_mergejoinable(RestrictInfo *restrictinfo)
 
        if (!is_opclause(clause))
                return;
-       if (length(((OpExpr *) clause)->args) != 2)
+       if (list_length(((OpExpr *) clause)->args) != 2)
                return;
 
        opno = ((OpExpr *) clause)->opno;
@@ -950,7 +951,7 @@ check_hashjoinable(RestrictInfo *restrictinfo)
 
        if (!is_opclause(clause))
                return;
-       if (length(((OpExpr *) clause)->args) != 2)
+       if (list_length(((OpExpr *) clause)->args) != 2)
                return;
 
        opno = ((OpExpr *) clause)->opno;