Mysql的索引有时候会影响效率?
有一个大概5万条记录的表!其中字段a上面做了索引的。在不排序的情况下效率都挺高。
用 select * from table where a>10 order by id desc limit 0,30,效率很低大概需要 0.17秒左右。
用 select * from table where a=10 order by id desc limit 0,30 的效率还不错,只需要0.012秒。
在删除索引之后。
select * from table where a>10 order by id desc limit 0,30 只需要 0.0007秒
用 select * from table where a=10 order by id desc limit 0,30 却需要 0.125秒
所以出现了一个疑问。a>10这样的where子句似乎建了索引效率更低了。
但是如果使用
select * from table where a+0>10 order by id desc limit 0,30 这样就会忽略索引,目前只有用这方法解决。
哪位高手可以指点下迷津么?到底该不该建索引,什么时候建索引,什么时候建联合索引?
Recent Comments
- 为你牵挂 发表在《留言本》
- 灰常记忆 发表在《留言本》
- Visper 发表在《MeiuPic 2.1.0 发布!》
- 诺盾监控 发表在《MeiuPic 2.1.0 发布!》
- joe 发表在《留言本》
Archives









