mysql order by优化问题
explain select im.item_id from item_message im FORCE INDEX (item_id) where ( im.keyStr like '%拉%' ) and im.class = 1 and im.top = 0 and industry = '餐饮' order by im.item_id desc LIMIT 0 , 8
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE im index NULL item_id 4 NULL 8 Using where
以上sql,可以再继续优化吗,不知为什么,type哪里总是标识index,是因为我排序的字段item_id是唯一的值有关吗?
另外再问一个菜鸟问题,如果我不用FORCE INDEX (item_id),explain结果如下
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE im ref Industry,class,top Industry 63 const 1 Using where; Using filesort
这是为什么呢?虽然有了 Using filesort,但这里的type却是ref,非常不明白,而我用了FORCE INDEX 会使我其他索引,如
keyStr 的FULLTEXT 失效吗
附索引
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
item_message 0 PRIMARY 1 id A 8 NULL NULL BTREE
item_message 1 regional 1 regional A NULL NULL NULL YES BTREE
item_message 1 city 1 city A NULL NULL NULL BTREE
item_message 1 pic1 1 pic1 A NULL NULL NULL BTREE
item_message 1 pic2 1 pic2 A NULL NULL NULL BTREE
item_message 1 create_date 1 create_date A NULL NULL NULL BTREE
item_message 1 end_date 1 end_date A NULL NULL NULL BTREE
item_message 1 Industry 1 Industry A NULL NULL NULL YES BTREE
item_message 1 class 1 class A NULL NULL NULL BTREE
item_message 1 top 1 top A NULL NULL NULL BTREE
item_message 1 item_id 1 item_id A NULL NULL NULL BTREE
item_message 1 keyStr 1 keyStr NULL NULL NULL NULL YES FULLTEXT