首页 > 开发 > MySQL > 正文

mysql 影响行数大 实际结果特别小怎么优化呢

2017-09-08 09:11:53  来源:网友分享

Inoodb 的表, 进行简单的查询

select count('X') from AccountLogin where iNew = 1 and  dtEventTime  between '2012-10-22' and '2012-10-23'

iNew 和 dtEventTime 分别建立了单独的索引

查询结果其实只有 几十条 ,但是影响的行数特别大

请问这个SQL 该如何优化呢?

表里面的数据达到了千万级别

解决方案

show create table AccountLogin 发来看下,还有
explain select count('X') from AccountLogin where iNew = 1 and dtEventTime between '2012-10-22' and '2012-10-23';

这种查询如果多,应该建一个(iNew, dtEventTime)的索引,用上覆盖索引。