报错:Communications link failure Last packet sent to the server was 563 ms ago,同事说SQL语句效率不够高,帮忙看下SQL语句及优化
在执行一个任务的时候报的异常.
Communications link failure Last packet sent to the server was 563 ms ago.
原SQL语句:
select sum(amount) as total from (select amount,userId from consume_log where type =1001 and recordtime<1214524800 and recordtime>=1212278400 union all select amount,userId from consume_log where type =2001 and recordtime<1214524800 and recordtime>=1212278400) as temp group by userId;
用mysql工具直接在服务器上查询所耗时间:293秒,五分钟左右,查询结果数据:520000+
现在想优化下这个SQL语句,偿试过改成
select sum(amount) as total from (select amount,userId
from consume_log where type =1001 or type=2001 and recordtime<1214524800 and recordtime>=1212278400 )
as temp group by userId;
结果时间更长,后面同事告诉我,使用or的时候不会去使用索引,速度不会快很多,现在不知道怎么搞了,大家帮忙想想办法,给个思路...