[英]How to optimize update query with calculation on MySQL with big data
i want to update data on mysql table, this table have 2.258.164 row there is the query 我想更新mysql表上的数据,该表有2.258.164行,有查询
select ch_0
from bmkg.tb_datastore_2017
WHERE id_station='150001'
AND date_time<'2017-02-06 17:30:00'
and DATE_FORMAT(`date_time`,'%Y-%m-%d') = '2017-02-06'
order by date_time Desc limit 1
this query need 55-60 second, its to slowly, Please help me to optimize this.. Thank you, Warmest regards, 此查询需要55-60秒,它要慢慢来,请帮助我进行优化。.谢谢,最热烈的问候,
You can use BETWEEN to prevent a FULL TABLE SCAN 您可以使用BETWEEN来防止FULL TABLE SCAN
SELECT ch_0
FROM bmkg.tb_datastore_2017
WHERE id_station='150001'
AND `date_time` BETWEEN '2017-02-06 00:00:00' AND '2017-02-06 17:30:00'
ORDER BY date_time DESC
LIMIT 1;
please post also the EXPLAIN of my query to see if there are any INDEX 请还张贴解释我的查询,看看是否有任何INDEX
SELECT ch_0
FROM bmkg.tb_datastore_2017
WHERE id_station='150001'
AND `date_time` BETWEEN '2017-02-06 00:00:00' AND '2017-02-06 17:30:00'
ORDER BY date_time DESC
LIMIT 1;
Please try this.And let me know how much time it took to execute with same data. 请尝试一下。让我知道用相同的数据执行需要花费多少时间。 Hope this will helps you.
希望这对您有帮助。
You can also use like this :- 您也可以这样使用:-
select ch_0
from bmkg.tb_datastore_2017
WHERE id_station='150001'
AND date_time<'2017-02-06 17:30:00' and DATE(`date_time`) = '2017-02-06'
order by date_time Desc limit 1;
I too was stuck with such issue and using Date() function solved by problem or else you can share EXPLAIN plan for your query so that we can analyse more. 我也一直困扰于此类问题,并使用由问题解决的Date()函数,否则您可以为您的查询共享EXPLAIN计划,以便我们进行更多分析。
Thanks, 谢谢,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.