Skip to content

Commit 0dff51c

Browse files
guofengrichardCommitfest Bot
authored andcommitted
Retiring is_pushed_down
When forming an outer join's joinrel, we have the is_pushed_down flag in RestrictInfo nodes to distinguish those quals that are in that join's JOIN/ON condition from those that were pushed down to the joinrel and thus act as filter quals. Since now we have the outer-join-aware-Var infrastructure, we can check to see whether a qual clause's required_relids reference the outer join(s) being formed, in order to tell if it's a join or filter clause. This seems like a more principled way. This patch is an attempt to retire the is_pushed_down flag.
1 parent 8240401 commit 0dff51c

File tree

18 files changed

+148
-144
lines changed

18 files changed

+148
-144
lines changed

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5857,7 +5857,7 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
58575857
rinfo->clause);
58585858

58595859
if (IS_OUTER_JOIN(jointype) &&
5860-
!RINFO_IS_PUSHED_DOWN(rinfo, joinrel->relids))
5860+
!RINFO_IS_PUSHED_DOWN(rinfo, extra->ojrelids, joinrel->relids))
58615861
{
58625862
if (!is_remote_clause)
58635863
return false;
@@ -6619,7 +6619,6 @@ foreign_grouping_ok(PlannerInfo *root, RelOptInfo *grouped_rel,
66196619
Assert(!IsA(expr, RestrictInfo));
66206620
rinfo = make_restrictinfo(root,
66216621
expr,
6622-
true,
66236622
false,
66246623
false,
66256624
false,

src/backend/optimizer/path/costsize.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4972,7 +4972,7 @@ get_restriction_qual_cost(PlannerInfo *root, RelOptInfo *baserel,
49724972
* sjinfo: SpecialJoinInfo relevant to this join
49734973
* restrictlist: join quals
49744974
* Output parameters:
4975-
* *semifactors is filled in (see pathnodes.h for field definitions)
4975+
* extra->semifactors is filled in (see pathnodes.h for field definitions)
49764976
*/
49774977
void
49784978
compute_semi_anti_join_factors(PlannerInfo *root,
@@ -4982,7 +4982,7 @@ compute_semi_anti_join_factors(PlannerInfo *root,
49824982
JoinType jointype,
49834983
SpecialJoinInfo *sjinfo,
49844984
List *restrictlist,
4985-
SemiAntiJoinFactors *semifactors)
4985+
JoinPathExtraData *extra)
49864986
{
49874987
Selectivity jselec;
49884988
Selectivity nselec;
@@ -5005,7 +5005,7 @@ compute_semi_anti_join_factors(PlannerInfo *root,
50055005
{
50065006
RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
50075007

5008-
if (!RINFO_IS_PUSHED_DOWN(rinfo, joinrel->relids))
5008+
if (!RINFO_IS_PUSHED_DOWN(rinfo, extra->ojrelids, joinrel->relids))
50095009
joinquals = lappend(joinquals, rinfo);
50105010
}
50115011
}
@@ -5057,8 +5057,8 @@ compute_semi_anti_join_factors(PlannerInfo *root,
50575057
else
50585058
avgmatch = 1.0;
50595059

5060-
semifactors->outer_match_frac = jselec;
5061-
semifactors->match_count = avgmatch;
5060+
extra->semifactors.outer_match_frac = jselec;
5061+
extra->semifactors.match_count = avgmatch;
50625062
}
50635063

50645064
/*
@@ -5408,13 +5408,16 @@ calc_joinrel_size_estimate(PlannerInfo *root,
54085408
List *joinquals = NIL;
54095409
List *pushedquals = NIL;
54105410
ListCell *l;
5411+
Relids ojrelids = CALC_OUTER_JOIN_RELIDS(joinrel->relids,
5412+
outer_rel->relids,
5413+
inner_rel->relids);
54115414

54125415
/* Grovel through the clauses to separate into two lists */
54135416
foreach(l, restrictlist)
54145417
{
54155418
RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
54165419

5417-
if (RINFO_IS_PUSHED_DOWN(rinfo, joinrel->relids))
5420+
if (RINFO_IS_PUSHED_DOWN(rinfo, ojrelids, joinrel->relids))
54185421
pushedquals = lappend(pushedquals, rinfo);
54195422
else
54205423
joinquals = lappend(joinquals, rinfo);

src/backend/optimizer/path/equivclass.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ process_equivalence(PlannerInfo *root,
196196
*p_restrictinfo =
197197
make_restrictinfo(root,
198198
(Expr *) ntest,
199-
restrictinfo->is_pushed_down,
200199
restrictinfo->has_clone,
201200
restrictinfo->is_clone,
202201
restrictinfo->pseudoconstant,
@@ -2020,7 +2019,6 @@ reconsider_outer_join_clauses(PlannerInfo *root)
20202019
/* throw back a dummy replacement clause (see notes above) */
20212020
rinfo = make_restrictinfo(root,
20222021
(Expr *) makeBoolConst(true, false),
2023-
rinfo->is_pushed_down,
20242022
rinfo->has_clone,
20252023
rinfo->is_clone,
20262024
false, /* pseudoconstant */
@@ -2048,7 +2046,6 @@ reconsider_outer_join_clauses(PlannerInfo *root)
20482046
/* throw back a dummy replacement clause (see notes above) */
20492047
rinfo = make_restrictinfo(root,
20502048
(Expr *) makeBoolConst(true, false),
2051-
rinfo->is_pushed_down,
20522049
rinfo->has_clone,
20532050
rinfo->is_clone,
20542051
false, /* pseudoconstant */
@@ -2076,7 +2073,6 @@ reconsider_outer_join_clauses(PlannerInfo *root)
20762073
/* throw back a dummy replacement clause (see notes above) */
20772074
rinfo = make_restrictinfo(root,
20782075
(Expr *) makeBoolConst(true, false),
2079-
rinfo->is_pushed_down,
20802076
rinfo->has_clone,
20812077
rinfo->is_clone,
20822078
false, /* pseudoconstant */

src/backend/optimizer/path/joinpath.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static List *select_mergejoin_clauses(PlannerInfo *root,
8585
RelOptInfo *innerrel,
8686
List *restrictlist,
8787
JoinType jointype,
88+
JoinPathExtraData *extra,
8889
bool *mergejoin_allowed);
8990
static void generate_mergejoin_paths(PlannerInfo *root,
9091
RelOptInfo *joinrel,
@@ -151,6 +152,9 @@ add_paths_to_joinrel(PlannerInfo *root,
151152
extra.mergeclause_list = NIL;
152153
extra.sjinfo = sjinfo;
153154
extra.param_source_rels = NULL;
155+
extra.ojrelids = CALC_OUTER_JOIN_RELIDS(joinrel->relids,
156+
outerrel->relids,
157+
innerrel->relids);
154158

155159
/*
156160
* See if the inner relation is provably unique for this outer rel.
@@ -215,6 +219,7 @@ add_paths_to_joinrel(PlannerInfo *root,
215219
innerrel,
216220
restrictlist,
217221
jointype,
222+
&extra,
218223
&mergejoin_allowed);
219224

220225
/*
@@ -224,7 +229,7 @@ add_paths_to_joinrel(PlannerInfo *root,
224229
if (jointype == JOIN_SEMI || jointype == JOIN_ANTI || extra.inner_unique)
225230
compute_semi_anti_join_factors(root, joinrel, outerrel, innerrel,
226231
jointype, sjinfo, restrictlist,
227-
&extra.semifactors);
232+
&extra);
228233

229234
/*
230235
* Decide whether it's sensible to generate parameterized paths for this
@@ -2254,7 +2259,8 @@ hash_inner_and_outer(PlannerInfo *root,
22542259
* If processing an outer join, only use its own join clauses for
22552260
* hashing. For inner joins we need not be so picky.
22562261
*/
2257-
if (isouterjoin && RINFO_IS_PUSHED_DOWN(restrictinfo, joinrel->relids))
2262+
if (isouterjoin &&
2263+
RINFO_IS_PUSHED_DOWN(restrictinfo, extra->ojrelids, joinrel->relids))
22582264
continue;
22592265

22602266
if (!restrictinfo->can_join ||
@@ -2487,6 +2493,7 @@ select_mergejoin_clauses(PlannerInfo *root,
24872493
RelOptInfo *innerrel,
24882494
List *restrictlist,
24892495
JoinType jointype,
2496+
JoinPathExtraData *extra,
24902497
bool *mergejoin_allowed)
24912498
{
24922499
List *result_list = NIL;
@@ -2514,7 +2521,8 @@ select_mergejoin_clauses(PlannerInfo *root,
25142521
* we don't set have_nonmergeable_joinclause here because pushed-down
25152522
* clauses will become otherquals not joinquals.)
25162523
*/
2517-
if (isouterjoin && RINFO_IS_PUSHED_DOWN(restrictinfo, joinrel->relids))
2524+
if (isouterjoin &&
2525+
RINFO_IS_PUSHED_DOWN(restrictinfo, extra->ojrelids, joinrel->relids))
25182526
continue;
25192527

25202528
/* Check that clause is a mergeable operator clause */

src/backend/optimizer/path/joinrels.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static bool has_join_restriction(PlannerInfo *root, RelOptInfo *rel);
3434
static bool has_legal_joinclause(PlannerInfo *root, RelOptInfo *rel);
3535
static bool restriction_is_constant_false(List *restrictlist,
3636
RelOptInfo *joinrel,
37+
Relids ojrelids,
3738
bool only_pushed_down);
3839
static void populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
3940
RelOptInfo *rel2, RelOptInfo *joinrel,
@@ -894,6 +895,10 @@ populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
894895
RelOptInfo *rel2, RelOptInfo *joinrel,
895896
SpecialJoinInfo *sjinfo, List *restrictlist)
896897
{
898+
Relids ojrelids = CALC_OUTER_JOIN_RELIDS(joinrel->relids,
899+
rel1->relids,
900+
rel2->relids);
901+
897902
/*
898903
* Consider paths using each rel as both outer and inner. Depending on
899904
* the join type, a provably empty outer or inner rel might mean the join
@@ -916,7 +921,7 @@ populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
916921
{
917922
case JOIN_INNER:
918923
if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
919-
restriction_is_constant_false(restrictlist, joinrel, false))
924+
restriction_is_constant_false(restrictlist, joinrel, ojrelids, false))
920925
{
921926
mark_dummy_rel(joinrel);
922927
break;
@@ -930,12 +935,12 @@ populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
930935
break;
931936
case JOIN_LEFT:
932937
if (is_dummy_rel(rel1) ||
933-
restriction_is_constant_false(restrictlist, joinrel, true))
938+
restriction_is_constant_false(restrictlist, joinrel, ojrelids, true))
934939
{
935940
mark_dummy_rel(joinrel);
936941
break;
937942
}
938-
if (restriction_is_constant_false(restrictlist, joinrel, false) &&
943+
if (restriction_is_constant_false(restrictlist, joinrel, ojrelids, false) &&
939944
bms_is_subset(rel2->relids, sjinfo->syn_righthand))
940945
mark_dummy_rel(rel2);
941946
add_paths_to_joinrel(root, joinrel, rel1, rel2,
@@ -947,7 +952,7 @@ populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
947952
break;
948953
case JOIN_FULL:
949954
if ((is_dummy_rel(rel1) && is_dummy_rel(rel2)) ||
950-
restriction_is_constant_false(restrictlist, joinrel, true))
955+
restriction_is_constant_false(restrictlist, joinrel, ojrelids, true))
951956
{
952957
mark_dummy_rel(joinrel);
953958
break;
@@ -983,7 +988,7 @@ populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
983988
bms_is_subset(sjinfo->min_righthand, rel2->relids))
984989
{
985990
if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
986-
restriction_is_constant_false(restrictlist, joinrel, false))
991+
restriction_is_constant_false(restrictlist, joinrel, ojrelids, false))
987992
{
988993
mark_dummy_rel(joinrel);
989994
break;
@@ -1009,7 +1014,7 @@ populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
10091014
sjinfo) != NULL)
10101015
{
10111016
if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
1012-
restriction_is_constant_false(restrictlist, joinrel, false))
1017+
restriction_is_constant_false(restrictlist, joinrel, ojrelids, false))
10131018
{
10141019
mark_dummy_rel(joinrel);
10151020
break;
@@ -1024,12 +1029,12 @@ populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
10241029
break;
10251030
case JOIN_ANTI:
10261031
if (is_dummy_rel(rel1) ||
1027-
restriction_is_constant_false(restrictlist, joinrel, true))
1032+
restriction_is_constant_false(restrictlist, joinrel, ojrelids, true))
10281033
{
10291034
mark_dummy_rel(joinrel);
10301035
break;
10311036
}
1032-
if (restriction_is_constant_false(restrictlist, joinrel, false) &&
1037+
if (restriction_is_constant_false(restrictlist, joinrel, ojrelids, false) &&
10331038
bms_is_subset(rel2->relids, sjinfo->syn_righthand))
10341039
mark_dummy_rel(rel2);
10351040
add_paths_to_joinrel(root, joinrel, rel1, rel2,
@@ -1426,6 +1431,7 @@ mark_dummy_rel(RelOptInfo *rel)
14261431
static bool
14271432
restriction_is_constant_false(List *restrictlist,
14281433
RelOptInfo *joinrel,
1434+
Relids ojrelids,
14291435
bool only_pushed_down)
14301436
{
14311437
ListCell *lc;
@@ -1440,7 +1446,8 @@ restriction_is_constant_false(List *restrictlist,
14401446
{
14411447
RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
14421448

1443-
if (only_pushed_down && !RINFO_IS_PUSHED_DOWN(rinfo, joinrel->relids))
1449+
if (only_pushed_down &&
1450+
!RINFO_IS_PUSHED_DOWN(rinfo, ojrelids, joinrel->relids))
14441451
continue;
14451452

14461453
if (rinfo->clause && IsA(rinfo->clause, Const))

src/backend/optimizer/plan/analyzejoins.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ join_is_removable(PlannerInfo *root, SpecialJoinInfo *sjinfo)
282282
* above the outer join, even if it references no other rels (it might
283283
* be from WHERE, for example).
284284
*/
285-
if (RINFO_IS_PUSHED_DOWN(restrictinfo, joinrelids))
285+
if (RINFO_IS_PUSHED_DOWN(restrictinfo,
286+
bms_make_singleton(sjinfo->ojrelid),
287+
joinrelids))
286288
continue; /* ignore; not useful here */
287289

288290
/* Ignore if it's not a mergejoinable clause */
@@ -493,7 +495,9 @@ remove_rel_from_query(PlannerInfo *root, int relid, SpecialJoinInfo *sjinfo)
493495

494496
remove_join_clause_from_rels(root, rinfo, rinfo->required_relids);
495497

496-
if (RINFO_IS_PUSHED_DOWN(rinfo, join_plus_commute))
498+
if (RINFO_IS_PUSHED_DOWN(rinfo,
499+
bms_make_singleton(sjinfo->ojrelid),
500+
join_plus_commute))
497501
{
498502
/*
499503
* There might be references to relid or ojrelid in the
@@ -1298,6 +1302,9 @@ is_innerrel_unique_for(PlannerInfo *root,
12981302
{
12991303
List *clause_list = NIL;
13001304
ListCell *lc;
1305+
Relids ojrelids = CALC_OUTER_JOIN_RELIDS(joinrelids,
1306+
outerrelids,
1307+
innerrel->relids);
13011308

13021309
/*
13031310
* Search for mergejoinable clauses that constrain the inner rel against
@@ -1315,7 +1322,7 @@ is_innerrel_unique_for(PlannerInfo *root,
13151322
* join, we can't use it.
13161323
*/
13171324
if (IS_OUTER_JOIN(jointype) &&
1318-
RINFO_IS_PUSHED_DOWN(restrictinfo, joinrelids))
1325+
RINFO_IS_PUSHED_DOWN(restrictinfo, ojrelids, joinrelids))
13191326
continue;
13201327

13211328
/* Ignore if it's not a mergejoinable clause */

src/backend/optimizer/plan/createplan.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4391,6 +4391,7 @@ create_nestloop_plan(PlannerInfo *root,
43914391
{
43924392
extract_actual_join_clauses(joinrestrictclauses,
43934393
best_path->jpath.path.parent->relids,
4394+
best_path->jpath.ojrelids,
43944395
&joinclauses, &otherclauses);
43954396
}
43964397
else
@@ -4479,6 +4480,7 @@ create_mergejoin_plan(PlannerInfo *root,
44794480
{
44804481
extract_actual_join_clauses(joinclauses,
44814482
best_path->jpath.path.parent->relids,
4483+
best_path->jpath.ojrelids,
44824484
&joinclauses, &otherclauses);
44834485
}
44844486
else
@@ -4781,6 +4783,7 @@ create_hashjoin_plan(PlannerInfo *root,
47814783
{
47824784
extract_actual_join_clauses(joinclauses,
47834785
best_path->jpath.path.parent->relids,
4786+
best_path->jpath.ojrelids,
47844787
&joinclauses, &otherclauses);
47854788
}
47864789
else

0 commit comments

Comments
 (0)