Attached is a small patch which improves the way get_base_rel_indexes()
works.

The current version creates a new bitmapset on each recursion level then
bms_joins() to the one on the next level up each time. I understand that
this will patch will have about a 0 net performance improvement, but I
thought I'd post anyway as:

1. It removes 5 lines of code.
2. It's a better example to leave in the code.

Is it worth applying?

Regards

David Rowley
--
 David Rowley                   http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/>
 PostgreSQL Development, 24x7 Support, Training & Services
diff --git a/src/backend/optimizer/plan/planner.c 
b/src/backend/optimizer/plan/planner.c
index d598c1b..926a41a 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -2638,43 +2638,38 @@ is_dummy_plan(Plan *plan)
  * the only good way to distinguish baserels from appendrel children
  * is to see what is in the join tree.
  */
-static Bitmapset *
-get_base_rel_indexes(Node *jtnode)
+static void
+get_base_rel_indexes(Node *jtnode, Bitmapset **result)
 {
-       Bitmapset  *result;
 
        if (jtnode == NULL)
-               return NULL;
+               return;
        if (IsA(jtnode, RangeTblRef))
        {
                int                     varno = ((RangeTblRef *) 
jtnode)->rtindex;
 
-               result = bms_make_singleton(varno);
+               *result = bms_add_member(*result, varno);
        }
        else if (IsA(jtnode, FromExpr))
        {
                FromExpr   *f = (FromExpr *) jtnode;
                ListCell   *l;
 
-               result = NULL;
                foreach(l, f->fromlist)
-                       result = bms_join(result,
-                                                         
get_base_rel_indexes(lfirst(l)));
+                       get_base_rel_indexes(lfirst(l), result);
        }
        else if (IsA(jtnode, JoinExpr))
        {
                JoinExpr   *j = (JoinExpr *) jtnode;
 
-               result = bms_join(get_base_rel_indexes(j->larg),
-                                                 
get_base_rel_indexes(j->rarg));
+               get_base_rel_indexes(j->larg, result);
+               get_base_rel_indexes(j->rarg, result);
        }
        else
        {
                elog(ERROR, "unrecognized node type: %d",
                         (int) nodeTag(jtnode));
-               result = NULL;                  /* keep compiler quiet */
        }
-       return result;
 }
 
 /*
@@ -2684,7 +2679,7 @@ static void
 preprocess_rowmarks(PlannerInfo *root)
 {
        Query      *parse = root->parse;
-       Bitmapset  *rels;
+       Bitmapset  *rels = NULL;
        List       *prowmarks;
        ListCell   *l;
        int                     i;
@@ -2716,7 +2711,7 @@ preprocess_rowmarks(PlannerInfo *root)
         * make a bitmapset of all base rels and then remove the items we don't
         * need or have FOR [KEY] UPDATE/SHARE marks for.
         */
-       rels = get_base_rel_indexes((Node *) parse->jointree);
+       get_base_rel_indexes((Node *) parse->jointree, &rels);
        if (parse->resultRelation)
                rels = bms_del_member(rels, parse->resultRelation);
 
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to