我用是MySQL 4.1.20直以为当表某列出现在查询语句order by中时如果这个列建了索引MySQL利用这个索引现在才发现这个想当然是
这几天对数据库跟踪我发现总是有些特简单SQL执行起来特别慢
如:select id,title from sources where status=1 and isrepeat=0 order by id desc limit 0,30;
这个查询执行大概需要3s表sources大概有26万数据,id是自增主键status和isrepeat都建了索引使用explain看下MySQL是如何解释他:
居然没有用到主键索引(id)再看看MySQL是如何解释几乎同样SQL(select id,title from sources where status=1 and isrepeat=0 and id>0 order by id desc limit 0,30;):
最新评论