tidb
tidb copied to clipboard
Index join hint do not take effect
Please answer these questions before submitting your issue. Thanks!
- 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)
-
What did you expect to see? Second query should also choose index join.
-
What did you see instead? Second query chooses the hash join.
-
What version of TiDB are you using (
tidb-server -Vor runselect tidb_version();on TiDB)? c625c2723914be69327347650db080a0faafe3d3