MyISAM和InnoDB通过主键自增ID排序区别

来源:互联网 发布:matlab高级编程基础 编辑:程序博客网 时间:2024/05/16 07:22

1、MyISAM在通过主键排序时没有用到索引,而是直接用的文件排序

mysql> alter table edu_text engine=myisam;

Query OK, 5 rows affected (0.23 sec)
Records: 5  Duplicates: 0  Warnings: 0


mysql> explain select id,title,time from edu_text order by id;
+----+-------------+----------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table    | type | possible_keys | key  | key_len | ref  | rows | Extra          |
+----+-------------+----------+------+---------------+------+---------+------+------+----------------+
|  1 | SIMPLE      | edu_text | ALL  | NULL          | NULL | NULL    | NULL |    5 | Using filesort |
+----+-------------+----------+------+---------------+------+---------+------+------+----------------+

1 row in set (0.00 sec)


2、InnoDB通过主键排序

mysql> alter table edu_text engine=innodb;
Query OK, 5 rows affected (0.39 sec)
Records: 5  Duplicates: 0  Warnings: 0


mysql> explain select id,title,time from edu_text order by id;
+----+-------------+----------+-------+---------------+---------+---------+------+------+-------+
| id | select_type | table    | type  | possible_keys | key     | key_len | ref  | rows | Extra |
+----+-------------+----------+-------+---------------+---------+---------+------+------+-------+
|  1 | SIMPLE      | edu_text | index | NULL          | PRIMARY | 4       | NULL |    5 | NULL  |
+----+-------------+----------+-------+---------------+---------+---------+------+------+-------+
1 row in set (0.00 sec)