Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7fbf4b

Browse files
committed
Remove dead code now that orindxpath.c is history.
We don't need make_restrictinfo_from_bitmapqual() anymore at all. generate_bitmap_or_paths() doesn't need to be exported, and we can drop its rather klugy restriction_only flag.
1 parent f343a88 commit f7fbf4b

File tree

5 files changed

+8
-247
lines changed

5 files changed

+8
-247
lines changed

src/backend/optimizer/path/indxpath.c

+8-51
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ static List *build_index_paths(PlannerInfo *root, RelOptInfo *rel,
121121
SaOpControl saop_control, ScanTypeControl scantype);
122122
static List *build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
123123
List *clauses, List *other_clauses);
124-
static List *drop_indexable_join_clauses(RelOptInfo *rel, List *clauses);
124+
static List *generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
125+
List *clauses, List *other_clauses);
125126
static Path *choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
126127
List *paths);
127128
static int path_usage_comparator(const void *a, const void *b);
@@ -311,17 +312,15 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
311312
* restriction list. Add these to bitindexpaths.
312313
*/
313314
indexpaths = generate_bitmap_or_paths(root, rel,
314-
rel->baserestrictinfo, NIL,
315-
false);
315+
rel->baserestrictinfo, NIL);
316316
bitindexpaths = list_concat(bitindexpaths, indexpaths);
317317

318318
/*
319319
* Likewise, generate BitmapOrPaths for any suitable OR-clauses present in
320320
* the joinclause list. Add these to bitjoinpaths.
321321
*/
322322
indexpaths = generate_bitmap_or_paths(root, rel,
323-
joinorclauses, rel->baserestrictinfo,
324-
false);
323+
joinorclauses, rel->baserestrictinfo);
325324
bitjoinpaths = list_concat(bitjoinpaths, indexpaths);
326325

327326
/*
@@ -1154,16 +1153,10 @@ build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel,
11541153
* other_clauses is a list of additional clauses that can be assumed true
11551154
* for the purpose of generating indexquals, but are not to be searched for
11561155
* ORs. (See build_paths_for_OR() for motivation.)
1157-
*
1158-
* If restriction_only is true, ignore OR elements that are join clauses.
1159-
* When using this feature it is caller's responsibility that neither clauses
1160-
* nor other_clauses contain any join clauses that are not ORs, as we do not
1161-
* re-filter those lists.
11621156
*/
1163-
List *
1157+
static List *
11641158
generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
1165-
List *clauses, List *other_clauses,
1166-
bool restriction_only)
1159+
List *clauses, List *other_clauses)
11671160
{
11681161
List *result = NIL;
11691162
List *all_clauses;
@@ -1202,9 +1195,6 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
12021195
{
12031196
List *andargs = ((BoolExpr *) orarg)->args;
12041197

1205-
if (restriction_only)
1206-
andargs = drop_indexable_join_clauses(rel, andargs);
1207-
12081198
indlist = build_paths_for_OR(root, rel,
12091199
andargs,
12101200
all_clauses);
@@ -1213,8 +1203,7 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
12131203
indlist = list_concat(indlist,
12141204
generate_bitmap_or_paths(root, rel,
12151205
andargs,
1216-
all_clauses,
1217-
restriction_only));
1206+
all_clauses));
12181207
}
12191208
else
12201209
{
@@ -1224,9 +1213,6 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
12241213
Assert(!restriction_is_or_clause((RestrictInfo *) orarg));
12251214
orargs = list_make1(orarg);
12261215

1227-
if (restriction_only)
1228-
orargs = drop_indexable_join_clauses(rel, orargs);
1229-
12301216
indlist = build_paths_for_OR(root, rel,
12311217
orargs,
12321218
all_clauses);
@@ -1264,34 +1250,6 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
12641250
return result;
12651251
}
12661252

1267-
/*
1268-
* drop_indexable_join_clauses
1269-
* Remove any indexable join clauses from the list.
1270-
*
1271-
* This is a helper for generate_bitmap_or_paths(). We leave OR clauses
1272-
* in the list whether they are joins or not, since we might be able to
1273-
* extract a restriction item from an OR list. It's safe to leave such
1274-
* clauses in the list because match_clauses_to_index() will ignore them,
1275-
* so there's no harm in passing such clauses to build_paths_for_OR().
1276-
*/
1277-
static List *
1278-
drop_indexable_join_clauses(RelOptInfo *rel, List *clauses)
1279-
{
1280-
List *result = NIL;
1281-
ListCell *lc;
1282-
1283-
foreach(lc, clauses)
1284-
{
1285-
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1286-
1287-
Assert(IsA(rinfo, RestrictInfo));
1288-
if (restriction_is_or_clause(rinfo) ||
1289-
bms_is_subset(rinfo->clause_relids, rel->relids))
1290-
result = lappend(result, rinfo);
1291-
}
1292-
return result;
1293-
}
1294-
12951253

