关于MYSQL的性能问题?

select count(1) from A
where 
1=1  and `status`=0 and `type` in (1,2,3,4,5) and 
`type` ='1' AND time >= "1451185080";

select count(1) from A
where
1=1   and `status`=0 and 
`type` ='1' AND time >= "1451185080";

的性能一样吗?

阅读 2.8k
2 个回答

如果mysql优化器不够智能的话,第一个sql就会先找到type满足1,2,3,4,5的,然后再找type=1的,肯定比第二个sql性能差。
具体试试就知道了

下面一个性能应该会好一点。
1=1会被优化掉,然后in语句貌似不能索引命中。在其他SQL上in语句会索引命中的

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题