Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6190d82

Browse files
committed
Do not translate dummy SpecialJoinInfos for child joins
This teaches build_child_join_sjinfo() to create the dummy SpecialJoinInfos (those created for inner joins) directly for a given child join, skipping the unnecessary overhead of translating the parent joinrel's SpecialJoinInfo. To that end, this commit moves the code to initialize the dummy SpecialJoinInfos to a new function named init_dummy_sjinfo() and changes the few existing sites that have this code and build_child_join_sjinfo() to call this new function. Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Amit Langote <amitlangote09@gmail.com> Reviewed-by: Andrey Lepikhov <a.lepikhov@postgrespro.ru> Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com> Discussion: https://postgr.es/m/CAExHW5tHqEf3ASVqvFFcghYGPfpy7o3xnvhHwBGbJFMRH8KjNw@mail.gmail.com
1 parent 5278d0a commit 6190d82

File tree

3 files changed

+46
-51
lines changed

3 files changed

+46
-51
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,23 +5050,7 @@ compute_semi_anti_join_factors(PlannerInfo *root,
50505050
/*
50515051
* Also get the normal inner-join selectivity of the join clauses.
50525052
*/
5053-
norm_sjinfo.type = T_SpecialJoinInfo;
5054-
norm_sjinfo.min_lefthand = outerrel->relids;
5055-
norm_sjinfo.min_righthand = innerrel->relids;
5056-
norm_sjinfo.syn_lefthand = outerrel->relids;
5057-
norm_sjinfo.syn_righthand = innerrel->relids;
5058-
norm_sjinfo.jointype = JOIN_INNER;
5059-
norm_sjinfo.ojrelid = 0;
5060-
norm_sjinfo.commute_above_l = NULL;
5061-
norm_sjinfo.commute_above_r = NULL;
5062-
norm_sjinfo.commute_below_l = NULL;
5063-
norm_sjinfo.commute_below_r = NULL;
5064-
/* we don't bother trying to make the remaining fields valid */
5065-
norm_sjinfo.lhs_strict = false;
5066-
norm_sjinfo.semi_can_btree = false;
5067-
norm_sjinfo.semi_can_hash = false;
5068-
norm_sjinfo.semi_operators = NIL;
5069-
norm_sjinfo.semi_rhs_exprs = NIL;
5053+
init_dummy_sjinfo(&norm_sjinfo, outerrel->relids, innerrel->relids);
50705054

50715055
nselec = clauselist_selectivity(root,
50725056
joinquals,
@@ -5219,23 +5203,8 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
52195203
/*
52205204
* Make up a SpecialJoinInfo for JOIN_INNER semantics.
52215205
*/
5222-
sjinfo.type = T_SpecialJoinInfo;
5223-
sjinfo.min_lefthand = path->outerjoinpath->parent->relids;
5224-
sjinfo.min_righthand = path->innerjoinpath->parent->relids;
5225-
sjinfo.syn_lefthand = path->outerjoinpath->parent->relids;
5226-
sjinfo.syn_righthand = path->innerjoinpath->parent->relids;
5227-
sjinfo.jointype = JOIN_INNER;
5228-
sjinfo.ojrelid = 0;
5229-
sjinfo.commute_above_l = NULL;
5230-
sjinfo.commute_above_r = NULL;
5231-
sjinfo.commute_below_l = NULL;
5232-
sjinfo.commute_below_r = NULL;
5233-
/* we don't bother trying to make the remaining fields valid */
5234-
sjinfo.lhs_strict = false;
5235-
sjinfo.semi_can_btree = false;
5236-
sjinfo.semi_can_hash = false;
5237-
sjinfo.semi_operators = NIL;
5238-
sjinfo.semi_rhs_exprs = NIL;
5206+
init_dummy_sjinfo(&sjinfo, path->outerjoinpath->parent->relids,
5207+
path->innerjoinpath->parent->relids);
52395208

52405209
/* Get the approximate selectivity */
52415210
foreach(l, quals)

src/backend/optimizer/path/joinrels.c

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,38 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
654654
return true;
655655
}
656656

657+
/*
658+
* init_dummy_sjinfo
659+
* Populate the given SpecialJoinInfo for a plain inner join between rel1
660+
* and rel2
661+
*
662+
* Normally, an inner join does not have a SpecialJoinInfo node associated with
663+
* it. But some functions involved in join planning require one containing at
664+
* least the information of which relations are being joined. So we initialize
665+
* that information here.
666+
*/
667+
void
668+
init_dummy_sjinfo(SpecialJoinInfo *sjinfo, Relids left_relids,
669+
Relids right_relids)
670+
{
671+
sjinfo->type = T_SpecialJoinInfo;
672+
sjinfo->min_lefthand = left_relids;
673+
sjinfo->min_righthand = right_relids;
674+
sjinfo->syn_lefthand = left_relids;
675+
sjinfo->syn_righthand = right_relids;
676+
sjinfo->jointype = JOIN_INNER;
677+
sjinfo->ojrelid = 0;
678+
sjinfo->commute_above_l = NULL;
679+
sjinfo->commute_above_r = NULL;
680+
sjinfo->commute_below_l = NULL;
681+
sjinfo->commute_below_r = NULL;
682+
/* we don't bother trying to make the remaining fields valid */
683+
sjinfo->lhs_strict = false;
684+
sjinfo->semi_can_btree = false;
685+
sjinfo->semi_can_hash = false;
686+
sjinfo->semi_operators = NIL;
687+
sjinfo->semi_rhs_exprs = NIL;
688+
}
657689

658690
/*
659691
* make_join_rel
@@ -717,23 +749,7 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
717749
if (sjinfo == NULL)
718750
{
719751
sjinfo = &sjinfo_data;
720-
sjinfo->type = T_SpecialJoinInfo;
721-
sjinfo->min_lefthand = rel1->relids;
722-
sjinfo->min_righthand = rel2->relids;
723-
sjinfo->syn_lefthand = rel1->relids;
724-
sjinfo->syn_righthand = rel2->relids;
725-
sjinfo->jointype = JOIN_INNER;
726-
sjinfo->ojrelid = 0;
727-
sjinfo->commute_above_l = NULL;
728-
sjinfo->commute_above_r = NULL;
729-
sjinfo->commute_below_l = NULL;
730-
sjinfo->commute_below_r = NULL;
731-
/* we don't bother trying to make the remaining fields valid */
732-
sjinfo->lhs_strict = false;
733-
sjinfo->semi_can_btree = false;
734-
sjinfo->semi_can_hash = false;
735-
sjinfo->semi_operators = NIL;
736-
sjinfo->semi_rhs_exprs = NIL;
752+
init_dummy_sjinfo(sjinfo, rel1->relids, rel2->relids);
737753
}
738754

