有一个大概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  这样就会忽略索引,目前只有用这方法解决。

哪位高手可以指点下迷津么?到底该不该建索引,什么时候建索引,什么时候建联合索引?

 

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
验证你是否是机器人,请输入以下图片中的单词。 点击图片可以收听此验证码。
点击收听验证码