Open
Description
这个SQL在我们自动化部署环境平均执行时间16秒,最高执行时间32秒,看代码每10秒一次,
建议添加组合索引,优化 SQL 以便命中索引:
- 去掉 ORDER BY id ASC 避免 MYSQL 走主键索引遍历全表 Using where
<select id="findFailJobLogIds" resultType="long" >
SELECT id FROM `xxl_job_log`
WHERE !(
(trigger_code in (0, 200) and handle_code = 0)
OR
(handle_code = 200)
)
AND `alarm_status` = 0
ORDER BY id ASC
LIMIT #{pagesize}
</select>
索引:
KEY `I_trigger_time` (`trigger_time`),
KEY `I_handle_code` (`handle_code`)
数据量:
handle_code 有索引
500 337115
200 193482
0 30351
trigger_code 无索引
200 552070
500 5768
0 2430
alarm_status 无索引
2 342881
0 217975
-1 2
Metadata
Assignees
Labels
No labels
Activity