ITPub博客

首页 > Linux操作系统 > Linux操作系统 > mysql oder by 使用index一例

mysql oder by 使用index一例

原创 Linux操作系统 作者:season0891 时间:2012-05-31 14:33:11 0 删除 编辑

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use lvh
Database changed
mysql> explain select * from job_queue where 1=1  order by opt_time desc ;
+----+-------------+-----------+------+---------------+------+---------+------+--------+----------------+
| id | select_type | table     | type | possible_keys | key  | key_len | ref  | rows   | Extra          |
+----+-------------+-----------+------+---------------+------+---------+------+--------+----------------+
|  1 | SIMPLE      | job_queue | ALL  | NULL          | NULL | NULL    | NULL | 454244 | Using filesort |
+----+-------------+-----------+------+---------------+------+---------+------+--------+----------------+
1 row in set (0.00 sec)

mysql> explain select * from job_queue where 1=1  order by opt_time desc limit 100,10;
+----+-------------+-----------+-------+---------------+--------------+---------+------+------+-------+
| id | select_type | table     | type  | possible_keys | key          | key_len | ref  | rows | Extra |
+----+-------------+-----------+-------+---------------+--------------+---------+------+------+-------+
|  1 | SIMPLE      | job_queue | index | NULL          | ind_opt_time | 9       | NULL |  110 |       |
+----+-------------+-----------+-------+---------------+--------------+---------+------+------+-------+
1 row in set (0.00 sec)

mysql> explain select * from job_queue  order by opt_time desc limit 100,10;
+----+-------------+-----------+-------+---------------+--------------+---------+------+------+-------+
| id | select_type | table     | type  | possible_keys | key          | key_len | ref  | rows | Extra |
+----+-------------+-----------+-------+---------------+--------------+---------+------+------+-------+
|  1 | SIMPLE      | job_queue | index | NULL          | ind_opt_time | 9       | NULL |  110 |       |
+----+-------------+-----------+-------+---------------+--------------+---------+------+------+-------+
1 row in set (0.00 sec)

mysql>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/90618/viewspace-731553/,如需转载,请注明出处,否则将追究法律责任。

上一篇: SHELL 执行 MYSQL
请登录后发表评论 登录
全部评论

注册时间:2008-06-10

  • 博文量
    791
  • 访问量
    1939056