当mysql中有大量行时,索引将不起作用

当mysql中有大量行时,索引将不起作用,mysql,Mysql,当我使用小日期范围时,索引就起作用了。疑问是 EXPLAIN select sum(principalBalance) as pos, count(id) as TotalCases, sum(amountPaid) as paid, count(amountPaid) as paidCount, sum(amountPdc) as Pdc,sum(amountPtp),count(amountPtp) from caseDetails USE index (updatedAt_caseDeta

当我使用小日期范围时,索引就起作用了。疑问是

EXPLAIN select sum(principalBalance) as pos, count(id) as TotalCases, sum(amountPaid) as paid, count(amountPaid) as paidCount, sum(amountPdc) as Pdc,sum(amountPtp),count(amountPtp) from caseDetails USE index (updatedAt_caseDetails) where updatedAt between '2016/06/01 00:00:00' AND '2016/07/26 23:59:00'
此查询的结果:

id  select_type table   partitions  type    possible_keys   key key_len ref rows    filtered    Extra
1   SIMPLE  caseDetails     range   updatedAt_caseDetails   updatedAt_caseDetails   6       607554  100 Using index condition; Using MRR
id  select_type table   partitions  type    possible_keys   key key_len ref rows    filtered    Extra
1   SIMPLE  caseDetails     ALL updatedAt_caseDetails               2898377 22.94   Using where
在这个结果中,您可以看到key=updatedAt\u案例详细信息索引正在工作

但当我们增加日期范围时,索引将不起作用:

EXPLAIN select sum(principalBalance) as pos, count(id) as TotalCases, sum(amountPaid) as paid, count(amountPaid) as paidCount, sum(amountPdc) as Pdc,sum(amountPtp),count(amountPtp) from caseDetails USE index (updatedAt_caseDetails) where updatedAt between '2016/06/01 00:00:00' AND '2016/07/30 23:59:00'
此查询的结果:

id  select_type table   partitions  type    possible_keys   key key_len ref rows    filtered    Extra
1   SIMPLE  caseDetails     range   updatedAt_caseDetails   updatedAt_caseDetails   6       607554  100 Using index condition; Using MRR
id  select_type table   partitions  type    possible_keys   key key_len ref rows    filtered    Extra
1   SIMPLE  caseDetails     ALL updatedAt_caseDetails               2898377 22.94   Using where

我应该使用力索引而不是使用索引: 使用力指数,其工作性能良好

查询结果将为:

解释选择sumprincipalBalance作为pos,countid作为TotalCases,sumamountPaid作为paid,countamountPaid作为paidCount,sumamountPdc作为Pdc,sumamountPtp,countamountPtp 根据案例详情,部队索引更新日期为“2016/06/01 00:00:00”至“2016/07/26 23:59:00”

结果将是: