Replace slightly klugy create_bitmap_restriction() function with a
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 25 Apr 2005 02:14:48 +0000 (02:14 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 25 Apr 2005 02:14:48 +0000 (02:14 +0000)
more efficient routine in restrictinfo.c (which can make use of
make_restrictinfo_internal).

src/backend/optimizer/path/orindxpath.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/util/restrictinfo.c
src/include/optimizer/planmain.h
src/include/optimizer/restrictinfo.h

index fb055400d41a3c759712e0f7ae84b168abb01c98..5ea528ef26e46b2405269e06ccee8434b1b826cc 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.69 2005/04/25 01:30:13 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.70 2005/04/25 02:14:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -146,7 +146,8 @@ create_or_index_quals(Query *root, RelOptInfo *rel)
         * Convert the path's indexclauses structure to a RestrictInfo tree,
         * and add it to the rel's restriction list.
         */
-       newrinfos = create_bitmap_restriction((Path *) bestpath);
+       newrinfos = make_restrictinfo_from_bitmapqual((Path *) bestpath,
+                                                                                                 true, true);
        Assert(list_length(newrinfos) == 1);
        or_rinfo = (RestrictInfo *) linitial(newrinfos);
        Assert(IsA(or_rinfo, RestrictInfo));
index 0ce65a93d192c2a66a316aca8ee56bdc7230fb62..8c06278f8fedd327be1496e855320b80edb9c109 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.185 2005/04/25 01:30:13 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.186 2005/04/25 02:14:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -54,7 +54,6 @@ static BitmapHeapScan *create_bitmap_scan_plan(Query *root,
                                                                                           List *tlist, List *scan_clauses);
 static Plan *create_bitmap_subplan(Query *root, Path *bitmapqual,
                                                                   List **qual, List **indexqual);
-static List *create_bitmap_qual(Path *bitmapqual);
 static TidScan *create_tidscan_plan(Query *root, TidPath *best_path,
                                        List *tlist, List *scan_clauses);
 static SubqueryScan *create_subqueryscan_plan(Query *root, Path *best_path,
@@ -981,86 +980,6 @@ create_bitmap_subplan(Query *root, Path *bitmapqual,
        return plan;
 }
 
-/*
- * Given a bitmapqual tree, generate the equivalent ordinary expression tree
- * (which we need for the bitmapqualorig field of the BitmapHeapScan plan).
- * The result is expressed as an implicit-AND list.
- */
-static List *
-create_bitmap_qual(Path *bitmapqual)
-{
-       List       *result;
-       List       *sublist;
-
-       if (IsA(bitmapqual, BitmapAndPath))
-       {
-               BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
-               ListCell   *l;
-
-               result = NIL;
-               foreach(l, apath->bitmapquals)
-               {
-                       sublist = create_bitmap_qual(lfirst(l));
-                       result = list_concat(result, sublist);
-               }
-       }
-       else if (IsA(bitmapqual, BitmapOrPath))
-       {
-               BitmapOrPath *opath = (BitmapOrPath *) bitmapqual;
-               List       *newlist = NIL;
-               ListCell   *l;
-
-               foreach(l, opath->bitmapquals)
-               {
-                       sublist = create_bitmap_qual(lfirst(l));
-                       if (sublist == NIL)
-                       {
-                               /* constant TRUE input yields constant TRUE OR result */
-                               return NIL;
-                       }
-                       newlist = lappend(newlist, make_ands_explicit(sublist));
-               }
-               result = list_make1(make_orclause(newlist));
-       }
-       else if (IsA(bitmapqual, IndexPath))
-       {
-               IndexPath *ipath = (IndexPath *) bitmapqual;
-
-               result = get_actual_clauses(ipath->indexclauses);
-       }
-       else
-       {
-               elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));
-               result = NIL;                   /* keep compiler quiet */
-       }
-
-       return result;
-}
-
-/*
- * Given a bitmapqual tree, generate the equivalent RestrictInfo list.
- */
-List *
-create_bitmap_restriction(Path *bitmapqual)
-{
-       List       *bitmapquals;
-       List       *bitmapclauses;
-       ListCell   *l;
-
-       bitmapquals = create_bitmap_qual(bitmapqual);
-
-       /* must convert qual list to restrictinfos ... painful ... */
-       bitmapclauses = NIL;
-       foreach(l, bitmapquals)
-       {
-               bitmapclauses = lappend(bitmapclauses,
-                                                               make_restrictinfo((Expr *) lfirst(l),
-                                                                                                 true, true));
-       }
-
-       return bitmapclauses;
-}
-
 /*
  * create_tidscan_plan
  *      Returns a tidscan plan for the base relation scanned by 'best_path'
@@ -1210,7 +1129,9 @@ create_nestloop_plan(Query *root,
                {
                        List       *bitmapclauses;
 
-                       bitmapclauses = create_bitmap_restriction(innerpath->bitmapqual);
+                       bitmapclauses =
+                               make_restrictinfo_from_bitmapqual(innerpath->bitmapqual,
+                                                                                                 true, true);
                        joinrestrictclauses =
                                select_nonredundant_join_clauses(root,
                                                                                                 joinrestrictclauses,
index edf268019a80a0eccba22101f21d90813f3a8e23..e19a308cdf43dbee2dc954e51f45906d5d355001 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.34 2005/04/25 01:30:13 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.35 2005/04/25 02:14:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -65,10 +65,95 @@ make_restrictinfo(Expr *clause, bool is_pushed_down, bool valid_everywhere)
                                                                          is_pushed_down, valid_everywhere);
 }
 
+/*
+ * make_restrictinfo_from_bitmapqual
+ *
+ * Given the bitmapqual Path structure for a bitmap indexscan, generate
+ * RestrictInfo node(s) equivalent to the condition represented by the
+ * indexclauses of the Path structure.
+ *
+ * The result is a List since we might need to return multiple RestrictInfos.
+ *
+ * To do this through the normal make_restrictinfo() API, callers would have
+ * to strip off the RestrictInfo nodes present in the indexclauses lists, and
+ * then make_restrictinfo() would have to build new ones.  It's better to have
+ * a specialized routine to allow sharing of RestrictInfos.
+ */
+List *
+make_restrictinfo_from_bitmapqual(Path *bitmapqual,
+                                                                 bool is_pushed_down,
+                                                                 bool valid_everywhere)
+{
+       List       *result;
+
+       if (IsA(bitmapqual, BitmapAndPath))
+       {
+               BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
+               ListCell   *l;
+
+               result = NIL;
+               foreach(l, apath->bitmapquals)
+               {
+                       List       *sublist;
+
+                       sublist = make_restrictinfo_from_bitmapqual((Path *) lfirst(l),
+                                                                                                               is_pushed_down,
+                                                                                                               valid_everywhere);
+                       result = list_concat(result, sublist);
+               }
+       }
+       else if (IsA(bitmapqual, BitmapOrPath))
+       {
+               BitmapOrPath *opath = (BitmapOrPath *) bitmapqual;
+               List       *withris = NIL;
+               List       *withoutris = NIL;
+               ListCell   *l;
+
+               foreach(l, opath->bitmapquals)
+               {
+                       List       *sublist;
+
+                       sublist = make_restrictinfo_from_bitmapqual((Path *) lfirst(l),
+                                                                                                               is_pushed_down,
+                                                                                                               valid_everywhere);
+                       if (sublist == NIL)
+                       {
+                               /* constant TRUE input yields constant TRUE OR result */
+                               /* (though this probably cannot happen) */
+                               return NIL;
+                       }
+                       /* Create AND subclause with RestrictInfos */
+                       withris = lappend(withris, make_ands_explicit(sublist));
+                       /* And one without */
+                       sublist = get_actual_clauses(sublist);
+                       withoutris = lappend(withoutris, make_ands_explicit(sublist));
+               }
+               /* Here's the magic part not available to outside callers */
+               result =
+                       list_make1(make_restrictinfo_internal(make_orclause(withoutris),
+                                                                                                 make_orclause(withris),
+                                                                                                 is_pushed_down,
+                                                                                                 valid_everywhere));
+       }
+       else if (IsA(bitmapqual, IndexPath))
+       {
+               IndexPath *ipath = (IndexPath *) bitmapqual;
+
+               result = list_copy(ipath->indexclauses);
+       }
+       else
+       {
+               elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));
+               result = NIL;                   /* keep compiler quiet */
+       }
+
+       return result;
+}
+
 /*
  * make_restrictinfo_internal
  *
- * Common code for the main entry point and the recursive cases.
+ * Common code for the main entry points and the recursive cases.
  */
 static RestrictInfo *
 make_restrictinfo_internal(Expr *clause, Expr *orclause,
index c98838a2b25b4751976d3685d844c1559e2fff16..129439ddec895f086d3841cca6590f16e1630e43 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.83 2005/04/25 01:30:14 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.84 2005/04/25 02:14:48 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -33,7 +33,6 @@ extern Plan *optimize_minmax_aggregates(Query *root, List *tlist,
  * prototypes for plan/createplan.c
  */
 extern Plan *create_plan(Query *root, Path *best_path);
-extern List *create_bitmap_restriction(Path *bitmapqual);
 extern SubqueryScan *make_subqueryscan(List *qptlist, List *qpqual,
                                  Index scanrelid, Plan *subplan);
 extern Append *make_append(List *appendplans, bool isTarget, List *tlist);
index 5c47a0d00b125a397671c78ffbedf47b4c4411b1..3760a65669b50e43cc8b9d877d71e2e7c560e37a 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.28 2005/04/25 01:30:14 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.29 2005/04/25 02:14:48 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,6 +18,9 @@
 
 extern RestrictInfo *make_restrictinfo(Expr *clause, bool is_pushed_down,
                                  bool valid_everywhere);
+extern List *make_restrictinfo_from_bitmapqual(Path *bitmapqual,
+                                                                                          bool is_pushed_down,
+                                                                                          bool valid_everywhere);
 extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
 extern List *get_actual_clauses(List *restrictinfo_list);
 extern void get_actual_join_clauses(List *restrictinfo_list,