📄 innodb.test
字号:
insert into t1 values (10, 20);insert into t2 values (10, 20);update t1, t2 set t1.b = 150, t2.b = t1.b where t2.a = t1.a and t1.a = 10;drop table t1,t2;## Test of multi-table-delete with foreign key constraints#CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE ) ENGINE=INNODB;insert into t1 set id=1;insert into t2 set id=1, t1_id=1;delete t1,t2 from t1,t2 where t1.id=t2.t1_id;select * from t1;select * from t2;drop table t2,t1;CREATE TABLE t1(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;CREATE TABLE t2(id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id) ) ENGINE=INNODB;INSERT INTO t1 VALUES(1);INSERT INTO t2 VALUES(1, 1);SELECT * from t1;UPDATE t1,t2 SET t1.id=t1.id+1, t2.t1_id=t1.id+1;SELECT * from t1;UPDATE t1,t2 SET t1.id=t1.id+1 where t1.id!=t2.id;SELECT * from t1;DROP TABLE t1,t2;## Test of range_optimizer#set autocommit=0;CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;INSERT INTO t3 VALUES("my-test-1", "my-test-2");COMMIT;INSERT INTO t1 VALUES("this-key", "will disappear");INSERT INTO t2 VALUES("this-key", "will also disappear");DELETE FROM t3 WHERE id1="my-test-1";SELECT * FROM t1;SELECT * FROM t2;SELECT * FROM t3;ROLLBACK;SELECT * FROM t1;SELECT * FROM t2;SELECT * FROM t3;SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;COMMIT;set autocommit=1;DROP TABLE t1,t2,t3;## Check update with conflicting key#CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);# We need the a < 1000 test here to quard against the halloween problemsUPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;SELECT * from t1;drop table t1;## Test multi update with different join methods#CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) engine=innodb;CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) engine=innodb;INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12);INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);# Full join, without keyupdate t1,t2 set t1.a=t1.a+100;select * from t1;# unique keyupdate t1,t2 set t1.a=t1.a+100 where t1.a=101;select * from t1;# ref keyupdate t1,t2 set t1.b=t1.b+10 where t1.b=2;select * from t1;# Range key (in t1)update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t1.a=t2.a+100;select * from t1;select * from t2;drop table t1,t2;CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) ENGINE=MyISAM;CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB;SET AUTOCOMMIT=0;INSERT INTO t1 ( B_ID ) VALUES ( 1 );INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );ROLLBACK;SELECT * FROM t1;drop table t1,t2;create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) engine = innodb;insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2);select distinct parent,child from t1 order by parent;drop table t1;## Test that MySQL priorities clustered indexes#create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;create table t2 (a int not null auto_increment primary key, b int);insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);insert into t2 (a) select b from t1;insert into t1 (b) select b from t2;insert into t2 (a) select b from t1;insert into t1 (a) select b from t2;insert into t2 (a) select b from t1;insert into t1 (a) select b from t2;insert into t2 (a) select b from t1;insert into t1 (a) select b from t2;insert into t2 (a) select b from t1;insert into t1 (a) select b from t2;insert into t2 (a) select b from t1;insert into t1 (a) select b from t2;insert into t2 (a) select b from t1;insert into t1 (a) select b from t2;insert into t2 (a) select b from t1;insert into t1 (a) select b from t2;insert into t2 (a) select b from t1;insert into t1 (a) select b from t2;select count(*) from t1;--replace_column 9 #explain select * from t1 where c between 1 and 10000;update t1 set c=a;--replace_column 9 #explain select * from t1 where c between 1 and 10000;drop table t1,t2;## Test of UPDATE ... ORDER BY#create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;insert into t1 (id) values (null),(null),(null),(null),(null);update t1 set fk=69 where fk is null order by id limit 1;SELECT * from t1;drop table t1;create table t1 (a int not null, b int not null, key (a));insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3);SET @tmp=0;update t1 set b=(@tmp:=@tmp+1) order by a;update t1 set b=99 where a=1 order by b asc limit 1;update t1 set b=100 where a=1 order by b desc limit 2;update t1 set a=a+10+b where a=1 order by b;select * from t1 order by a,b;drop table t1;## Test of multi-table-updates (bug #1980).#create table t1 ( c char(8) not null ) engine=innodb;insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');alter table t1 add b char(8) not null;alter table t1 add a char(8) not null;alter table t1 add primary key (a,b,c);update t1 set a=c, b=c;create table t2 (c char(8) not null, b char(8) not null, a char(8) not null, primary key(a,b,c)) engine=innodb;insert into t2 select * from t1;delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;drop table t1,t2;## test autoincrement with TRUNCATE#SET AUTOCOMMIT=1;create table t1 (a integer auto_increment primary key) engine=innodb;insert into t1 (a) values (NULL),(NULL);truncate table t1;insert into t1 (a) values (NULL),(NULL);SELECT * from t1;drop table t1;## Test dictionary handling with spaceand quoting#CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (`t1_id`) REFERENCES `t1`(`id 1`) ON DELETE CASCADE ) ENGINE=INNODB;#show create table t2;drop table t2,t1;## Test of multi updated and foreign keys#create table `t1` (`id` int( 11 ) not null ,primary key ( `id` )) engine = innodb;insert into `t1`values ( 1 ) ;create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = innodb;insert into `t2`values ( 1 ) ;create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb;insert into `t3`values ( 1 ) ;--error 1451delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;--error 1451update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;--error 1054update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;drop table t3,t2,t1;## test for recursion depth limit#create table t1( id int primary key, pid int, index(pid), foreign key(pid) references t1(id) on delete cascade) engine=innodb;insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6), (8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);-- error 1451delete from t1 where id=0;delete from t1 where id=15;delete from t1 where id=0;drop table t1;## Test timestamps#CREATE TABLE t1 (col1 int(1))ENGINE=InnoDB;CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx(stamp))ENGINE=InnoDB;insert into t1 values (1),(2),(3);# Note that timestamp 3 is wronginsert into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <'20020204120000' GROUP BY col1;drop table t1,t2;## Test by Francois MASUREL#CREATE TABLE t1 ( `id` int(10) unsigned NOT NULL auto_increment, `id_object` int(10) unsigned default '0', `id_version` int(10) unsigned NOT NULL default '1', `label` varchar(100) NOT NULL default '', `description` text, PRIMARY KEY (`id`), KEY `id_object` (`id_object`), KEY `id_version` (`id_version`)) ENGINE=InnoDB;INSERT INTO t1 VALUES("6", "3382", "9", "Test", NULL), ("7", "102", "5", "Le Pekin (Test)", NULL),("584", "1794", "4", "Test de resto", NULL),("837", "1822", "6", "Test 3", NULL),("1119", "3524", "1", "Societe Test", NULL),("1122", "3525", "1", "Fournisseur Test", NULL);CREATE TABLE t2 ( `id` int(10) unsigned NOT NULL auto_increment, `id_version` int(10) unsigned NOT NULL default '1', PRIMARY KEY (`id`), KEY `id_version` (`id_version`)) ENGINE=InnoDB;INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");SELECT t2.id, t1.`label` FROM t2 INNER JOIN(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);drop table t1,t2;create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=myisam;create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=innodb;create table t3 (a int, b varchar(200), c text not null) checksum=1 engine=innodb;insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");insert t2 select * from t1;insert t3 select * from t1;checksum table t1, t2, t3, t4 quick;checksum table t1, t2, t3, t4;checksum table t1, t2, t3, t4 extended;#show table status;drop table t1,t2,t3;## Test problem with refering to different fields in same table in UNION# (Bug #2552)#create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;drop table t1;## Bug2160#create table t1 (a int) engine=innodb;create table t2 like t1;drop table t1,t2;## Test of automaticly created foreign keys#create table t1 (id int(11) not null, id2 int(11) not null, unique (id,id2)) engine=innodb;create table t2 (id int(11) not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;show create table t1;show create table t2;create index id on t2 (id);show create table t2;create index id2 on t2 (id);show create table t2;drop index id2 on t2;--error 1025,1025drop index id on t2;show create table t2;drop table t2;create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;show create table t2;create unique index id on t2 (id,id2);show create table t2;drop table t2;# Check foreign key columns created in different order than key columnscreate table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;show create table t2;drop table t2;create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;show create table t2;drop table t2;create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;show create table t2;drop table t2;create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;show create table t2;drop table t2;create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;show create table t2;alter table t2 add index id_test (id), add index id_test2 (id,id2);show create table t2;drop table t2;# Test error handling# Clean up filename -- embedded server reports whole path without .frm,# regular server reports relative path with .frm (argh!)--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t2.frm t2--error ER_WRONG_FK_DEFcreate table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;# bug#3749create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;show create table t2;drop table t2;create table t2 (a int auto_increment primary key, b int, foreign key (b) references t1(id), foreign key (b) references t1(id), unique(b)) engine=innodb;show create table t2;drop table t2, t1;## Bug #6126: Duplicate columns in keys gives misleading error message#--error 1060create table t1 (c char(10), index (c,c)) engine=innodb;--error 1060create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;--error 1060create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;--error 1060create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;create table t1 (c1 char(10), c2 char(10)) engine=innodb;--error 1060alter table t1 add key (c1,c1);--error 1060alter table t1 add key (c2,c1,c1);--error 1060alter table t1 add key (c1,c2,c1);--error 1060alter table t1 add key (c1,c1,c2);drop table t1;## Bug #4082: integer truncation#create table t1(a int(1) , b int(1)) engine=innodb;insert into t1 values ('1111', '3333');select distinct concat(a, b) from t1;drop table t1;#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -