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
plan: new plan support index look up join. #3281
Conversation
plan/new_physical_plan_builder.go
Outdated
@@ -113,6 +113,168 @@ func (p *Projection) convert2NewPhysicalPlan(prop *requiredProp) (taskProfile, e | |||
return task, p.storeTaskProfile(prop, task) | |||
} | |||
|
|||
func (p *LogicalJoin) getIndexJoinKey(inner Plan) []*expression.Column { |
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.
Remove this function since it is not called by others.
plan/new_physical_plan_builder.go
Outdated
@@ -133,7 +295,7 @@ func (p *LogicalJoin) convert2NewPhysicalPlan(prop *requiredProp) (taskProfile, | |||
default: | |||
if p.preferUseMergeJoin() { | |||
task, err = p.convert2MergeJoin(prop) | |||
} else { | |||
} else if task, err = p.tryToGetIndexJoin(prop); task == nil && err == nil { | |||
// TODO: We will consider index look up join in the future. |
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.
remove this comment
plan/plan.go
Outdated
@@ -113,6 +113,15 @@ type requiredProp struct { | |||
taskTp taskType | |||
} | |||
|
|||
func (p *requiredProp) checkMatchSchema(schema *expression.Schema) bool { |
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.
This function is not called by others.
plan/new_physical_plan_builder.go
Outdated
return matchOffsets | ||
} | ||
|
||
func (p *LogicalJoin) convertToIndexJoin(prop *requiredProp, outerIdx int) (taskProfile, error) { |
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.
add a comment for outerIdx.
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.
Rest LGTM.
plan/new_physical_plan_builder.go
Outdated
|
||
// convertToIndexJoin will generate index join by required properties and outerIndex. OuterIdx points out the outer child, | ||
// because we will swap the children of join when the right child is outer child. | ||
// First of all, we will extract th join keys for p's equal conditions. If the join keys can match some of the indices or pk |
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.
s/th/the
plan/new_physical_plan_builder.go
Outdated
return task, nil | ||
} | ||
|
||
func (p *LogicalJoin) tryToGetIndexJoin(prop *requiredProp) (taskProfile, error) { |
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.
add a comment for this function.
LGTM |
sql: "select /*+ TIDB_INLJ(t1, t2) */ * from t t1 left outer join t t2 on t1.a = t2.a and t2.b < 1", | ||
best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([lt(t2.b, 1)]))}(t1.a,t2.a)", | ||
}, | ||
// Test Index Join failed. |
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.
Join failed?
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.
Fail to use index join
plan/new_physical_plan_builder.go
Outdated
@@ -133,7 +295,7 @@ func (p *LogicalJoin) convert2NewPhysicalPlan(prop *requiredProp) (taskProfile, | |||
default: | |||
if p.preferUseMergeJoin() { | |||
task, err = p.convert2MergeJoin(prop) | |||
} else { | |||
} else if task, err = p.tryToGetIndexJoin(prop); task == nil && err == nil { | |||
// TODO: We will consider index look up join in the future. |
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.
Should we update this comment?
return nil | ||
} | ||
for i, col := range p.tableInfo.Columns { | ||
if mysql.HasPriKeyFlag(col.Flag) { |
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.
Should we consider composed primary key?
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.
composed primary key is index
if !found { | ||
return nil | ||
} | ||
if i+1 == len(keys) { |
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.
This is not "keys match all columns in index." but "all keys match columns in index."
@shenli PTAL |
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.
LGTM
I give up the old index look up join which uses apply and create a new indexJoin Plan.
@shenli @zimulala @winoros PTAL