Mysql索引优化遇到的有关问题

Mysql索引优化遇到的有关问题

Mysql索引优化遇到的问题

今天在写sql语句时有语句如下:

select article_id from articles
 where status=1 and (create_time between '2012-05-30 00:00:00' and '2012-06-30 00:00:00') order by read_num desc

为优化该sql,我自信满满的建立组合索引(status,create_time,read_num),当sql语句解析时,却显示如下:

Using where; Using index; Using filesort

出现了最不该出现的Using filesort,查阅了多方资料将索引改为(status,read_num)后一切正常了,原因如下:

(status,create_time,read_num)组合索引看似非常完美,由于create_time不是确定值,使用该组合索引的话仍会一个个找出符合create_time的值后再对其进行排序,会出现file soft,解决办法为使用(status,read_num)索引即可

?

?

?

Mysql索引优化遇到的有关问题

相关文章:

你感兴趣的文章:

标签云: