mysql的force index

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

以下语句由于order by 走了settle_id这个主键,每次查询要4-6秒。blog

 

若是语句里非要有order by。那么将语句改写:索引

FROMclass

`wxhc_settle` force index (idx_user_id)im

WHERE查询

`c_user_id` = 43865 img

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

AND `status` IN (0, 1)ps

ORDER BYindex

`settle_id` DESC

LIMIT 15,

45;

相关文章
相关标签/搜索