读书人

mysql5.0 innoBD 引擎中关于order by

发布时间: 2012-03-29 12:53:12 作者: rapoo

mysql5.0 innoBD 引擎中关于order by XXX desc 的速度问题
新手刚用mysql,请问一下一张a表3W条的记录

在a表的xxx字段建立索引
create index a_xxx on a(xxx desc);
然后

select * from table order by XXX 只需要 0.02秒
为什么用
select * from table order by XXX desc就需要 6-7秒

不解..求指点

是不是没有降序索引的,那小弟该如何使得倒序排序速度快一些呢?

[解决办法]
explain select * from table order by XXX ;
explain select * from table order by XXX desc;

看一下,BTREE理论上应该没有这么大的差别。 你的第一个语句是不是执行过了一次再执行的?

SQL code
mysql> select count(*) from (select * from t1 order by id )t;+----------+| count(*) |+----------+|   499999 |+----------+1 row in set (11.86 sec)mysql> select count(*) from (select * from t1 order by id desc)t;+----------+| count(*) |+----------+|   499999 |+----------+1 row in set (11.73 sec)mysql>
[解决办法]
探讨
新手刚用mysql,请问一下一张a表3W条的记录

在a表的xxx字段建立索引
create index a_xxx on a(xxx desc);
然后

select * from table order by XXX 只需要 0.02秒
为什么用
select * from table order by XXX desc就需要 6-7秒

不解..求指点

是不是没……

读书人网 >Mysql

热点推荐