tidb版本:v6.5.3
现象:
大概语句如下
select q.a,q,b from (
select a,b from table1 partition(p0520) where c >100 group by a,b) as n join table1 partition(p0520) q on n.a=q.a group by a,b;
默认执行计划是n和q 表走了个index hash join,我想让n 和 q 走个hash join ,我加的hint如下
select /*+hash_join_build(@qb1) */ q.a,q,b from (
select /*+ qb_name(qb1) */ a,b from table1 partition(p0520) where c >100 group by a,b) as n join table1 partition(p0520) q on n.a=q.a group by a,b;
发现这样的hint无法让语句走hash join,求助一下,上述语句怎么才能让走hash join
友利奈绪
2024 年5 月 23 日 07:29
2
select /*+hash_join_build(@qb1 ) / q.a,q,b from (
select / + qb_name(qb1) */ a,b from table1 partition(p0520) where c >100 group by a,b) as n join table1 partition(p0520) q on n.a=q.a group by a,b;
和select /*+hash_join_build(@qb1 ) */ q.a,-------->q,b <-----from ( 和这个位置符号错了有关系吗
有猫万事足
2024 年5 月 23 日 10:22
4
应该是bug来着,6.5.6以上的版本应该修复了
opened 12:26PM - 16 Aug 23 UTC
closed 12:36PM - 21 Aug 23 UTC
type/bug
sig/planner
severity/moderate
affects-6.5
epic/hint
affects-7.1
affects-7.5
## Enhancement
```
create table t1 (a int, key(a));
create table t2 (a int, k… ey(a));
explain select /*+ tidb_inlj(bb) */ aa.* from
(select * from t1) as aa
left join
(select t2.a, t2.a*2 as a2 from t2) as bb
on aa.a=bb.a;
mysql> show warnings;
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1815 | There are no matching table names for (bb) in optimizer hint /*+ INL_JOIN(bb) */ or /*+ TIDB_INLJ(bb) */. Maybe you can use the table alias name |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
也可以通过下面这种方式绕一下
select /*+hash_join_probe(q) */ q.a,q.b from (
select a,b from table1 partition(p0520) where c >100 group by a,b) as n join table1 partition(p0520) q on n.a=q.a group by a,b;
SELECT /*+ TIDB_HINT('hint_name') */ ... FROM (
SELECT ...
FROM table
WHERE condition
) AS sub_table;
在这个例子中,/*+ TIDB_HINT('hint_name') */
是添加的Hint,hint_name
是你想要使用的Hint的名称。然而,具体的Hint名称和用法取决于TiDB的版本和它所支持的Hint类型。
加号后面少写了一个空格?/*+ hash_join_build(@qb1 ) */