首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql5.0 innoBD 引擎中关于order by XXX desc 的速度有关问题

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

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秒

不解..求指点

是不是没……

热点排行