Skip to content
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

Index join hint do not take effect #7551

Closed
alivxxx opened this issue Aug 30, 2018 · 0 comments
Closed

Index join hint do not take effect #7551

alivxxx opened this issue Aug 30, 2018 · 0 comments
Assignees
Labels
sig/planner SIG: Planner

Comments

@alivxxx
Copy link
Contributor

alivxxx commented Aug 30, 2018

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
MySQL [test]> create table idxJoinOuter (a int unsigned);
Query OK, 0 rows affected (0.12 sec)
MySQL [test]> create table idxJoinInner (a int unsigned unique);
Query OK, 0 rows affected (0.02 sec)
MySQL [test]> explain select /*+ TIDB_INLJ(o, i)*/ * from idxJoinOuter o left join idxJoinInner i on o.a = i.a where o.a in (1, 2) and (i.a - 3) > 0;
+--------------------------+----------+------+---------------------------------------------------------------------------+
| id                       | count    | task | operator info                                                             |
+--------------------------+----------+------+---------------------------------------------------------------------------+
| IndexJoin_10             | 25.00    | root | inner join, inner:IndexReader_9, outer key:o.a, inner key:i.a             |
| ├─TableReader_13         | 20.00    | root | data:Selection_12                                                         |
| │ └─Selection_12         | 20.00    | cop  | in(o.a, 1, 2)                                                             |
| │   └─TableScan_11       | 10000.00 | cop  | table:o, range:[-inf,+inf], keep order:false, stats:pseudo                |
| └─IndexReader_9          | 0.00     | root | index:Selection_8                                                         |
|   └─Selection_8          | 0.00     | cop  | gt(minus(i.a, 3), 0)                                                      |
|     └─IndexScan_7        | 10.00    | cop  | table:i, index:a, range: decided by [o.a], keep order:false, stats:pseudo |
+--------------------------+----------+------+---------------------------------------------------------------------------+
7 rows in set (0.00 sec)
MySQL [test]> explain select /*+ TIDB_INLJ(o, i)*/ * from idxJoinOuter o left join idxJoinInner i on o.a = i.a where o.a in (1, 2) and i.a in (1,2) and (o.a-3) > 0 and (i.a - 3) > 0;
+-------------------------+----------+------+----------------------------------------------------------------------+
| id                      | count    | task | operator info                                                        |
+-------------------------+----------+------+----------------------------------------------------------------------+
| HashLeftJoin_7          | 20.00    | root | inner join, inner:IndexReader_14, equal:[eq(o.a, i.a)]               |
| ├─TableReader_11        | 16.00    | root | data:Selection_10                                                    |
| │ └─Selection_10        | 16.00    | cop  | gt(minus(o.a, 3), 0), in(o.a, 1, 2)                                  |
| │   └─TableScan_9       | 10000.00 | cop  | table:o, range:[-inf,+inf], keep order:false, stats:pseudo           |
| └─IndexReader_14        | 16.00    | root | index:Selection_13                                                   |
|   └─Selection_13        | 16.00    | cop  | gt(minus(i.a, 3), 0)                                                 |
|     └─IndexScan_12      | 20.00    | cop  | table:i, index:a, range:[1,1], [2,2], keep order:false, stats:pseudo |
+-------------------------+----------+------+----------------------------------------------------------------------+
7 rows in set (0.00 sec)
  1. What did you expect to see?
    Second query should also choose index join.

  2. What did you see instead?
    Second query chooses the hash join.

  3. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
    c625c27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner
Projects
None yet
Development

No branches or pull requests

3 participants