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都创建了索引

mysql 时间范围查询优化
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- threenewbee 2020-05-12 21:56关注
看符合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必要的字段,而不是*来节约。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报