在给后台的执行SQL加上计时器之后,我惊讶地发现之前建立的索引根本没有被使用:它一直在用遍历所有记录的方法排序! 于是修改索引,测试,再修改,再测试。终于把贴子列表很卡的问题解决了。 问题的关键就是这样一条语句: select id,title,uid,fttime,hfcount from tz where bkid not in (select rowid from bk where notshow=1) order by fttime desc limit 0,20 tz.ftime / tz.bkid 都有索引,可是一直很慢,要2~5秒不等。但是,改成 select id,title,uid,fttime,hfcount from tz where bkid in(8,11) order by fttime desc limit 0,20 之后,0.03毫秒就完成了。 试了各种方法都没有解决,最后我给bk.notshow加了个索引,速度立即提升到0.05了。 我很不解,bk表就25行而已,加索引和不加为啥区别那么大?