12961254
/*
12971255
* choose_bitmap_and
@@ -1708,8 +1666,7 @@ get_bitmap_tree_required_outer(Path *bitmapqual)
17081666
* These are appended to the initial contents of *quals and *preds (hence
17091667
* caller should initialize those to NIL).
17101668
*
1711-
* This is sort of a simplified version of make_restrictinfo_from_bitmapqual;
1712-
* here, we are not trying to produce an accurate representation of the AND/OR
1669+
* Note we are not trying to produce an accurate representation of the AND/OR
17131670
* semantics of the Path, but just find out all the base conditions used.
17141671
*
17151672
* The result lists contain pointers to the expressions used in the Path,

src/backend/optimizer/plan/createplan.c

-3
Original file line numberDiff line numberDiff line change
@@ -1413,9 +1413,6 @@ create_bitmap_scan_plan(PlannerInfo *root,
14131413
* OR subtrees. This could be done in a less hacky way if we returned the
14141414
* indexquals in RestrictInfo form, but that would be slower and still pretty
14151415
* messy, since we'd have to build new RestrictInfos in many cases.)
1416-
*
1417-
* Note: if you find yourself changing this, you probably need to change
1418-
* make_restrictinfo_from_bitmapqual too.
14191416
*/
14201417
static Plan *
14211418
create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,

src/backend/optimizer/util/restrictinfo.c

-187
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "postgres.h"
1616

1717
#include "optimizer/clauses.h"
18-
#include "optimizer/predtest.h"
1918
#include "optimizer/restrictinfo.h"
2019
#include "optimizer/var.h"
2120

@@ -87,192 +86,6 @@ make_restrictinfo(Expr *clause,
8786
nullable_relids);
8887
}
8988

