1
create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb default charset=ucs2;
2
insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe');
4
alter table t1 add unique index (b);
5
ERROR 23000: Duplicate entry '2' for key 'b'
6
insert into t1 values(8,9,'fff','fff');
16
t1 CREATE TABLE `t1` (
18
`b` int(11) DEFAULT NULL,
19
`c` char(10) DEFAULT NULL,
20
`d` varchar(20) DEFAULT NULL,
22
) ENGINE=InnoDB DEFAULT CHARSET=ucs2
23
alter table t1 add index (b);
24
insert into t1 values(10,10,'kkk','iii');
33
select * from t1 force index(b) order by b;
41
explain select * from t1 force index(b) order by b;
42
id select_type table type possible_keys key key_len ref rows Extra
43
1 SIMPLE t1 index NULL b 5 NULL 6
46
t1 CREATE TABLE `t1` (
48
`b` int(11) DEFAULT NULL,
49
`c` char(10) DEFAULT NULL,
50
`d` varchar(20) DEFAULT NULL,
53
) ENGINE=InnoDB DEFAULT CHARSET=ucs2
54
alter table t1 add unique index (c), add index (d);
55
insert into t1 values(11,11,'aaa','mmm');
65
select * from t1 force index(b) order by b;
74
select * from t1 force index(c) order by c;
83
select * from t1 force index(d) order by d;
92
explain select * from t1 force index(b) order by b;
93
id select_type table type possible_keys key key_len ref rows Extra
94
1 SIMPLE t1 index NULL b 5 NULL 7
95
explain select * from t1 force index(c) order by c;
96
id select_type table type possible_keys key key_len ref rows Extra
97
1 SIMPLE t1 index NULL c 21 NULL 7
98
explain select * from t1 force index(d) order by d;
99
id select_type table type possible_keys key key_len ref rows Extra
100
1 SIMPLE t1 index NULL d 43 NULL 7
101
show create table t1;
103
t1 CREATE TABLE `t1` (
104
`a` int(11) NOT NULL,
105
`b` int(11) DEFAULT NULL,
106
`c` char(10) DEFAULT NULL,
107
`d` varchar(20) DEFAULT NULL,
109
UNIQUE KEY `c` (`c`),
112
) ENGINE=InnoDB DEFAULT CHARSET=ucs2
114
Table Op Msg_type Msg_text
115
test.t1 check status OK