planner: fix bugs related to TIDB_INLJ hint#11253
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11253 +/- ##
================================================
+ Coverage 81.2684% 81.2753% +0.0069%
================================================
Files 423 423
Lines 90094 90106 +12
================================================
+ Hits 73218 73234 +16
Misses 11581 11581
+ Partials 5295 5291 -4 |
Codecov Report
@@ Coverage Diff @@
## master #11253 +/- ##
===========================================
Coverage 81.5135% 81.5135%
===========================================
Files 423 423
Lines 91045 91045
===========================================
Hits 74214 74214
Misses 11541 11541
Partials 5290 5290 |
|
/run-all-tests |
|
PTAL @winoros |
|
/run-all-tests |
| tblName := p.Schema().Columns[0].TblName.L | ||
| for _, column := range p.Schema().Columns { | ||
| if column.TblName.L != tblName { | ||
| return nil |
There was a problem hiding this comment.
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.
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.
Because there is no available index in this situation.
There was a problem hiding this comment.
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, t2.a and t3.a are indices. But we can't choose the index join with TIDB_INLJ hint.
There was a problem hiding this comment.
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.
Use Hint TIDB_INLJ(t1, t3) may lead to Index Join + Index Join.
|
/run-all-tests |
|
|
||
| // This function will return the table alias of a given logical plan. | ||
| // If there're multiple tables, it will return nil. | ||
| // This function will be further developed in the future. |
There was a problem hiding this comment.
This line provides little info and makes me curious, you can add more details like what will be developed and why.
There was a problem hiding this comment.
I have rewrite the comments... I find out it may only be influenced by Schema refactoring.
a8f2fa8 to
60f40cc
Compare
|
/run-all-tests |
|
/run-all-tests |
2 similar comments
|
/run-all-tests |
|
/run-all-tests |
|
/run-all-tests |
|
/run-all-tests |
|
After my strange operation, the approve is lost. @zz-jason |
|
I find out it's not the latest version, I have to reset to another commit. @zz-jason |
|
Dismiss again. I used force-push too carelessly, I'll pay attention next time. @zz-jason |
|
cherry pick to release-2.1 in PR #11361 |
|
cherry pick to release-3.0 in PR #11362 |
What problem does this PR solve?
SQL Hint doesn't work correctly in some cases:
What is changed and how it works?
Fix the logic of tryToGetIndexJoin, it won't return incorrect
forcedany more.Fix function extractTableAlias, to ensure the table alias is available.
Check List
Tests
Side effects