indexing won't work when we have large amount of rows in mysql -


when using small date range indexing working. query is

explain select sum(principalbalance) pos, count(id) totalcases, sum(amountpaid) paid, count(amountpaid) paidcount, sum(amountpdc) pdc,sum(amountptp),count(amountptp) casedetails use index (updatedat_casedetails) updatedat between '2016/06/01 00:00:00' , '2016/07/26 23:59:00' 

result of query:

id  select_type table   partitions  type    possible_keys   key key_len ref rows    filtered    1   simple  casedetails     range   updatedat_casedetails   updatedat_casedetails   6       607554  100 using index condition; using mrr 

in result can see key=updatedat_casedetails indexing working

but when increase date range indexing wont work:

explain select sum(principalbalance) pos, count(id) totalcases, sum(amountpaid) paid, count(amountpaid) paidcount, sum(amountpdc) pdc,sum(amountptp),count(amountptp) casedetails use index (updatedat_casedetails) updatedat between '2016/06/01 00:00:00' , '2016/07/30 23:59:00' 

result of query:

id  select_type table   partitions  type    possible_keys   key key_len ref rows    filtered    1   simple  casedetails     updatedat_casedetails               2898377 22.94   using 

i should use force index () instead of use index(): using force index working fine.

result query be:

explain select sum(principalbalance) pos, count(id) totalcases, sum(amountpaid) paid, count(amountpaid) paidcount, sum(amountpdc) pdc,sum(amountptp),count(amountptp) casedetails force index (updatedat_casedetails) updatedat between '2016/06/01 00:00:00' , '2016/07/26 23:59:00'

result be: enter image description here


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -