mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
4cc4b2c775
Disable part of innodb-index test because MySQL changed its behavior and is not calling ::add_index() anymore in the following ALTER TABLE: CREATE TABLE t (a INT) ENGINE=INNODB; INSERT INTO t VALUES (NULL); ALTER TABLE t ADD PRIMARY KEY (a); -- adding primary index on non-NULL column Previously, in ALTER TABLE, MySQL would call ::add_index() which would fail with a "primary key cannot contain NULL" error. The change occured in: mysql-5.1$ bzr log -v -r2667 ------------------------------------------------------------ revno: 2667 committer: Davi Arnaut <davi@mysql.com> branch nick: 33873-5.1 timestamp: Tue 2008-06-17 11:12:21 -0300 message: Bug#33873: Fast ALTER TABLE doesn't work with multibyte character sets The problem was that when comparing tables for a possible fast alter table, the comparison was being performed using the parsed information and not the final definition. The solution is to use the possible final table layout to compare if a fast alter is possible or not. modified: mysql-test/include/mix1.inc mysql-test/r/alter_table.result mysql-test/r/innodb_mysql.result mysql-test/t/alter_table.test sql/sql_table.cc mysql-5.1$
389 lines
13 KiB
Text
389 lines
13 KiB
Text
-- source include/have_innodb.inc
|
|
|
|
create table t1(a int not null, b int, c char(10) not null, d varchar(20)) engine = innodb;
|
|
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);
|
|
alter table t1 add index d2 (d);
|
|
show create table t1;
|
|
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;
|
|
alter table t1 add index (b);
|
|
show create table t1;
|
|
|
|
# Check how existing tables interfere with temporary tables.
|
|
CREATE TABLE `t1#1`(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
|
|
--error 156
|
|
alter table t1 add unique index (c), add index (d);
|
|
rename table `t1#1` to `t1#2`;
|
|
--error 156
|
|
alter table t1 add unique index (c), add index (d);
|
|
drop table `t1#2`;
|
|
|
|
alter table t1 add unique index (c), add index (d);
|
|
show create table t1;
|
|
explain select * from t1 force index(c) order by c;
|
|
--error ER_REQUIRES_PRIMARY_KEY
|
|
drop index c on t1;
|
|
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);
|
|
show create table t1;
|
|
explain select * from t1 force index(c) order by c;
|
|
select * from t1 force index(c) 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 force index(b) order by b;
|
|
select * from t1 force index(c) order by c;
|
|
select * from t1 force index(d) order by d;
|
|
explain select * from t1 force index(b) order by b;
|
|
explain select * from t1 force index(c) order by c;
|
|
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 = 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 force index(c) order by c;
|
|
select * from t1 force index(d) order by d;
|
|
explain select * from t1 order by b;
|
|
explain select * from t1 force index(c) order by c;
|
|
explain select * from t1 force index(d) 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 force index(c) order by c;
|
|
explain select * from t1 order by b;
|
|
explain select * from t1 force index(c) 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 force index(b) order by b;
|
|
explain select * from t1 force index(b) order by b;
|
|
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 force index(b) order by b;
|
|
explain select * from t1 force index(b) order by b;
|
|
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 force index(b) order by b;
|
|
select * from t1 force index(c) order by c;
|
|
explain select * from t1 force index(b) order by b;
|
|
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 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,
|
|
foreign key (b) references t1(b) on delete cascade,
|
|
foreign key (c) references t3(c), foreign key (d) references t4(d))
|
|
engine = innodb;
|
|
--error ER_DROP_INDEX_FK
|
|
alter table t1 drop index b;
|
|
--error ER_DROP_INDEX_FK
|
|
alter table t3 drop index c;
|
|
--error ER_DROP_INDEX_FK
|
|
alter table t4 drop index d;
|
|
--error ER_DROP_INDEX_FK
|
|
alter table t2 drop index b;
|
|
--error ER_DROP_INDEX_FK
|
|
alter table t2 drop index b, drop index c, drop index d;
|
|
# Apparently, the following makes mysql_alter_table() drop index d.
|
|
create unique index dc on t2 (d,c);
|
|
create index dc on t1 (b,c);
|
|
# This should preserve the foreign key constraints.
|
|
alter table t2 add primary key (a);
|
|
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 t4 add constraint dc foreign key (a) references t1(a);
|
|
show create table t4;
|
|
--replace_regex /'test\.#sql-[0-9a-f_]*'/'#sql-temporary'/
|
|
# a foreign key 'test/dc' already exists
|
|
--error ER_CANT_CREATE_TABLE
|
|
alter table t3 add constraint dc foreign key (a) references t1(a);
|
|
show create table t3;
|
|
alter table t2 drop index b, add index (b);
|
|
show create table t2;
|
|
--error ER_ROW_IS_REFERENCED_2
|
|
delete from t1;
|
|
--error ER_CANT_DROP_FIELD_OR_KEY
|
|
drop index dc on t4;
|
|
# there is no foreign key dc on t3
|
|
--replace_regex /'\.\/test\/#sql2-[0-9a-f-]*'/'#sql2-temporary'/
|
|
--error ER_ERROR_ON_RENAME
|
|
alter table t3 drop foreign key dc;
|
|
alter table t4 drop foreign key dc;
|
|
select * from t2;
|
|
delete from t1;
|
|
select * from t2;
|
|
|
|
drop table t2,t4,t3,t1;
|
|
|
|
-- let charset = utf8
|
|
-- source include/innodb-index.inc
|
|
|
|
create table t1(a int not null, b int) engine = innodb;
|
|
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 = 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'),(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=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 force index(c) order by c;
|
|
explain select * from t1 order by a;
|
|
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=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 t2(d varchar(17) primary key) engine=innodb default charset=utf8;
|
|
create table t3(a int primary key) engine=innodb;
|
|
|
|
insert into t3 values(22),(44),(33),(55),(66);
|
|
|
|
insert into t2 values ('jejdkrun87'),('adfd72nh9k'),
|
|
('adfdpplkeock'),('adfdijnmnb78k'),('adfdijn0loKNHJik');
|
|
|
|
create table t1(a int, b blob, c text, d text not null)
|
|
engine=innodb default charset = utf8;
|
|
|
|
# r2667 The following test is disabled because MySQL behavior changed.
|
|
# r2667 The test was added with this comment:
|
|
# r2667
|
|
# r2667 ------------------------------------------------------------------------
|
|
# r2667 r1699 | marko | 2007-08-10 19:53:19 +0300 (Fri, 10 Aug 2007) | 5 lines
|
|
# r2667
|
|
# r2667 branches/zip: Add changes that accidentally omitted from r1698:
|
|
# r2667
|
|
# r2667 innodb-index.test, innodb-index.result: Add a test for creating
|
|
# r2667 a PRIMARY KEY on a column that contains a NULL value.
|
|
# r2667 ------------------------------------------------------------------------
|
|
# r2667
|
|
# r2667 but in BZR-r2667:
|
|
# r2667 http://bazaar.launchpad.net/~mysql/mysql-server/mysql-5.1/revision/davi%40mysql.com-20080617141221-8yre8ys9j4uw3xx5?start_revid=joerg%40mysql.com-20080630105418-7qoe5ehomgrcdb89
|
|
# r2667 MySQL changed the behavior to do full table copy when creating PRIMARY INDEX
|
|
# r2667 on a non-NULL column instead of calling ::add_index() which would fail (and
|
|
# r2667 this is what we were testing here). Before r2667 the code execution path was
|
|
# r2667 like this (when adding PRIMARY INDEX on a non-NULL column with ALTER TABLE):
|
|
# r2667
|
|
# r2667 mysql_alter_table()
|
|
# r2667 compare_tables() // would return ALTER_TABLE_INDEX_CHANGED
|
|
# r2667 ::add_index() // would fail with "primary index cannot contain NULL"
|
|
# r2667
|
|
# r2667 after r2667 the code execution path is the following:
|
|
# r2667
|
|
# r2667 mysql_alter_table()
|
|
# r2667 compare_tables() // returns ALTER_TABLE_DATA_CHANGED
|
|
# r2667 full copy is done, without calling ::add_index()
|
|
# r2667
|
|
# r2667 To enable, remove "# r2667: " below.
|
|
# r2667
|
|
# r2667: insert into t1 values (null,null,null,'null');
|
|
insert into t1
|
|
select a,left(repeat(d,100*a),65535),repeat(d,20*a),d from t2,t3;
|
|
drop table t2, t3;
|
|
select count(*) from t1 where a=44;
|
|
select a,
|
|
length(b),b=left(repeat(d,100*a),65535),length(c),c=repeat(d,20*a),d from t1;
|
|
# r2667: --error ER_PRIMARY_CANT_HAVE_NULL
|
|
# r2667: alter table t1 add primary key (a), add key (b(20));
|
|
# r2667: delete from t1 where d='null';
|
|
--error ER_DUP_ENTRY
|
|
alter table t1 add primary key (a), add key (b(20));
|
|
delete from t1 where a%2;
|
|
check table t1;
|
|
alter table t1 add primary key (a,b(255),c(255)), add key (b(767));
|
|
select count(*) from t1 where a=44;
|
|
select a,
|
|
length(b),b=left(repeat(d,100*a),65535),length(c),c=repeat(d,20*a),d from t1;
|
|
show create table t1;
|
|
check table t1;
|
|
explain select * from t1 where b like 'adfd%';
|
|
|
|
#
|
|
# Test locking
|
|
#
|
|
|
|
create table t2(a int, b varchar(255), primary key(a,b)) engine=innodb;
|
|
insert into t2 select a,left(b,255) from t1;
|
|
drop table t1;
|
|
rename table t2 to t1;
|
|
|
|
connect (a,localhost,root,,);
|
|
connect (b,localhost,root,,);
|
|
connection a;
|
|
begin;
|
|
# Obtain an IX lock on the table
|
|
select a from t1 limit 1 for update;
|
|
connection b;
|
|
# This would require an S lock on the table, conflicting with the IX lock.
|
|
--error ER_LOCK_WAIT_TIMEOUT
|
|
create index t1ba on t1 (b,a);
|
|
connection a;
|
|
commit;
|
|
begin;
|
|
# Obtain an IS lock on the table
|
|
select a from t1 limit 1 lock in share mode;
|
|
connection b;
|
|
# This will require an S lock on the table. No conflict with the IS lock.
|
|
create index t1ba on t1 (b,a);
|
|
# This would require an X lock on the table, conflicting with the IS lock.
|
|
--error ER_LOCK_WAIT_TIMEOUT
|
|
drop index t1ba on t1;
|
|
connection a;
|
|
commit;
|
|
explain select a from t1 order by b;
|
|
--send
|
|
select a,sleep(2+a/100) from t1 order by b limit 3;
|
|
|
|
# The following DROP INDEX will succeed, altough the SELECT above has
|
|
# opened a read view. However, during the execution of the SELECT,
|
|
# MySQL should hold a table lock that should block the execution
|
|
# of the DROP INDEX below.
|
|
|
|
connection b;
|
|
select sleep(1);
|
|
drop index t1ba on t1;
|
|
|
|
# After the index was dropped, subsequent SELECTs will use the same
|
|
# read view, but they should not be accessing the dropped index any more.
|
|
|
|
connection a;
|
|
reap;
|
|
explain select a from t1 order by b;
|
|
select a from t1 order by b limit 3;
|
|
commit;
|
|
|
|
connection default;
|
|
disconnect a;
|
|
disconnect b;
|
|
|
|
drop table t1;
|
|
|
|
# Test creating a table that could lead to undo log overflow.
|
|
# In the undo log, we write a 768-byte prefix (REC_MAX_INDEX_COL_LEN)
|
|
# of each externally stored column that appears as a column prefix in an index.
|
|
# For this test case, it would suffice to write 1 byte, though.
|
|
create table t1(a blob,b blob,c blob,d blob,e blob,f blob,g blob,h blob,
|
|
i blob,j blob,k blob,l blob,m blob,n blob,o blob,p blob,
|
|
q blob,r blob,s blob,t blob,u blob)
|
|
engine=innodb;
|
|
create index t1a on t1 (a(1));
|
|
create index t1b on t1 (b(1));
|
|
create index t1c on t1 (c(1));
|
|
create index t1d on t1 (d(1));
|
|
create index t1e on t1 (e(1));
|
|
create index t1f on t1 (f(1));
|
|
create index t1g on t1 (g(1));
|
|
create index t1h on t1 (h(1));
|
|
create index t1i on t1 (i(1));
|
|
create index t1j on t1 (j(1));
|
|
create index t1k on t1 (k(1));
|
|
create index t1l on t1 (l(1));
|
|
create index t1m on t1 (m(1));
|
|
create index t1n on t1 (n(1));
|
|
create index t1o on t1 (o(1));
|
|
create index t1p on t1 (p(1));
|
|
create index t1q on t1 (q(1));
|
|
create index t1r on t1 (r(1));
|
|
create index t1s on t1 (s(1));
|
|
create index t1t on t1 (t(1));
|
|
--error 139
|
|
create index t1u on t1 (u(1));
|
|
--error 139
|
|
create index t1ut on t1 (u(1), t(1));
|
|
create index t1st on t1 (s(1), t(1));
|
|
show create table t1;
|
|
drop table t1;
|