90-
/*
91-
* make_restrictinfo_from_bitmapqual
92-
*
93-
* Given the bitmapqual Path structure for a bitmap indexscan, generate
94-
* RestrictInfo node(s) equivalent to the condition represented by the
95-
* indexclauses of the Path structure.
96-
*
97-
* The result is a List (effectively, implicit-AND representation) of
98-
* RestrictInfos.
99-
*
100-
* The caller must pass is_pushed_down, but we assume outerjoin_delayed
101-
* and pseudoconstant are false while outer_relids and nullable_relids
102-
* are NULL (no other kind of qual should ever get into a bitmapqual).
103-
*
104-
* If include_predicates is true, we add any partial index predicates to
105-
* the explicit index quals. When this is not true, we return a condition
106-
* that might be weaker than the actual scan represents.
107-
*
108-
* To do this through the normal make_restrictinfo() API, callers would have
109-
* to strip off the RestrictInfo nodes present in the indexclauses lists, and
110-
* then make_restrictinfo() would have to build new ones. It's better to have
111-
* a specialized routine to allow sharing of RestrictInfos.
112-
*
113-
* The qual manipulations here are much the same as in create_bitmap_subplan;
114-
* keep the two routines in sync!
115-
*/
116-
List *
117-
make_restrictinfo_from_bitmapqual(Path *bitmapqual,
118-
bool is_pushed_down,
119-
bool include_predicates)
120-
{
121-
List *result;
122-
ListCell *l;
123-
124-
if (IsA(bitmapqual, BitmapAndPath))
125-
{
126-
BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
127-
128-
/*
129-
* There may well be redundant quals among the subplans, since a
130-
* top-level WHERE qual might have gotten used to form several
131-
* different index quals. We don't try exceedingly hard to eliminate
132-
* redundancies, but we do eliminate obvious duplicates by using
133-
* list_concat_unique.
134-
*/
135-
result = NIL;
136-
foreach(l, apath->bitmapquals)
137-
{
138-
List *sublist;
139-
140-
sublist = make_restrictinfo_from_bitmapqual((Path *) lfirst(l),
141-
is_pushed_down,
142-
include_predicates);
143-
result = list_concat_unique(result, sublist);
144-
}
145-
}
146-
else if (IsA(bitmapqual, BitmapOrPath))
147-
{
148-
BitmapOrPath *opath = (BitmapOrPath *) bitmapqual;
149-
List *withris = NIL;
150-
List *withoutris = NIL;
151-
152-
/*
153-
* Here, we only detect qual-free subplans. A qual-free subplan would
154-
* cause us to generate "... OR true ..." which we may as well reduce
155-
* to just "true". We do not try to eliminate redundant subclauses
156-
* because (a) it's not as likely as in the AND case, and (b) we might
157-
* well be working with hundreds or even thousands of OR conditions,
158-
* perhaps from a long IN list. The performance of list_append_unique
159-
* would be unacceptable.
160-
*/
161-
foreach(l, opath->bitmapquals)
162-
{
163-
List *sublist;
164-
165-
sublist = make_restrictinfo_from_bitmapqual((Path *) lfirst(l),
166-
is_pushed_down,
167-
include_predicates);
168-
if (sublist == NIL)
169-
{
170-
/*
171-
* If we find a qual-less subscan, it represents a constant
172-
* TRUE, and hence the OR result is also constant TRUE, so we
173-
* can stop here.
174-
*/
175-
return NIL;
176-
}
177-
178-
/*
179-
* If the sublist contains multiple RestrictInfos, we create an
180-
* AND subclause. If there's just one, we have to check if it's
181-
* an OR clause, and if so flatten it to preserve AND/OR flatness
182-
* of our output.
183-
*
184-
* We construct lists with and without sub-RestrictInfos, so as
185-
* not to have to regenerate duplicate RestrictInfos below.
186-
*/
187-
if (list_length(sublist) > 1)
188-
{
189-
withris = lappend(withris, make_andclause(sublist));
190-
sublist = get_actual_clauses(sublist);
191-
withoutris = lappend(withoutris, make_andclause(sublist));
192-
}
193-
else
194-
{
195-
RestrictInfo *subri = (RestrictInfo *) linitial(sublist);
196-
197-
Assert(IsA(subri, RestrictInfo));
198-
if (restriction_is_or_clause(subri))
199-
{
200-
BoolExpr *subor = (BoolExpr *) subri->orclause;
201-
202-
Assert(or_clause((Node *) subor));
203-
withris = list_concat(withris,
204-
list_copy(subor->args));
205-
subor = (BoolExpr *) subri->clause;
206-
Assert(or_clause((Node *) subor));
207-
withoutris = list_concat(withoutris,
208-
list_copy(subor->args));
209-
}
210-
else
211-
{
212-
withris = lappend(withris, subri);
213-
withoutris = lappend(withoutris, subri->clause);
214-
}
215-
}
216-
}
217-
218-
/*
219-
* Avoid generating one-element ORs, which could happen due to
220-
* redundancy elimination or ScalarArrayOpExpr quals.
221-
*/
222-
if (list_length(withris) <= 1)
223-
result = withris;
224-
else
225-
{
226-
/* Here's the magic part not available to outside callers */
227-
result =
228-
list_make1(make_restrictinfo_internal(make_orclause(withoutris),
229-
make_orclause(withris),
230-
is_pushed_down,
231-
false,
232-
false,
233-
NULL,
234-
NULL,
235-
NULL));
236-
}
237-
}
238-
else if (IsA(bitmapqual, IndexPath))
239-
{
240-
IndexPath *ipath = (IndexPath *) bitmapqual;
241-
242-
result = list_copy(ipath->indexclauses);
243-
if (include_predicates && ipath->indexinfo->indpred != NIL)
244-
{
245-
foreach(l, ipath->indexinfo->indpred)
246-
{
247-
Expr *pred = (Expr *) lfirst(l);
248-
249-
/*
250-
* We know that the index predicate must have been implied by
251-
* the query condition as a whole, but it may or may not be
252-
* implied by the conditions that got pushed into the
253-
* bitmapqual. Avoid generating redundant conditions.
254-
*/
255-
if (!predicate_implied_by(list_make1(pred), result))
256-
result = lappend(result,
257-
make_restrictinfo(pred,
258-
is_pushed_down,
259-
false,
260-
false,
261-
NULL,
262-
NULL,
263-
NULL));
264-
}
265-
}
266-
}
267-
else
268-
{
269-
elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));
270-
result = NIL; /* keep compiler quiet */
271-
}
272-
273-
return result;
274-
}
275-
27689
/*
27790
* make_restrictinfos_from_actual_clauses
27891
*

src/include/optimizer/paths.h

-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
4343
* routines to generate index paths
4444
*/
4545
extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
46-
extern List *generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
47-
List *clauses, List *other_clauses,
48-
bool restriction_only);
4946
extern bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel,
5047
List *restrictlist,
5148
List *exprlist, List *oprlist);

src/include/optimizer/restrictinfo.h

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ extern RestrictInfo *make_restrictinfo(Expr *clause,
2828
Relids required_relids,
2929
Relids outer_relids,
3030
Relids nullable_relids);
31-
extern List *make_restrictinfo_from_bitmapqual(Path *bitmapqual,
32-
bool is_pushed_down,
33-
bool include_predicates);
3431
extern List *make_restrictinfos_from_actual_clauses(PlannerInfo *root,
3532
List *clause_list);
3633
extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);

0 commit comments

Comments
 (0)