InnoDB和MyISAM都是密集索引?

 1  以前从一些资料上看到InnoDB的索引是稀疏索引,而MyISAM的索引是密集索引,今天刻意测试了一下,发现竟然不是这样。
 2  找时间研究下,mark一下先。
 3  mysql> show  create  table uniq_id\G
 4  ***************************  1row ***************************
 5           Table: uniq_id
 6   Create  TableCREATE  TABLE `uniq_id` (
 7     `id` int( 11DEFAULT  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  ***************************  1row ***************************
14          Table: same_id
15   Create  TableCREATE  TABLE `same_id` (
16    `id` int( 11DEFAULT  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  ***************************  1row ***************************
53          Table: uniq_id2
54   Create  TableCREATE  TABLE `uniq_id2` (
55    `id` int( 11NOT  NULL,
56    `v` int( 11DEFAULT  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  ***************************  1row ***************************
63          Table: same_id2
64   Create  TableCREATE  TABLE `same_id2` (
65    `id` int( 11NOT  NULL,
66    `v` int( 11DEFAULT  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

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

转载于:http://blog.itpub.net/10478177/viewspace-696404/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值