假设有一个sql
select
t_1.a,
t_2.c,
min(t_2.d)
from t_1
join t_2 on t1.b = t2.b
group by t1.a, t2.c
架构如下
CREATE TABLE `t_1` (
`a` bigint(20) NOT NULL,
`b` bigint(20) NOT NULL,
UNIQUE KEY `idx_a_b` (`a`,`b`),
KEY `idx_a` (`a`),
KEY `idx_b` (`b`),
) ENGINE=InnoDB CHARSET=utf8;
CREATE TABLE `t_2` (
`b` bigint(20) NOT NULL,
`c` bigint(20) NOT NULL,
`d` int(11) NOT NULL,
UNIQUE KEY `b` (`b`,`c`),
KEY `idx_c` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
解释如下所示
1 SIMPLE t_2 ALL b NULL NULL NULL 285480使用临时;使用filesort
1 SIMPLE t_1 ref idx_b idx_b 8 t_2.b 11