有一个菜鸟问题。假设我创建了下表:
温度1
向上,varchar(15)
dn,varchar(15)
我添加了几个指标:
create table temp1 (up varchar(15), dn varchar(15), index id1(up), index id2(dn))
在我用一些随机数据填充表后,我执行以下解释选择
explain select * from temp1 as t1, temp1 as t2 where t1.up = t2.up
并得到
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | ALL | id1 | NULL | NULL | NULL | 4 | |
| 1 | SIMPLE | t2 | ALL | id1 | NULL | NULL | NULL | 3 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
为什么优化器不使用键?!我一定错过了一些非常简单的东西。. .
(我问这个问题是因为与我实际使用的表(700K 行)的类似查询运行速度非常慢,我猜它与索引有关)。
谢谢您的帮助!