MySQL:Ver 14.12 Distrib 5.0.51b,用于 redhat-linux-gnu (x86_64) 使用 EditLine 包装器
sql_1:
SELECT SQL_NO_CACHE COUNT(*) FROM `ting_song_info`;
结果 :
+----------+
| COUNT(*) |
+----------+
| 2637447 |
+----------+
1 row in set (0.42 sec)
解释 :
+----+-------------+----------------+-------+---------------+-------------------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------------+-------+---------------+-------------------+---------+------+---------+-------------+
| 1 | SIMPLE | ting_song_info | index | NULL | total_listen_nums | 4 | NULL | 2769410 | Using index |
+----+-------------+----------------+-------+---------------+-------------------+---------+------+---------+-------------+
sql_1 使用密钥total_listen_nums
。
然后指定密钥。
sql_2:
SELECT SQL_NO_CACHE COUNT(*) FROM `ting_song_info` USE KEY(`album_id`);
结果 :
+----------+
| COUNT(*) |
+----------+
| 2637447 |
+----------+
1 row in set (5.21 sec)
解释:
+----+-------------+----------------+-------+---------------+----------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------------+-------+---------------+----------+---------+------+---------+-------------+
| 1 | SIMPLE | ting_song_info | index | NULL | album_id | 8 | NULL | 2769410 | Using index |
+----+-------------+----------------+-------+---------------+----------+---------+------+---------+-------------+
total_listen_nums 的 key_len 比album_id 更小。
这就是sql_1使用total_listen_nums的原因吗?