mysql的force index

MSQL中使用order by 有个坑,会默认走order by 后面的索引。而不走where条件里应该走的索引。大家在使用时要绕过此坑。 

如下语句因为order by 走了settle_id这个主键,每次查询要4-6秒。

如果语句里非要有order by。那么将语句改写:

FROM

`wxhc_settle` force index (idx_user_id)

WHERE

`c_user_id` = 43865 

AND  gmt_create>'2018-09-12 00:00:00' 

AND `status` IN (0, 1)

ORDER BY

`settle_id` DESC

LIMIT 15,

45;

猜你喜欢

转载自www.cnblogs.com/ThinkVenus/p/9667564.html