-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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: fix bugs related to TIDB_INLJ hint #11253
Changes from 3 commits
f268cf1
c23b6b1
b3e6506
277a20e
943444a
41c1828
e96d277
74216c7
a9b60c9
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 |
---|---|---|
|
@@ -312,6 +312,12 @@ func (p *LogicalJoin) extractOnCondition(conditions []expression.Expression, der | |
|
||
func extractTableAlias(p LogicalPlan) *model.CIStr { | ||
foreyes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if p.Schema().Len() > 0 && p.Schema().Columns[0].TblName.L != "" { | ||
tblName := p.Schema().Columns[0].TblName.L | ||
for _, column := range p.Schema().Columns { | ||
if column.TblName.L != tblName { | ||
winoros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil | ||
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. What about returns all alias table name here. Then index lookup join hint may be effective in more situation. 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. This feature will be added later, we will have some Join Order Hints. By the way, index lookup join doesn't seem to be able to work when there are multiple alias. 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. Because there is no available index in this situation. 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. tidb(localhost:4000) > drop table if exists t;
Query OK, 0 rows affected (0.02 sec)
tidb(localhost:4000) > create table t(a int, b int, primary key(a));
Query OK, 0 rows affected (0.00 sec)
tidb(localhost:4000) > explain select /*+ TIDB_INLJ(t1) */ t1.b, t2.a from t t1, t t2, t t3 where t1.a = t2.a and t1.a = t3.a;
+----------------------------+----------+------+------------------------------------------------------------+
| id | count | task | operator info |
+----------------------------+----------+------+------------------------------------------------------------+
| Projection_9 | 15625.00 | root | test.t1.b, test.t2.a |
| └─MergeJoin_10 | 15625.00 | root | inner join, left key:test.t3.a, right key:test.t1.a |
| ├─TableReader_17 | 10000.00 | root | data:TableScan_16 |
| │ └─TableScan_16 | 10000.00 | cop | table:t3, range:[-inf,+inf], keep order:true, stats:pseudo |
| └─MergeJoin_18 | 12500.00 | root | inner join, left key:test.t1.a, right key:test.t2.a |
| ├─TableReader_25 | 10000.00 | root | data:TableScan_24 |
| │ └─TableScan_24 | 10000.00 | cop | table:t1, range:[-inf,+inf], keep order:true, stats:pseudo |
| └─TableReader_27 | 10000.00 | root | data:TableScan_26 |
| └─TableScan_26 | 10000.00 | cop | table:t2, range:[-inf,+inf], keep order:true, stats:pseudo |
+----------------------------+----------+------+------------------------------------------------------------+
9 rows in set, 1 warning (0.00 sec) Actually, in this case, 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. Because Hint only influence joins involving t1 , it should not enforce parent join to use Index Join. The parent join compares Index Join + Index Join(Hint works) and Merge Join + Merge Join(Hint doesn't work because Merge Join require order, t1 can't be inner table in this situation), and choose the second as the best one. If change the condition into t1.a = t2.a AND t2.a = t3.a, optimizer will choose Merge Join + Index Join, because t1 is able to be inner table in this situation. Actually, they are the same...Maybe we can do some optimize? Kenan & me are going to enhance Optimizer Hints. 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. Use Hint |
||
} | ||
} | ||
return &(p.Schema().Columns[0].TblName) | ||
} | ||
return nil | ||
|
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.
They can both be not nil? consider the situation that
leftJoins != nil && rightJoins != nil && lhsCardinality == rhsCardinality
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 case have been listed in the next line of comments. Do I need to explain more specifically in the comments?
In this case,
leftOuter
andrightOuter
must be bothfalse
or bothtrue
, and the result ofenforced
are all correct in these cases.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.
I think this comment can be removed, it explains nothing useful for the reviewer to understand the following code logic.
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.
Okay, It's really confusing.