MySQL复合唯一索引分析
关于复合唯一索引(unique key 或 unique index),网上搜索不少人说:”这种索引起到的关键作用是约束,查询时性能上没有得到提高或者查询时根本没有走索引列“。也有人说:“查询时使用到了索引和普通索引一样“。那么问题到底是怎样的呢?
测试准备工作
准备建表语句,插入数据等工作:
-- 建表(注:a,b是复合唯一索引)
create table test0(id bigint not null primary key auto_increment, a varchar(10) not null, b varchar(10) not null, unique index(a, b))engine=innodb charset=utf8 auto_increment=1;
-- 插入数据
insert into test0(a, b)values('china', 'chinese');
insert into test0(a, b)values('japan', 'japanese');
insert into test0(a, b)values('germany', 'german');
insert into test0(a, b)values('korea', 'korea');
insert into test0(a, b)values('france', 'frence');
insert into test0(a, b)values('australia', 'australia');
inse