首页 新闻 搜索 专区 学院

mysql 查询范围能影响使用的索引!

0
[待解决问题]
mysql> explain select count(*) from ctc_sms_ent where nstat=0 and timeMillis>(1321439756000-147000-0) and timeMillis<=1321439756000;
+----+-------------+-------------+-------+---------------+-------------+---------+------+-------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+-------+---------------+-------------+---------+------+-------+-------------+
| 1 | SIMPLE | ctc_sms_ent | range | millisIndex | millisIndex | 9 | NULL | 83844 | Using where |
+----+-------------+-------------+-------+---------------+-------------+---------+------+-------+-------------+
1 row in set

mysql> explain select count(*) from ctc_sms_ent where nstat=0 and timeMillis>(1321439756000-147000-1) and timeMillis<=1321439756000;
+----+-------------+-------------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+------+---------------+------+---------+------+--------+-------------+
| 1 | SIMPLE | ctc_sms_ent | ALL | millisIndex | NULL | NULL | NULL | 500039 | Using where |
+----+-------------+-------------+------+---------------+------+---------+------+--------+-------------+
1 row in set

mysql> explain select count(*) from ctc_sms_ent where nstat=0 and timeMillis>(1321439756000-147000+1) and timeMillis<=1321439756000;
+----+-------------+-------------+-------+---------------+-------------+---------+------+-------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+-------+---------------+-------------+---------+------+-------+-------------+
| 1 | SIMPLE | ctc_sms_ent | range | millisIndex | millisIndex | 9 | NULL | 83844 | Using where |
+----+-------------+-------------+-------+---------------+-------------+---------+------+-------+-------------+
1 row in set
xiabibocnblogs的主页 xiabibocnblogs | 初学一级 | 园豆:200
提问于:2011-11-17 15:44
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册