- 积分
- 51
- UID
- 14501
- 阅读权限
- 20
- 注册时间
- 2013-9-17
- 精华
- 在线时间
- 小时
- 最后登录
- 1970-1-1
- 职业
- 4
|
4#
楼主 |
发表于 2013-9-18 07:50:13
|
只看该作者
唯一索引表占空间比普通索引要大50%,比不带索引表要大73%,4G的基础表建了唯一索引后有7G左右
创建唯一索引时,表要重建,占的内存空间比较大(个人理解),导致失败了
测试数据如下:
-- 1、唯一索引 Query OK, 100000 rows affected (29.72 sec)
drop table if exists prod_inst_000;
create table prod_inst_000 ENGINE=InnoDB DEFAULT CHARSET=utf8 as select * from prod_inst_551 limit 0,0;
create unique index uidx_prod_inst_000 on prod_inst_000 (prod_inst_id);
insert into prod_inst_000 select * from prod_inst_551 limit 0,100000;
commit;
-rw-rw---- 1 mysql mysql 16104 Sep 18 07:25 prod_inst_000.frm
-rw-rw---- 1 mysql mysql 88080384 Sep 18 07:25 prod_inst_000.ibd
-- 2、普通索引 Query OK, 100000 rows affected (18.18 sec)
drop table if exists prod_inst_000;
create table prod_inst_000 ENGINE=InnoDB DEFAULT CHARSET=utf8 as select * from prod_inst_551 limit 0,0;
create index idx_prod_inst_000 on prod_inst_000 (prod_inst_id);
insert into prod_inst_000 select * from prod_inst_551 limit 0,100000;
commit;
-rw-rw---- 1 mysql mysql 16104 Sep 18 07:28 prod_inst_000.frm
-rw-rw---- 1 mysql mysql 58720256 Sep 18 07:28 prod_inst_000.ibd
-- 3、唯一索引占空间比普通索引要增长50%
(88080384-58720256)/58720256=0.5
|
|