MYSQL使用的索引不合适,指定索引
公司有个user_main表 结构如下
索引如下
慢sql
SELECT * FROM user_main WHERE updateTime >= '2021-09-08 01:30:02.01' AND updateTime <= '2021-09-10 01:30:01.664' AND RIGHT(userId,1) = 2 AND userId>10000 ORDER BY userId ASC LIMIT 1000;
指定索引 FORCE INDEX (idx_updateTime)
SELECT * FROM user_main FORCE INDEX (idx_updateTime) WHERE updateTime >= '2021-09-08 01:30:02.01' AND updateTime <= '2021-09-10 01:30:01.664' AND RIGHT(userId,1) = 2 AND userId>10000 ORDER BY userId ASC LIMIT 1000;
执行计划