数据大概25万。select id,title from sell where status = 5 and catid in(605,1270,8310,1330,129,130,1320,52,66,90,21) order by vips ,updatetime desc limit 10000,20做了联合索引,status,catid,vips,updatetime 四个做的联系索引testi但是查询还是要0.22秒。还能再优化吗。explain结果如下*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: sell
         type: range
possible_keys: status,title,catid,status1,testi
          key: testi
      key_len: 5
          ref: NULL
         rows: 34948
        Extra: Using where; Using filesort
1 row in set (0.01 sec)这种情况还能再优化吗

解决方案 »

  1.   

    status,catid,vips,updatetime 这个索引去掉
    做成catid,status,vips,updatetime 这个顺序的联合索引
      

  2.   

    贴出你的
    show index from sell 
    以供分析。你目前的语句应该是只利用了 status,catid 的索引,然后生成结果后需要重新排序。
      

  3.   

    索引比较多,有些是别人建的.好象是取出数据再排序.如果把catid in换成 catid就正常.不用using filesort.
    Table  Non_unique  Key_name  Seq_in_index  Column_name  Collation  Cardinality  Sub_part  Packed  Null  Index_type  Comment 
    sell  0  PRIMARY  1  id  A  332625  NULL  NULL     BTREE   
    sell  1  editdate  1  editdate  A  1465  NULL  NULL     BTREE   
    sell  1  editdate  2  vips  A  1788  NULL  NULL     BTREE   
    sell  1  editdate  3  updatetime  A  166312  NULL  NULL     BTREE   
    sell  1  status  1  status  A  5  NULL  NULL     BTREE   
    sell  1  status  2  thumb  A  332625  NULL  NULL     BTREE   
     
    sell  1  time1  1  vips  A  8  NULL  NULL     BTREE   
    sell  1  time1  2  updatetime  A  166312  NULL  NULL     BTREE   
    sell  1  time1  3  id  A  332625  NULL  NULL     BTREE   
    sell  1  title  1  status  A  5  NULL  NULL     BTREE   
    sell  1  title  2  title  A  332625  NULL  NULL     BTREE     
    sell  1  catid  1  catid  A  273  NULL  NULL     BTREE        
    sell  1  status1  1  status  A  5  NULL  NULL     BTREE   
    sell  1  edittime  1  updatetime  A  166312  NULL  NULL     BTREE   
    sell  1  testi  1  status  A  5  NULL  NULL     BTREE   
    sell  1  testi  2  catid  A  1072  NULL  NULL     BTREE   
    sell  1  testi  3  vips  A  1439  NULL  NULL     BTREE   
    sell  1  testi  4  updatetime  A  166312  NULL  NULL     BTREE