aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/path/indxpath.c59
-rw-r--r--src/backend/optimizer/plan/createplan.c3
-rw-r--r--src/backend/optimizer/util/restrictinfo.c187
-rw-r--r--src/include/optimizer/paths.h3
-rw-r--r--src/include/optimizer/restrictinfo.h3
5 files changed, 8 insertions, 247 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 0e05107319c..4ef5c1c7af6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -121,7 +121,8 @@ static List *build_index_paths(PlannerInfo *root, RelOptInfo *rel,
SaOpControl saop_control, ScanTypeControl scantype);
static List *build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
List *clauses, List *other_clauses);
-static List *drop_indexable_join_clauses(RelOptInfo *rel, List *clauses);
+static List *generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
+ List *clauses, List *other_clauses);
static Path *choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
List *paths);
static int path_usage_comparator(const void *a, const void *b);
@@ -311,8 +312,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* restriction list. Add these to bitindexpaths.
*/
indexpaths = generate_bitmap_or_paths(root, rel,
- rel->baserestrictinfo, NIL,
- false);
+ rel->baserestrictinfo, NIL);
bitindexpaths = list_concat(bitindexpaths, indexpaths);
/*
@@ -320,8 +320,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
* the joinclause list. Add these to bitjoinpaths.
*/
indexpaths = generate_bitmap_or_paths(root, rel,
- joinorclauses, rel->baserestrictinfo,
- false);
+ joinorclauses, rel->baserestrictinfo);
bitjoinpaths = list_concat(bitjoinpaths, indexpaths);
/*
@@ -1154,16 +1153,10 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
* other_clauses is a list of additional clauses that can be assumed true
* for the purpose of generating indexquals, but are not to be searched for
* ORs. (See build_paths_for_OR() for motivation.)
- *
- * If restriction_only is true, ignore OR elements that are join clauses.
- * When using this feature it is caller's responsibility that neither clauses
- * nor other_clauses contain any join clauses that are not ORs, as we do not
- * re-filter those lists.
*/
-List *
+static List *
generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
- List *clauses, List *other_clauses,
- bool restriction_only)
+ List *clauses, List *other_clauses)
{
List *result = NIL;
List *all_clauses;
@@ -1202,9 +1195,6 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
{
List *andargs = ((BoolExpr *) orarg)->args;
- if (restriction_only)
- andargs = drop_indexable_join_clauses(rel, andargs);
-
indlist = build_paths_for_OR(root, rel,
andargs,
all_clauses);
@@ -1213,8 +1203,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
indlist = list_concat(indlist,
generate_bitmap_or_paths(root, rel,
andargs,
- all_clauses,
- restriction_only));
+ all_clauses));
}
else
{
@@ -1224,9 +1213,6 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
Assert(!restriction_is_or_clause((RestrictInfo *) orarg));
orargs = list_make1(orarg);
- if (restriction_only)
- orargs = drop_indexable_join_clauses(rel, orargs);
-
indlist = build_paths_for_OR(root, rel,
orargs,
all_clauses);
@@ -1264,34 +1250,6 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
return result;
}
-/*
- * drop_indexable_join_clauses
- * Remove any indexable join clauses from the list.
- *
- * This is a helper for generate_bitmap_or_paths(). We leave OR clauses
- * in the list whether they are joins or not, since we might be able to
- * extract a restriction item from an OR list. It's safe to leave such
- * clauses in the list because match_clauses_to_index() will ignore them,
- * so there's no harm in passing such clauses to build_paths_for_OR().
- */
-static List *
-drop_indexable_join_clauses(RelOptInfo *rel, List *clauses)
-{
- List *result = NIL;
- ListCell *lc;
-
- foreach(lc, clauses)
- {
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
-
- Assert(IsA(rinfo, RestrictInfo));
- if (restriction_is_or_clause(rinfo) ||
- bms_is_subset(rinfo->clause_relids, rel->relids))
- result = lappend(result, rinfo);
- }
- return result;
-}
-
/*
* choose_bitmap_and
@@ -1708,8 +1666,7 @@ get_bitmap_tree_required_outer(Path *bitmapqual)
* These are appended to the initial contents of *quals and *preds (hence
* caller should initialize those to NIL).
*
- * This is sort of a simplified version of make_restrictinfo_from_bitmapqual;
- * here, we are not trying to produce an accurate representation of the AND/OR
+ * Note we are not trying to produce an accurate representation of the AND/OR
* semantics of the Path, but just find out all the base conditions used.
*
* The result lists contain pointers to the expressions used in the Path,
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index f2c122d2959..701fe786ce7 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -1413,9 +1413,6 @@ create_bitmap_scan_plan(PlannerInfo *root,
* OR subtrees. This could be done in a less hacky way if we returned the
* indexquals in RestrictInfo form, but that would be slower and still pretty
* messy, since we'd have to build new RestrictInfos in many cases.)
- *
- * Note: if you find yourself changing this, you probably need to change
- * make_restrictinfo_from_bitmapqual too.
*/
static Plan *
create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c
index 55ce9d86543..d500154f5d8 100644
--- a/src/backend/optimizer/util/restrictinfo.c
+++ b/src/backend/optimizer/util/restrictinfo.c
@@ -15,7 +15,6 @@
#include "postgres.h"
#include "optimizer/clauses.h"
-#include "optimizer/predtest.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/var.h"
@@ -88,192 +87,6 @@ make_restrictinfo(Expr *clause,
}
/*
- * 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 (effectively, implicit-AND representation) of
- * RestrictInfos.
- *
- * The caller must pass is_pushed_down, but we assume outerjoin_delayed
- * and pseudoconstant are false while outer_relids and nullable_relids
- * are NULL (no other kind of qual should ever get into a bitmapqual).
- *
- * If include_predicates is true, we add any partial index predicates to
- * the explicit index quals. When this is not true, we return a condition
- * that might be weaker than the actual scan represents.
- *
- * 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.
- *
- * The qual manipulations here are much the same as in create_bitmap_subplan;
- * keep the two routines in sync!
- */
-List *
-make_restrictinfo_from_bitmapqual(Path *bitmapqual,
- bool is_pushed_down,
- bool include_predicates)
-{
- List *result;
- ListCell *l;
-
- if (IsA(bitmapqual, BitmapAndPath))
- {
- BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
-
- /*
- * There may well be redundant quals among the subplans, since a
- * top-level WHERE qual might have gotten used to form several
- * different index quals. We don't try exceedingly hard to eliminate
- * redundancies, but we do eliminate obvious duplicates by using
- * list_concat_unique.
- */
- result = NIL;
- foreach(l, apath->bitmapquals)
- {
- List *sublist;
-
- sublist = make_restrictinfo_from_bitmapqual((Path *) lfirst(l),
- is_pushed_down,
- include_predicates);
- result = list_concat_unique(result, sublist);
- }
- }
- else if (IsA(bitmapqual, BitmapOrPath))
- {
- BitmapOrPath *opath = (BitmapOrPath *) bitmapqual;
- List *withris = NIL;
- List *withoutris = NIL;
-
- /*
- * Here, we only detect qual-free subplans. A qual-free subplan would
- * cause us to generate "... OR true ..." which we may as well reduce
- * to just "true". We do not try to eliminate redundant subclauses
- * because (a) it's not as likely as in the AND case, and (b) we might
- * well be working with hundreds or even thousands of OR conditions,
- * perhaps from a long IN list. The performance of list_append_unique
- * would be unacceptable.
- */
- foreach(l, opath->bitmapquals)
- {
- List *sublist;
-
- sublist = make_restrictinfo_from_bitmapqual((Path *) lfirst(l),
- is_pushed_down,
- include_predicates);
- if (sublist == NIL)
- {
- /*
- * If we find a qual-less subscan, it represents a constant
- * TRUE, and hence the OR result is also constant TRUE, so we
- * can stop here.
- */
- return NIL;
- }
-
- /*
- * If the sublist contains multiple RestrictInfos, we create an
- * AND subclause. If there's just one, we have to check if it's
- * an OR clause, and if so flatten it to preserve AND/OR flatness
- * of our output.
- *
- * We construct lists with and without sub-RestrictInfos, so as
- * not to have to regenerate duplicate RestrictInfos below.
- */
- if (list_length(sublist) > 1)
- {
- withris = lappend(withris, make_andclause(sublist));
- sublist = get_actual_clauses(sublist);
- withoutris = lappend(withoutris, make_andclause(sublist));
- }
- else
- {
- RestrictInfo *subri = (RestrictInfo *) linitial(sublist);
-
- Assert(IsA(subri, RestrictInfo));
- if (restriction_is_or_clause(subri))
- {
- BoolExpr *subor = (BoolExpr *) subri->orclause;
-
- Assert(or_clause((Node *) subor));
- withris = list_concat(withris,
- list_copy(subor->args));
- subor = (BoolExpr *) subri->clause;
- Assert(or_clause((Node *) subor));
- withoutris = list_concat(withoutris,
- list_copy(subor->args));
- }
- else
- {
- withris = lappend(withris, subri);
- withoutris = lappend(withoutris, subri->clause);
- }
- }
- }
-
- /*
- * Avoid generating one-element ORs, which could happen due to
- * redundancy elimination or ScalarArrayOpExpr quals.
- */
- if (list_length(withris) <= 1)
- result = withris;
- else
- {
- /* 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,
- false,
- false,
- NULL,
- NULL,
- NULL));
- }
- }
- else if (IsA(bitmapqual, IndexPath))
- {
- IndexPath *ipath = (IndexPath *) bitmapqual;
-
- result = list_copy(ipath->indexclauses);
- if (include_predicates && ipath->indexinfo->indpred != NIL)
- {
- foreach(l, ipath->indexinfo->indpred)
- {
- Expr *pred = (Expr *) lfirst(l);
-
- /*
- * We know that the index predicate must have been implied by
- * the query condition as a whole, but it may or may not be
- * implied by the conditions that got pushed into the
- * bitmapqual. Avoid generating redundant conditions.
- */
- if (!predicate_implied_by(list_make1(pred), result))
- result = lappend(result,
- make_restrictinfo(pred,
- is_pushed_down,
- false,
- false,
- NULL,
- NULL,
- NULL));
- }
- }
- }
- else
- {
- elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));
- result = NIL; /* keep compiler quiet */
- }
-
- return result;
-}
-
-/*
* make_restrictinfos_from_actual_clauses
*
* Given a list of implicitly-ANDed restriction clauses, produce a list
diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h
index ed8d260dbe3..dfe3a223e5b 100644
--- a/src/include/optimizer/paths.h
+++ b/src/include/optimizer/paths.h
@@ -43,9 +43,6 @@ extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
* routines to generate index paths
*/
extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
-extern List *generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
- List *clauses, List *other_clauses,
- bool restriction_only);
extern bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel,
List *restrictlist,
List *exprlist, List *oprlist);
diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h
index 47b19691c29..fcef2b6dcb2 100644
--- a/src/include/optimizer/restrictinfo.h
+++ b/src/include/optimizer/restrictinfo.h
@@ -28,9 +28,6 @@ extern RestrictInfo *make_restrictinfo(Expr *clause,
Relids required_relids,
Relids outer_relids,
Relids nullable_relids);
-extern List *make_restrictinfo_from_bitmapqual(Path *bitmapqual,
- bool is_pushed_down,
- bool include_predicates);
extern List *make_restrictinfos_from_actual_clauses(PlannerInfo *root,
List *clause_list);
extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);