-- source include/have_innodb.inc create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb; insert into t1 values (5,5,'oo','oo'),(4,4,'tr','tr'),(3,4,'ad','ad'),(2,3,'ak','ak'); commit; --error 1061 alter table t1 add index b (b), add index b (b); --error 1060 alter table t1 add index (b,b); alter table t1 add index d2 (d); show create table t1; explain select * from t1 order by d; select * from t1 order by d; --error 1582 alter table t1 add unique index (b); show create table t1; alter table t1 add index (b); show create table t1; alter table t1 add unique index (c), add index (d); show create table t1; explain select * from t1 order by c; select * from t1 order by c; alter table t1 drop index b, add index (b); show create table t1; insert into t1 values(6,1,'ggg','ggg'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; drop table t1; create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ad','ad'),(4,4,'afe','afe'); commit; alter table t1 add index (c(2)); show create table t1; alter table t1 add unique index (d(10)); show create table t1; insert into t1 values(5,1,'ggg','ggg'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; alter table t1 drop index d; insert into t1 values(8,9,'fff','fff'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; drop table t1; create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe'); commit; alter table t1 add unique index (b,c); insert into t1 values(8,9,'fff','fff'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; alter table t1 add index (b,c); insert into t1 values(11,11,'kkk','kkk'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; alter table t1 add unique index (c,d); insert into t1 values(13,13,'yyy','aaa'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; drop table t1; create table t1(a int not null, b int not null, c int, primary key (a), key (b)) engine = innodb; create table t3(a int not null, c int not null, d int, primary key (a), key (c)) engine = innodb; create table t4(a int not null, d int not null, e int, primary key (a), key (d)) engine = innodb; create table t2(a int not null, b int not null, c int not null, d int not null, e int, primary key (a), foreign key (b) references t1(b), foreign key (c) references t3(c), foreign key (d) references t4(d)) engine = innodb; --error 1542 alter table t1 drop index b; --error 1542 alter table t3 drop index c; --error 1542 alter table t4 drop index d; --error 1542 alter table t2 drop index b; --error 1542 alter table t2 drop index b, drop index c, drop index d; set foreign_key_checks=0; insert into t1 values (1,1,1); insert into t3 values (1,1,1); insert into t4 values (1,1,1); insert into t2 values (1,1,1,1,1); commit; alter table t2 drop index b, add index (b); show create table t2; set foreign_key_checks=1; set foreign_key_checks=0; --disable_warnings drop table if exists t1,t2,t3,t4; --enable_warnings set foreign_key_checks=1; create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb default charset=utf8; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe'); commit; --replace_regex /Duplicate entry '[0-9]*'/Duplicate entry ''/ --error 1582 alter table t1 add unique index (b); insert into t1 values(8,9,'fff','fff'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; alter table t1 add index (b); insert into t1 values(10,10,'kkk','iii'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; alter table t1 add unique index (c), add index (d); insert into t1 values(11,11,'aaa','mmm'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; check table t1; drop table t1; create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb default charset=ucs2; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe'); commit; --replace_regex /Duplicate entry '[0-9]*'/Duplicate entry ''/ --error 1582 alter table t1 add unique index (b); show create table t1; alter table t1 add index (b); insert into t1 values(8,9,'fff','fff'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; alter table t1 add unique index (c), add index (d); insert into t1 values(10,10,'aaa','kkk'); select * from t1; select * from t1 order by b; select * from t1 order by c; select * from t1 order by d; explain select * from t1 order by b; explain select * from t1 order by c; explain select * from t1 order by d; show create table t1; check table t1; drop table t1; create table t1(a int not null, b int) engine = innodb; insert into t1 values (1,1),(1,1),(1,1),(1,1); --error 1582 alter table t1 add unique index (a); --error 1582 alter table t1 add unique index (b); --error 1582 alter table t1 add unique index (a), add unique index(b); show create table t1; drop table t1; create table t1(a int not null, c int not null,b int, primary key(a), unique key(c), key(b)) engine = innodb; alter table t1 drop index c, drop index b; show create table t1; drop table t1; create table t1(a int not null, b int, primary key(a)) engine = innodb; alter table t1 add index (b); show create table t1; drop table t1; create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ac','ac'),(4,4,'afe','afe'); --error 1582 alter table t1 add unique index (b), add unique index (c), add unique index (d); --error 1582 alter table t1 add unique index (b), add index (d), add unique index (c); show create table t1; drop table t1; create table t1(a int not null, b int not null, c int, primary key (a), key(c)) engine=innodb; insert into t1 values (5,1,5),(4,2,4),(3,3,3),(2,4,2),(1,5,1); alter table t1 add unique index (b); insert into t1 values (10,20,20),(11,19,19),(12,18,18),(13,17,17); show create table t1; check table t1; explain select * from t1 order by c; explain select * from t1 order by a; explain select * from t1 order by b; select * from t1 order by a; select * from t1 order by b; select * from t1 order by c; drop table t1; create table t1(a int not null, b int not null) engine=innodb; insert into t1 values (1,1); alter table t1 add primary key(b); insert into t1 values (2,2); show create table t1; check table t1; select * from t1; explain select * from t1; explain select * from t1 order by a; explain select * from t1 order by b; checksum table t1; drop table t1; create table t1(a int not null) engine=innodb; insert into t1 values (1); alter table t1 add primary key(a); insert into t1 values (2); show create table t1; check table t1; commit; select * from t1; explain select * from t1; explain select * from t1 order by a; drop table t1; create table t1(a int, b blob, c text, d text not null) engine=innodb default charset = utf8; insert into t1 values (22,repeat('jejdkrun87',220),repeat('jejdkrun87',440),'jejdkrun87'); insert into t1 values (44,repeat('adfd72nh9k',440),repeat('adfd72nh9k',880),'adfd72nh9k'); select count(*) from t1 where a=44; select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1; select a,length(b),length(c),d from t1; alter table t1 add primary key (a), add key (b(20)); select count(*) from t1 where a=44; select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1; select a,length(b),length(c),d from t1; insert into t1 values (33,repeat('adfdpplkeock',330),repeat('adfdpplkeock',660),'adfdpplkeock'); insert into t1 values (55,repeat('adfdijnmnb78k',550),repeat('adfdijnmnb78k',1100),'adfdijnmnb78k'); insert into t1 values (66,repeat('adfdijn0loKNHJik',660),repeat('adfdijn0loKNHJik',1320),'adfdijn0loKNHJik'); show create table t1; check table t1; explain select * from t1 where b like 'adfd%'; select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1; select a,length(b),length(c),d from t1; drop table t1;