-- source include/no_valgrind_without_big.inc # Bug#13654923 BOGUS DEBUG ASSERTION IN INDEX CREATION FOR ZERO-LENGTH RECORD create table t1(a varchar(2) primary key) ENGINE=XENGINE; insert into t1 values(''); --enable_info create index t1a1 on t1(a(1)); --disable_info drop table t1; create table t1(a int not null, b int, c char(10) not null, d varchar(20)) ENGINE=XENGINE; insert into t1 values (5,5,'oo','oo'),(4,4,'tr','tr'),(3,4,'ad','ad'),(2,3,'ak','ak'); commit; --error ER_DUP_KEYNAME alter table t1 add index b (b), add index b (b); --error ER_DUP_FIELDNAME alter table t1 add index (b,b); --enable_info alter table t1 add index d2 (d); --disable_info show create table t1; -- disable_result_log analyze table t1; -- enable_result_log --replace_column 10 # explain select * from t1 force index(d2) order by d; select * from t1 force index (d2) order by d; --error ER_DUP_ENTRY alter table t1 add unique index (b); show create table t1; --enable_info alter table t1 add index (b); --disable_info show create table t1; --enable_info alter table t1 add unique index (c), add index (d); --disable_info show create table t1; analyze table t1; --replace_column 10 # explain select * from t1 force index(c) order by c; --enable_info alter table t1 add primary key (a), drop index c; show create table t1; --error ER_MULTIPLE_PRI_KEY alter table t1 add primary key (c); --error ER_DUP_ENTRY alter table t1 drop primary key, add primary key (b); create unique index c on t1 (c); --disable_info show create table t1; analyze table t1; --replace_column 10 # explain select * from t1 force index(c) order by c; select * from t1 force index(c) order by c; --enable_info alter table t1 drop index b, add index (b); --disable_info show create table t1; insert into t1 values(6,1,'ggg','ggg'); select * from t1; select * from t1 force index(b) order by b; select * from t1 force index(c) order by c; select * from t1 force index(d) order by d; -- disable_result_log analyze table t1; -- enable_result_log --replace_column 10 # explain select * from t1 force index(b) order by b; --replace_column 10 # explain select * from t1 force index(c) order by c; --replace_column 10 # explain select * from t1 force index(d) 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=XENGINE; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ad','ad'),(4,4,'afe','afe'); commit; --enable_info alter table t1 add index (c(2)); show create table t1; alter table t1 add unique index (d(10)); show create table t1; --disable_info insert into t1 values(5,1,'ggg','ggg'); -- disable_result_log analyze table t1; -- enable_result_log select * from t1; select * from t1 force index(c) order by c; select * from t1 force index(d) order by d; --replace_column 10 # explain select * from t1 order by b; --replace_column 10 # explain select * from t1 force index(c) order by c; --replace_column 10 # explain select * from t1 force index(d) order by d; show create table t1; --enable_info alter table t1 drop index d; --disable_info insert into t1 values(8,9,'fff','fff'); select * from t1; select * from t1 force index(c) order by c; -- disable_result_log analyze table t1; -- enable_result_log --replace_column 10 # explain select * from t1 order by b; --replace_column 10 # explain select * from t1 force index(c) order by c; --replace_column 10 # 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=XENGINE; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe'); commit; --enable_info alter table t1 add unique index (b,c); --disable_info insert into t1 values(8,9,'fff','fff'); select * from t1; select * from t1 force index(b) order by b; -- disable_result_log analyze table t1; -- enable_result_log --replace_column 10 # explain select * from t1 force index(b) order by b; show create table t1; --enable_info alter table t1 add index (b,c); --disable_info insert into t1 values(11,11,'kkk','kkk'); select * from t1; select * from t1 force index(b) order by b; -- disable_result_log analyze table t1; -- enable_result_log --replace_column 10 # explain select * from t1 force index(b) order by b; show create table t1; --enable_info alter table t1 add unique index (c,d); --disable_info insert into t1 values(13,13,'yyy','aaa'); select * from t1; select * from t1 force index(b) order by b; select * from t1 force index(c) order by c; -- disable_result_log analyze table t1; -- enable_result_log --replace_column 10 # explain select * from t1 force index(b) order by b; --replace_column 10 # explain select * from t1 force index(c) order by c; 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=XENGINE default charset=utf8; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe'); commit; --error ER_DUP_ENTRY alter table t1 add unique index (b); insert into t1 values(8,9,'fff','fff'); select * from t1; show create table t1; alter table t1 add index (b); insert into t1 values(10,10,'kkk','iii'); -- disable_query_log -- disable_result_log analyze table t1; -- enable_result_log -- enable_query_log select * from t1; select * from t1 force index(b) order by b; --replace_column 10 # explain select * from t1 force index(b) order by b; show create table t1; alter table t1 add unique index (c), add index (d); insert into t1 values(11,11,'aaa','mmm'); -- disable_query_log -- disable_result_log analyze table t1; -- enable_result_log -- enable_query_log select * from t1; select * from t1 force index(b) order by b; select * from t1 force index(c) order by c; select * from t1 force index(d) order by d; --replace_column 10 # explain select * from t1 force index(b) order by b; --replace_column 10 # explain select * from t1 force index(c) order by c; --replace_column 10 # explain select * from t1 force index(d) order by d; show create table t1; check table t1; drop table t1; create table t1(a int not null, b int) ENGINE=XENGINE; insert into t1 values (1,1),(1,1),(1,1),(1,1); --error ER_DUP_ENTRY alter table t1 add unique index (a); --error ER_DUP_ENTRY alter table t1 add unique index (b); --error ER_DUP_ENTRY 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=XENGINE; 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=XENGINE; 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=XENGINE; insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ac','ac'),(4,4,'afe','afe'),(5,4,'affe','affe'); --error ER_DUP_ENTRY alter table t1 add unique index (b), add unique index (c), add unique index (d); --error ER_DUP_ENTRY alter table t1 add unique index (c), add unique index (b), add index (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(c)) ENGINE=XENGINE; insert into t1 values (5,1,5),(4,2,4),(3,3,3),(2,4,2),(1,5,1); --enable_info alter table t1 add unique index (b); --disable_info insert into t1 values (10,20,20),(11,19,19),(12,18,18),(13,17,17); show create table t1; check table t1; -- disable_result_log analyze table t1; -- enable_result_log --replace_column 10 # explain select * from t1 force index(c) order by c; --replace_column 10 # explain select * from t1 order by a; --replace_column 10 # explain select * from t1 force index(b) order by b; select * from t1 order by a; select * from t1 force index(b) order by b; select * from t1 force index(c) order by c; drop table t1; create table t1(a int not null, b int not null) ENGINE=XENGINE; insert into t1 values (1,1); --enable_info alter table t1 add primary key(b); --disable_info insert into t1 values (2,2); show create table t1; check table t1; select * from t1; analyze table t1; --replace_column 10 # explain select * from t1; --replace_column 10 # explain select * from t1 order by a; --replace_column 10 # explain select * from t1 order by b; checksum table t1; drop table t1; create table t1(a int not null) ENGINE=XENGINE; insert into t1 values (1); --enable_info alter table t1 add primary key(a); --disable_info insert into t1 values (2); show create table t1; check table t1; commit; select * from t1; analyze table t1; --replace_column 10 # explain select * from t1; --replace_column 10 # explain select * from t1 order by a; drop table t1; create table t480(a serial)engine=xengine; insert into t480 values(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(), (),(),(),(),(),(),(),(); insert into t480 select 0 from t480; insert into t480 select 0 from t480; insert into t480 select 0 from t480; insert into t480 select 0 from t480; --echo # Bug#19163915 INNODB: DUPLICATE RECORDS COULD EXIST --echo # WHEN SKIPPING SORT FOR CLUSTER INDEX # last mtuple in previous buffer and first mtuple in next buffer # are equal. SELECT @@innodb_sort_buffer_size; create table t1(f1 int auto_increment not null, f2 char(200) not null, f3 char(200) not null, f4 char(200) not null,primary key(f1,f2,f3,f4)) charset latin1; insert into t1 select NULL,'aaa','bbb','ccc' from t480; insert into t1 values(106, 'aaa','bbb','cccc'); select count(*) from t1; --echo # Skip sort --echo # Change PK from (f1,f2,f3,f4) to (f1,f2,f3) --error ER_DUP_ENTRY alter table t1 drop primary key, add primary key(f1,f2,f3); select count(*) from t1; drop table t1; # Duplicates exist with in the buffer create table t1(f1 int auto_increment not null, f2 char(200) not null, f3 char(200) not null, f4 char(200) not null,primary key(f1,f2,f3,f4)) charset latin1; insert into t1 select NULL,'aaa','bbb','ccc' from t480; insert into t1 values(108,'aaa','bbb','cccc'); select count(*) from t1; --error ER_DUP_ENTRY alter table t1 drop primary key, add primary key(f1,f2,f3); select count(*) from t1; drop table t1, t480; --echo # --echo # Bug #19896922 SORTING SKIPPED WHEN PREFIX LENGTH OF THE PK --echo # FIELD IS CHANGED --echo # # Prefix length changes for the varchar column. create table t1(a int not null, b varchar(30) not null, primary key (b(10), a)) ENGINE=XENGINE; insert into t1 values(0,'khdHps6UxW8Lwaoxa604oK6zkb'),(1,'khdHps6UxW8L'); select * from t1; alter table t1 drop primary key, add primary key (b(18),a); select * from t1; drop table t1; create table t1(a int not null, b varchar(30) not null, primary key (b(10), a)) ENGINE=XENGINE; insert into t1 values(0,'khdHps6UxW8Lwaoxa604oK6zkb'),(1,'khdHps6UtW8L'); select * from t1; alter table t1 drop primary key, add primary key (b(8),a); select * from t1; drop table t1; --echo # --echo # Bug #21103101 SORTING SKIPPED WHEN DROPPING THE SINGLE --echo # COLUMN PRIMARY KEY --echo # # Drop primary key column. create table t1(f1 int not null, f2 int not null, primary key (f1), unique key(f1, f2))ENGINE=XENGINE; insert into t1 values(1,3), (2,2); alter table t1 drop column f1; drop table t1; # Drop Primary key when lock is none. create table t1(f1 int not null, f2 int not null, primary key (f1), unique key(f1, f2))ENGINE=XENGINE; insert into t1 values(1,3), (2,2); --error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON alter table t1 drop primary key, lock=none; drop table t1; --echo # --echo # BUG#21612714 ALTER TABLE SORTING SKIPPED WHEN CHANGE PK AND DROP --echo # LAST COLUMN OF OLD PK --echo # # no skip sort cases # pk(o1,o2) to pk(o1,o3), drop o2 create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,1,2),(1,2,1); alter table t1 drop primary key, add primary key(o1,o3), drop o2, lock=none; drop table t1; # pk(o1,o2) to pk(o3), drop o1, o2 create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,1,2),(1,2,1); alter table t1 drop o1, drop o2, add primary key(o3), lock=none; drop table t1; # pk(o1,o2) to pk(o1,o3) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,1,2),(1,2,1); alter table t1 drop primary key, add primary key(o1,o3), lock=none; drop table t1; # pk(o1,o2) to pk(o3) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,1,2),(1,2,1); alter table t1 drop primary key, add primary key(o3), lock=none; drop table t1; # pk(o1,o2) to pk(n1,o3) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,1,2),(1,2,1); alter table t1 add column n1 int not null, drop primary key, add primary key(n1,o3), lock=none; drop table t1; # pk(o1,o2) to pk(o3,n1) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,1,2),(2,2,1); alter table t1 add column n1 int not null, drop primary key, add primary key(o3,n1), lock=none; drop table t1; # pk(o1,o2) to pk(o2,o1) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,2,2),(2,1,1); alter table t1 drop primary key, add primary key(o2, o1), lock=none; drop table t1; # pk(o1,o2) to pk(o2) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,2,2),(2,1,1); alter table t1 drop primary key, add primary key(o2), lock=none; drop table t1; # pk(o1,o2) to pk(o2,o3) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,2,2),(2,1,1); alter table t1 drop primary key, add primary key(o2,o3), lock=none; drop table t1; # pk(o2,o1) to pk(o2,o3) create table t1(o1 int, o2 int, o3 int not null, primary key(o2,o1)) ENGINE=XENGINE; insert into t1 values(1,1,2),(2,1,1); alter table t1 drop primary key, add primary key(o2,o3), lock=none; drop table t1; # pk(o1,o2) to pk(o1,o3,o2) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,1,2),(1,2,1); alter table t1 drop primary key, add primary key(o1,o3,o2), lock=none; drop table t1; # pk(o1,o2) to pk(o3,o1,o2) create table t1(o1 int, o2 int, o3 int not null, primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values(1,2,2),(2,1,1); alter table t1 drop primary key, add primary key(o3,o1,o2), lock=none; drop table t1; # pk(o1,o2,o3) to pk(o1,o3) create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) ENGINE=XENGINE; insert into t1 values(1,1,2),(1,2,1); alter table t1 drop primary key, add primary key(o1,o3), lock=none; drop table t1; # pk(o1,o2,o3) to pk(o2,o3) by drop o1 create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) ENGINE=XENGINE; insert into t1 values(1,2,2),(2,1,1); alter table t1 drop o1, lock=none; drop table t1; # pk(o1,o2,o3) to pk(o1,o3) by drop o2 create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) ENGINE=XENGINE; insert into t1 values(1,1,2),(1,2,1); alter table t1 drop o2, lock=none; drop table t1; # pk(o1,o2,o3) to pk(o3) by drop o1,o2 create table t1(o1 int, o2 int, o3 int, primary key(o1,o2,o3)) ENGINE=XENGINE; insert into t1 values(1,2,2),(2,1,1); alter table t1 drop o1, drop o2, lock=none; drop table t1; # no skip sort for prefix change # pk(o1(2),o2) to pk(o1(3),o2) create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) ENGINE=XENGINE; insert into t1 values('abd', 1, 1), ('abc', 2, 2); alter table t1 drop primary key, add primary key(o1(3), o2), lock=none; drop table t1; # pk(o1(2),o2) to pk(o1,o2) create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) ENGINE=XENGINE; insert into t1 values('abd', 1, 1), ('abc', 2, 2); alter table t1 drop primary key, add primary key(o1, o2), lock=none; drop table t1; # pk(o1(2),o2) to pk(o1(3),o3) create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) ENGINE=XENGINE; insert into t1 values('abd', 1, 1), ('abc', 2, 2); alter table t1 drop primary key, add primary key(o1(3), o3), lock=none; drop table t1; # pk(o1(2),o2) to pk(o1,o3) create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(2), o2)) ENGINE=XENGINE; insert into t1 values('abd', 1, 1), ('abc', 2, 2); alter table t1 drop primary key, add primary key(o1, o3), lock=none; drop table t1; # pk(o1(3),o2) to pk(o1(2),o2) create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(3), o2)) ENGINE=XENGINE; insert into t1 values('abc', 2, 1), ('abd', 1, 2); alter table t1 drop primary key, add primary key(o1(2), o2), lock=none; drop table t1; # pk(o1,o2) to pk(o1(2),o2) create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1, o2)) ENGINE=XENGINE; insert into t1 values('abc', 2, 1), ('abd', 1, 2); alter table t1 drop primary key, add primary key(o1(2), o2), lock=none; drop table t1; # pk(o1(3),o2) to pk(o1(2),o3) create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1(3), o2)) ENGINE=XENGINE; insert into t1 values('abc', 2, 2), ('abd', 1, 1); alter table t1 drop primary key, add primary key(o1(2), o3), lock=none; drop table t1; # pk(o1,o2) to pk(o1(2),o3) create table t1(o1 varchar(10), o2 int, o3 int not null, primary key(o1, o2)) ENGINE=XENGINE; insert into t1 values('abc', 2, 2), ('abd', 1, 1); alter table t1 drop primary key, add primary key(o1(2), o3), lock=none; drop table t1; # pk(o1,o2(2),o3) to pk(o1,o2(3)) create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(2),o3)) ENGINE=XENGINE; insert into t1 values(1, 'abd', 1), (1, 'abc', 2); alter table t1 drop primary key, add primary key(o1,o2(3)), lock=none; drop table t1; # pk(o1,o2(2),o3) to pk(o1,o2) create table t1(o1 int, o2 varchar(10), o3 int, primary key(o1,o2(2),o3)) ENGINE=XENGINE; insert into t1 values(1, 'abd', 1), (1, 'abc', 2); alter table t1 drop primary key, add primary key(o1,o2), lock=none; drop table t1; # pk(o1(3),o2(3)) to pk(o1(2),o2(3)) create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) ENGINE=XENGINE; insert into t1 values('abc', 'acd'), ('abd', 'abd'); alter table t1 drop primary key, add primary key(o1(2),o2(3)), lock=none; drop table t1; # pk(o1,o2) to pk(o1(2),o2) create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values('abc', 'acd'), ('abd', 'abd'); alter table t1 drop primary key, add primary key(o1(2),o2), lock=none; drop table t1; # pk(o1(3),o2(3)) to pk(o2(3),o1(3)) create table t1(o1 varchar(10), o2 varchar(10), primary key(o1(3),o2(3))) ENGINE=XENGINE; insert into t1 values('abd', 'acd'), ('acd', 'abd'); alter table t1 drop primary key, add primary key(o2(3),o1(3)), lock=none; drop table t1; # pk(o1,o2) to pk(o2,o1) create table t1(o1 varchar(10), o2 varchar(10), primary key(o1,o2)) ENGINE=XENGINE; insert into t1 values('abd', 'acd'), ('acd', 'abd'); alter table t1 drop primary key, add primary key(o2,o1), lock=none; drop table t1; CREATE TABLE t1(a INT NOT NULL, b INT, PRIMARY KEY (a ASC)) ENGINE=XENGINE; SHOW CREATE TABLE t1; INSERT INTO t1 VALUES(5,5), (4,4), (3,4), (2,3); --error 1178 ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY (a DESC); ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY (a ASC); CHECK TABLE t1; SELECT * FROM t1; DROP TABLE t1; # no skip sort cases --source ../include/alter_table_pk_no_sort.inc --source suite/xengine/include/check_xengine_log_error.inc