select * From tb order by istop desc, pid desc limit 20,20
这样要500+ msselect * From tb order by  pid desc limit 20,20去掉 istop desc, 这样就是30ms 以下。istop 为tinyint(1) 值一般是0与1怎么办才可以加快速度。我把istop建索引基本没用。

解决方案 »

  1.   

    1、alter table tb order by istop desc, pid desc;
    OR
    2、alter table tb order by pid desc;
      

  2.   

    谢谢yueliangdao0608的解答,但问题又来了。
    现在如果要order by istop desc, pid desc不要WHERE就很快,或要WHERE不要order by istop desc, pid desc(要
    order by pid desc ,两样都要还是慢。相差是上百倍呢
    WHERE 里的我都建索引了的呀
      

  3.   

     ALTER TABLE `tb` ADD INDEX ( `pid ` , `istop` )  
      

  4.   

    现在列表在100ms左右了,原来要1500ms左右,但select * From tb where pid=1 or parentid=1 这样要2000++ms了,pid,parentid我都建索引的原来是pid=1 or parentid=1 只要100ms左右,order by istop desc, pid desc 要2000+ms这MY SQL的索引真不好调哦
      

  5.   

    Create an compose index if  you have additional where clause.
    i.e.select * From tb where a = ... order by istop desc, pid desc limit 20,20Then you can create an index defined with create index idx_u on tb(a,istop,pid);