[英]Mysql Very Long Time in Query Execution
I have get the query in this thread Sum Multiple Row Date Difference Mysql 我在此线程中得到查询总和多行日期差异Mysql
The problem now is that the query execution time is so long. 现在的问题是查询执行时间太长。 I try with a little row data http://sqlfiddle.com/#!2/0d496/1/0 . 我尝试使用一些行数据http://sqlfiddle.com/#!2/0d496/1/0 。 And it is like crazy thing when i try to execute this query in my local database (my table total row is about 200.000 row), because there is no result even when I wait in a very long time. 当我尝试在本地数据库中执行此查询时(我的表总行约为200.000行),这就像疯狂的事情,因为即使我等待很长时间也没有结果。
I want to ask, is this query by default need a long time to execute? 我想问一下,默认情况下此查询是否需要很长时间才能执行? Is it possible to make it faster? 有可能使其更快吗? How? 怎么样? Thank you. 谢谢。
Try adding Speed to your index: 尝试将Speed添加到索引中:
KEY LogCarIdx
( LogDate
, CarId
, Speed
) 关键LogCarIdx
( LogDate
, CarId
, Speed
)
Then the c1 based query uses the index (so says explain). 然后基于c1的查询使用索引(因此请解释一下)。 Can't tell the speed difference in the sqlfiddle, but might help in the full size query. 无法在sqlfiddle中分辨出速度差异,但可能对全尺寸查询有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.