您当前的位置: 首页 > 数据库教程 > MySQL教程 > InnoDB和MyISAM都是密集索引

InnoDB和MyISAM都是密集索引

作者:不详 来源:网络 发布时间: 2011-06-21 13:36 点击:
1 以前从一些资料上看到InnoDB的索引是稀疏索引,而MyISAM的索引是密集索引,今天刻意测试了一下,发现竟然不是这样。 2 找时间研究下,mark一下先。 3 mysql show create table uniq_id\G 4 *************************** 1. row *************************** 5 Table:

InnoDB和MyISAM都是密集索引

1 以前从一些资料上看到InnoDB的索引是稀疏索引,而MyISAM的索引是密集索引,今天刻意测试了一下,发现竟然不是这样。
2 找时间研究下,mark一下先。
3 mysql> show create table uniq_id\G
4 *************************** 1. row ***************************
5 Table: uniq_id
6 Create Table: CREATE TABLE `uniq_id` (
7 `id` int(11) DEFAULT NULL,
8 KEY `id` (`id`)
9 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
10 1 row in set (0.00 sec)
11
12 mysql> show create table same_id\G
13 *************************** 1. row ***************************
14 Table: same_id
15 Create Table: CREATE TABLE `same_id` (
16 `id` int(11) DEFAULT NULL,
17 KEY `id` (`id`)
18 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
19 1 row in set (0.00 sec)
20
21 mysql> select count(*),count(distinct id) from same_id;
22 +----------+--------------------+
23 | count(*) | count(distinct id) |
24 +----------+--------------------+
25 | 1000000 | 1 |
26 +----------+--------------------+
27 1 row in set (0.21 sec)
28
29 mysql> alter table uniq_id add index(id);
30 Query OK, 1000000 rows affected (1.27 sec)
31 Records: 1000000 Duplicates: 0 Warnings: 0
32
33 mysql> alter table same_id add index(id);
34 Query OK, 1000000 rows affected (1.59 sec)
35 Records: 1000000 Duplicates: 0 Warnings: 0
36
37 -rw-rw---- 1 mysql mysql 11326464 May 26 10:54 same_id.MYI
38 -rw-rw---- 1 mysql mysql 11326464 May 26 10:54 uniq_id.MYI
39
40 mysql> alter table uniq_id engine=innodb;
41 Query OK, 1000000 rows affected (8.89 sec)
42 Records: 1000000 Duplicates: 0 Warnings: 0
43
44 mysql> alter table same_id engine=innodb;
45 Query OK, 1000000 rows affected (8.48 sec)
46 Records: 1000000 Duplicates: 0 Warnings: 0
47
48 -rw-rw---- 1 mysql mysql 58720256 May 26 10:56 same_id.ibd
49 -rw-rw---- 1 mysql mysql 58720256 May 26 10:56 uniq_id.ibd
50
51 mysql> show create table uniq_id2\G
52 *************************** 1. row ***************************
53 Table: uniq_id2
54 Create Table: CREATE TABLE `uniq_id2` (
55 `id` int(11) NOT NULL,
56 `v` int(11) DEFAULT NULL,
57 PRIMARY KEY (`id`)
58 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
59 1 row in set (0.00 sec)
60
61 mysql> show create table same_id2\G
62 *************************** 1. row ***************************
63 Table: same_id2
64 Create Table: CREATE TABLE `same_id2` (
65 `id` int(11) NOT NULL,
66 `v` int(11) DEFAULT NULL,
67 PRIMARY KEY (`id`)
68 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
69 1 row in set (0.00 sec)
70
71
72 -rw-rw---- 1 mysql mysql 10263552 May 26 11:00 same_id2.MYI
73 -rw-rw---- 1 mysql mysql 10263552 May 26 11:01 uniq_id2.MYI
74
75 mysql> alter table same_id2 add index(v);
76 Query OK, 1000000 rows affected (9.06 sec)
77 Records: 1000000 Duplicates: 0 Warnings: 0
78
79 mysql> alter table uniq_id2 add index(v);
80 Query OK, 1000000 rows affected (8.60 sec)
81 Records: 1000000 Duplicates: 0 Warnings: 0
82
83 -rw-rw---- 1 mysql mysql 21605376 May 26 11:02 same_id2.MYI
84 -rw-rw---- 1 mysql mysql 21605376 May 26 11:02 uniq_id2.MYI
85
86 mysql> alter table uniq_id2 engine=innodb;
87 Query OK, 1000000 rows affected (7.66 sec)
88 Records: 1000000 Duplicates: 0 Warnings: 0
89
90 mysql> alter table same_id2 engine=innodb;
91 Query OK, 1000000 rows affected (8.19 sec)
92 Records: 1000000 Duplicates: 0 Warnings: 0
93
94 -rw-rw---- 1 mysql mysql 54525952 May 26 11:05 same_id2.ibd
95 -rw-rw---- 1 mysql mysql 54525952 May 26 11:05 uniq_id2.ibd

分享到:
本文"InnoDB和MyISAM都是密集索引"由远航站长收集整理而来,仅供大家学习与参考使用。更多网站制作教程尽在远航站长站。
顶一下
(0)
0%
踩一下
(0)
0%
[点击 次] [返回上一页] [打印]
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
关于本站 - 联系我们 - 网站声明 - 友情连接- 网站地图 - 站点地图 - 返回顶部
Copyright © 2007-2013 www.yhzhan.com(远航站长). All Rights Reserved .
远航站长:为中小站长提供最佳的学习与交流平台,提供网页制作与网站编程等各类网站制作教程.
官方QQ:445490277 网站群:26680406 网站备案号:豫ICP备07500620号-4