-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
planner: support push down broadcast cartesian join to TiFlash #25049
Changes from all commits
6389486
c43b446
4896c8b
b7b4a73
1cf6b51
1edb01f
f892839
440907f
c3ec801
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1661,6 +1661,9 @@ func (p *LogicalJoin) shouldUseMPPBCJ() bool { | |
if p.ctx.GetSessionVars().BroadcastJoinThresholdSize == 0 || p.ctx.GetSessionVars().BroadcastJoinThresholdCount == 0 { | ||
return p.ctx.GetSessionVars().AllowBCJ | ||
} | ||
if len(p.EqualConditions) == 0 && p.ctx.GetSessionVars().AllowCartesianBCJ == 2 { | ||
return true | ||
} | ||
if p.JoinType == LeftOuterJoin || p.JoinType == SemiJoin || p.JoinType == AntiSemiJoin { | ||
return checkChildFitBC(p.children[1]) | ||
} else if p.JoinType == RightOuterJoin { | ||
|
@@ -1769,9 +1772,19 @@ func (p *LogicalJoin) tryToGetMppHashJoin(prop *property.PhysicalProperty, useBC | |
return nil | ||
} | ||
|
||
if (p.JoinType != InnerJoin && p.JoinType != LeftOuterJoin && p.JoinType != RightOuterJoin && p.JoinType != SemiJoin && p.JoinType != AntiSemiJoin) || len(p.EqualConditions) == 0 { | ||
if p.JoinType != InnerJoin && p.JoinType != LeftOuterJoin && p.JoinType != RightOuterJoin && p.JoinType != SemiJoin && p.JoinType != AntiSemiJoin { | ||
return nil | ||
} | ||
|
||
if len(p.EqualConditions) == 0 { | ||
if p.ctx.GetSessionVars().AllowCartesianBCJ == 0 || !useBCJ { | ||
return nil | ||
} | ||
} | ||
if (len(p.LeftConditions) != 0 && p.JoinType != LeftOuterJoin) || (len(p.RightConditions) != 0 && p.JoinType != RightOuterJoin) { | ||
return nil | ||
} | ||
Comment on lines
+1784
to
+1786
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add this? |
||
|
||
if prop.PartitionTp == property.BroadcastType { | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,11 @@ | |
"explain format = 'brief' select count(*) from fact_t where exists (select 1 from d1_t where d1_k = fact_t.d1_k)", | ||
"explain format = 'brief' select count(*) from fact_t where exists (select 1 from d1_t where d1_k = fact_t.d1_k and value > fact_t.col1)", | ||
"explain format = 'brief' select count(*) from fact_t where not exists (select 1 from d1_t where d1_k = fact_t.d1_k)", | ||
"explain format = 'brief' select count(*) from fact_t where not exists (select 1 from d1_t where d1_k = fact_t.d1_k and value > fact_t.col1)" | ||
"explain format = 'brief' select count(*) from fact_t where not exists (select 1 from d1_t where d1_k = fact_t.d1_k and value > fact_t.col1)", | ||
"explain format = 'brief' select count(*) from fact_t join d1_t on fact_t.d1_k > d1_t.d1_k", | ||
"explain format = 'brief' select count(*) from fact_t left join d1_t on fact_t.d1_k > d1_t.d1_k", | ||
"explain format = 'brief' select count(*) from fact_t right join d1_t on fact_t.d1_k > d1_t.d1_k", | ||
"explain format = 'brief' select count(*) from fact_t where d1_k not in (select d1_k from d1_t)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add some example for semi join? |
||
] | ||
}, | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -486,6 +486,12 @@ type SessionVars struct { | |
|
||
// AllowBCJ means allow broadcast join. | ||
AllowBCJ bool | ||
|
||
// AllowCartesianBCJ means allow broadcast CARTESIAN join, 0 means not allow, 1 means allow broadcast CARTESIAN join | ||
// but the table size should under the broadcast threshold, 2 means allow broadcast CARTESIAN join even if the table | ||
// size exceeds the broadcast threshold | ||
AllowCartesianBCJ int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sessioni level or instance level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. session level. |
||
|
||
// AllowDistinctAggPushDown can be set true to allow agg with distinct push down to tikv/tiflash. | ||
AllowDistinctAggPushDown bool | ||
|
||
|
@@ -971,6 +977,7 @@ func NewSessionVars() *SessionVars { | |
StmtCtx: new(stmtctx.StatementContext), | ||
AllowAggPushDown: false, | ||
AllowBCJ: false, | ||
AllowCartesianBCJ: DefOptCartesianBCJ, | ||
BroadcastJoinThresholdSize: DefBroadcastJoinThresholdSize, | ||
BroadcastJoinThresholdCount: DefBroadcastJoinThresholdSize, | ||
OptimizerSelectivityLevel: DefTiDBOptimizerSelectivityLevel, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why add this?
a inner join cannot have leftConditions or rightConditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because TiFlash assuming
leftConditions
only exists forleft join
andrightConditions
only exists forright join