tidb icon indicating copy to clipboard operation
tidb copied to clipboard

Index join hint do not take effect

Open alivxxx opened this issue 8 years ago • 0 comments

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)? c625c2723914be69327347650db080a0faafe3d3

alivxxx avatar Aug 30 '18 07:08 alivxxx