739755
/*
@@ -1682,6 +1698,14 @@ build_child_join_sjinfo(PlannerInfo *root, SpecialJoinInfo *parent_sjinfo,
16821698
AppendRelInfo **right_appinfos;
16831699
int right_nappinfos;
16841700

1701+
/* Dummy SpecialJoinInfos can be created without any translation. */
1702+
if (parent_sjinfo->jointype == JOIN_INNER)
1703+
{
1704+
Assert(parent_sjinfo->ojrelid == 0);
1705+
init_dummy_sjinfo(sjinfo, left_relids, right_relids);
1706+
return sjinfo;
1707+
}
1708+
16851709
memcpy(sjinfo, parent_sjinfo, sizeof(SpecialJoinInfo));
16861710
left_appinfos = find_appinfos_by_relids(root, left_relids,
16871711
&left_nappinfos);

src/include/optimizer/paths.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ extern bool have_join_order_restriction(PlannerInfo *root,
112112
extern bool have_dangerous_phv(PlannerInfo *root,
113113
Relids outer_relids, Relids inner_params);
114114
extern void mark_dummy_rel(RelOptInfo *rel);
115+
extern void init_dummy_sjinfo(SpecialJoinInfo *sjinfo, Relids left_relids,
116+
Relids right_relids);
115117

116118
/*
117119
* equivclass.c

0 commit comments

Comments
 (0)