update call_record set duration=
case duration
when '-1' then '2'
else duration
end
where line_name='801' order by `time` desc limit 1这个表有10几W数据, duration,line_name, time 都为索引,现在这个语句耗时10几毫秒,我的系统其它语句都是0.3毫秒,请问怎么优化这个语句?优化mysqlcase when
case duration
when '-1' then '2'
else duration
end
where line_name='801' order by `time` desc limit 1这个表有10几W数据, duration,line_name, time 都为索引,现在这个语句耗时10几毫秒,我的系统其它语句都是0.3毫秒,请问怎么优化这个语句?优化mysqlcase when
贴出你的
show index from call_record;
explain select * from call_record where line_name='801' order by `time` desc limit 1;以供分析。
理论上创建了 index(line_name,time) 应该就已经非常优化了。
我多加了保存每个line_name最大的time,
这样直接类似 where duration=-1 and line_name='801' and time=max_time 就可以了,耗时0.3毫秒内现在我的系统运行起来了也才1-2%cpu,优化成功!谢谢大家