近日在项目中尝试使用如下语句返回列表

select * from dtu_log as l left join e as e on l.dlog_ele=e.id where 1=1 and e.maint_com=1 order by dlog_id desc limit 0,20

数据总量90w
查询耗时要5.5156秒多,无法接收
使用EXPLAIN查询,发现l并没有使用dlog_id作为索引
最终使用FORCE INDEX (PRIMARY) 强制索引解决该问题

修改后的语句为

select * from dtu_log as l FORCE INDEX (PRIMARY) left join e as e on l.dlog_ele=e.id where 1=1 and e.maint_com=1 order by dlog_id desc limit 0,20

同样的数据,修改后查询耗时0.0016秒
有了很好的改善,特此记录一次