mysql 时间范围查询优化

select * from table where createtime between '2019-01-01 00:00:00' and '2019-12-31 23:59:59' and storeid=1;
实际数据量17万条,扫描了77万行,数据总量为375万条数据,查询耗时85秒,请问一下怎么才能优化
其中storeid和createtime都创建了索引

看符合createtime between '2019-01-01 00:00:00' and '2019-12-31 23:59:59' 的数据有多少
storeid=1
有多少
用子查询看看
select * from( select * from table where createtime between '2019-01-01 00:00:00' and '2019-12-31 23:59:59' ) where storeid=1
或者
select * from( select * from table where storeid=1 ) where createtime between '2019-01-01 00:00:00' and '2019-12-31 23:59:59'

另外你返回的数据有17万?那么得考虑数据通讯的开销。可以select必要的字段,而不是*来节约。

可以把storeid放在时间的前面,你试下需要多久

msyql当查询数据大于五分之一时,就不走索引,所以得强制执行索引,在select * from table_name FORCE INDEX ( 组合索引 )
所谓组合索引,就是几个字段拼在一起组成的索引,排序有条件,像你的场景,组合索引,时间字段要排在最后

改为连接查询加分页实现