1
#######################################################################
3
# Please, DO NOT TOUCH this file as well as the innodb.result file. #
4
# These files are to be modified ONLY BY INNOBASE guys. #
6
# Use innodb_mysql.[test|result] files instead. #
8
# If nevertheless you need to make some changes here, please, forward #
9
# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com #
10
# (otherwise your changes may be erased). #
12
#######################################################################
16
# Small basic test with ignore
20
drop table if exists t1,t2,t3,t4;
21
drop database if exists mysqltest;
23
#set engine_condition_pushdown=0;
24
create table t1 (id int not null auto_increment, code int not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
26
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
27
select id, code, name from t1 order by id;
29
update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
30
select id, code, name from t1 order by id;
31
update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
32
select id, code, name from t1 order by id;
38
# The 'replace_column' statements are needed because the cardinality calculated
39
# by innodb is not always the same between runs
43
id int NOT NULL auto_increment,
44
parent_id int DEFAULT '0' NOT NULL,
45
level int DEFAULT '0' NOT NULL,
47
KEY parent_id (parent_id),
50
INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1),(179,5,2);
51
update t1 set parent_id=parent_id+100;
52
select * from t1 where parent_id=102;
53
update t1 set id=id+1000;
54
update t1 set id=1024 where id=1009;
56
update ignore t1 set id=id+1; # This will change all rows
58
update ignore t1 set id=1023 where id=1010;
59
select * from t1 where parent_id=102;
61
explain select level from t1 where level=1;
63
explain select level,id from t1 where level=1;
65
explain select level,id,parent_id from t1 where level=1;
66
select level,id from t1 where level=1;
67
select level,id,parent_id from t1 where level=1;
68
alter table t1 ENGINE=innodb;
78
gesuchnr int DEFAULT '0' NOT NULL,
79
benutzer_id int DEFAULT '0' NOT NULL,
80
PRIMARY KEY (gesuchnr,benutzer_id)
83
replace into t1 (gesuchnr,benutzer_id) values (2,1);
84
replace into t1 (gesuchnr,benutzer_id) values (1,1);
85
replace into t1 (gesuchnr,benutzer_id) values (1,1);
90
# test delete using hidden_primary_key
93
create table t1 (a int) engine=innodb;
94
insert into t1 values (1), (2);
95
alter table t1 engine=innodb;
96
delete from t1 where a = 1;
101
create table t1 (a int,b varchar(20)) engine=innodb;
102
insert into t1 values (1,""), (2,"testing");
103
delete from t1 where a = 1;
105
create index skr on t1 (a);
106
insert into t1 values (3,""), (4,"testing");
113
# Test of reading on secondary key with may be null
115
create table t1 (a int,b varchar(20),key(a)) engine=innodb;
116
insert into t1 values (1,""), (2,"testing");
117
select * from t1 where a = 1;
124
create table t1 (n int not null primary key) engine=innodb;
126
insert into t1 values (4);
128
select n, "after rollback" from t1;
129
insert into t1 values (4);
131
select n, "after commit" from t1;
133
insert into t1 values (5);
134
insert into t1 values (4);
136
select n, "after commit" from t1;
138
insert into t1 values (6);
139
insert into t1 values (4);
146
savepoint `my_savepoint`;
147
insert into t1 values (7);
149
insert into t1 values (3);
152
rollback to savepoint savept2;
154
rollback to savepoint savept3;
155
rollback to savepoint savept2;
156
release savepoint `my_savepoint`;
158
rollback to savepoint `my_savepoint`;
159
rollback to savepoint savept2;
160
insert into t1 values (8);
170
# Test for commit and FLUSH TABLES WITH READ LOCK
173
create table t1 (n int not null primary key) engine=innodb;
175
insert into t1 values (4);
176
flush tables with read lock;
178
# Current code can't handle a read lock in middle of transaction
187
# Testing transactions
190
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
192
insert into t1 values(1,'hamdouni');
193
select id as afterbegin_id,nom as afterbegin_nom from t1;
195
select id as afterrollback_id,nom as afterrollback_nom from t1;
197
insert into t1 values(2,'mysql');
198
select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
200
select id as afterrollback_id,nom as afterrollback_nom from t1;
205
# Simple not autocommit test
208
CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
209
insert into t1 values ('pippo', 12);
210
insert into t1 values ('pippo', 12); # Gives error
212
delete from t1 where id = 'pippo';
215
insert into t1 values ('pippo', 12);
226
# Test of active transactions
229
create table t1 (a integer) engine=innodb;
231
rename table t1 to t2;
232
create table t1 (b integer) engine=innodb;
233
insert into t1 values (1);
236
rename table t2 to t1;
241
# The following simple tests failed at some point
244
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
245
INSERT INTO t1 VALUES (1, 'Jochen');
249
CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
251
INSERT INTO t1 SET _userid='marc@anyware.co.uk';
254
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
259
# Test when reading on part of unique key
262
user_id int DEFAULT '0' NOT NULL,
265
ref_email varchar(100) DEFAULT '' NOT NULL,
267
PRIMARY KEY (user_id,ref_email)
270
INSERT INTO t1 VALUES (10292,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10292,'shirish','2333604','shirish@yahoo.com','ddsds'),(10292,'sonali','323232','sonali@bolly.com','filmstar');
271
select * from t1 where user_id=10292;
272
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
273
select * from t1 where user_id=10292;
274
select * from t1 where user_id>=10292;
275
select * from t1 where user_id>10292;
276
select * from t1 where user_id<10292;
280
# Test that keys are created in right order
283
CREATE TABLE t1 (a int not null, b int not null,c int not null,
284
key(a),primary key(a,b), unique(c),key(a),unique(b));
290
# Test of ALTER TABLE and innodb tables
293
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
294
alter table t1 engine=innodb;
295
insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
297
update t1 set col2='7' where col1='4';
299
alter table t1 add co3 int not null;
301
update t1 set col2='9' where col1='2';
306
# INSERT INTO innodb tables
309
create table t1 (a int not null , b int, primary key (a)) engine = innodb;
310
create TEMPORARY table t2 (a int not null , b int, primary key (a)) engine = myisam;
311
insert into t1 VALUES (1,3) , (2,3), (3,3);
313
insert into t2 select * from t1;
315
delete from t1 where b = 3;
317
insert into t1 select * from t2;
323
# ORDER BY on not primary key
327
user_name varchar(12),
330
user_id int DEFAULT '0' NOT NULL,
335
dummy_primary_key int NOT NULL auto_increment,
336
PRIMARY KEY (dummy_primary_key)
338
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','2000-09-07 23:06:59',1);
339
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','2000-09-07 23:06:59',2);
340
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','2000-09-07 23:06:59',3);
341
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','2000-09-07 23:06:59',4);
342
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','2000-09-07 23:06:59',5);
343
select user_name, password , subscribed, user_id, quota, weight, access_date, approved, dummy_primary_key from t1 order by user_name;
347
# Testing of tables without primary keys
351
id int NOT NULL auto_increment,
352
parent_id int DEFAULT '0' NOT NULL,
353
level int DEFAULT '0' NOT NULL,
355
KEY parent_id (parent_id),
358
INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1);
359
INSERT INTO t1 values (179,5,2);
360
update t1 set parent_id=parent_id+100;
361
select * from t1 where parent_id=102;
362
update t1 set id=id+1000;
363
update t1 set id=1024 where id=1009;
365
update ignore t1 set id=id+1; # This will change all rows
367
update ignore t1 set id=1023 where id=1010;
368
select * from t1 where parent_id=102;
370
explain select level from t1 where level=1;
371
select level,id from t1 where level=1;
372
select level,id,parent_id from t1 where level=1;
373
select level,id from t1 where level=1 order by id;
374
delete from t1 where level=1;
379
# Test of index only reads
382
sca_code char(6) NOT NULL,
383
cat_code char(6) NOT NULL,
384
sca_desc varchar(50),
385
lan_code char(2) NOT NULL,
386
sca_pic varchar(100),
387
sca_sdesc varchar(50),
388
sca_sch_desc varchar(16),
389
PRIMARY KEY (sca_code, cat_code, lan_code),
390
INDEX sca_pic (sca_pic)
393
INSERT INTO t1 ( sca_code, cat_code, sca_desc, lan_code, sca_pic, sca_sdesc, sca_sch_desc) VALUES ( 'PD', 'J', 'PENDANT', 'EN', NULL, NULL, 'PENDANT'),( 'RI', 'J', 'RING', 'EN', NULL, NULL, 'RING'),( 'QQ', 'N', 'RING', 'EN', 'not null', NULL, 'RING');
394
select count(*) from t1 where sca_code = 'PD';
395
select count(*) from t1 where sca_code <= 'PD';
396
select count(*) from t1 where sca_pic is null;
397
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
398
select count(*) from t1 where sca_code='PD' and sca_pic is null;
399
select count(*) from t1 where cat_code='E';
400
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
401
select count(*) from t1 where sca_code='PD' and sca_pic is null;
402
select count(*) from t1 where sca_pic >= 'n';
403
select sca_pic from t1 where sca_pic is null;
404
update t1 set sca_pic="test" where sca_pic is null;
405
delete from t1 where sca_code='pd';
409
# Test of opening table twice and timestamps
412
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
413
insert into t1 (a) values(1),(2),(3);
414
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
415
select a from t1 natural join t1 as t2 where b >= @a order by a;
416
update t1 set a=5 where a=1;
421
# Test with variable length primary key
423
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
424
insert into t1 values("hello",1),("world",2);
425
select * from t1 order by b desc;
426
alter table t1 engine=innodb;
432
# Test of create index with NULL columns
434
create table t1 (i int, j int ) ENGINE=innodb;
435
insert into t1 values (1,2);
436
select * from t1 where i=1 and j=2;
437
create index ax1 on t1 (i,j);
438
select * from t1 where i=1 and j=2;
442
# Test min-max optimization
451
INSERT INTO t1 VALUES (1, 1);
452
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
456
# Test INSERT DELAYED
459
CREATE TABLE t1 (a int NOT NULL) engine=innodb;
460
# Can't test this in 3.23
461
# INSERT DELAYED INTO t1 VALUES (1);
462
INSERT INTO t1 VALUES (1);
468
# Crash when using many tables (Test case by Jeremy D Zawodny)
471
create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, b1 int, b2 int, b3 int, b4 int, b5 int, b6 int) engine = innodb;
472
insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
474
explain select * from t1 where a > 0 and a < 50;
480
create table t1 (a char(20), unique (a(5))) engine=innodb;
482
create table t1 (a char(20), index (a(5))) engine=innodb;
483
show create table t1;
487
# Test using temporary table and auto_increment
490
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
491
insert into t1 values (NULL),(NULL),(NULL);
492
delete from t1 where a=3;
493
insert into t1 values (NULL);
495
alter table t1 add b int;
500
## Heikki had nevered considered the possibility of a second key that could
501
## be used as a primary key for replace. This is from the table that
502
## generates topics and "vars" -Brian
505
id int auto_increment primary key,
506
name varchar(32) not null,
511
insert into t1 values (1,'one','one value',101),
512
(2,'two','two value',102),(3,'three','three value',103);
513
replace into t1 (value,name,uid) values ('other value','two',102);
514
delete from t1 where uid=102;
515
replace into t1 (value,name,uid) values ('other value','two',102);
516
replace into t1 (value,name,uid) values ('other value','two',102);
524
create database mysqltest;
525
create table mysqltest.t1 (a int not null) engine= innodb;
526
insert into mysqltest.t1 values(1);
527
create TEMPORARY table mysqltest.t2 (a int not null) engine= myisam;
528
insert into mysqltest.t2 values(1);
529
create temporary table mysqltest.t3 (a int not null) engine= MEMORY;
530
insert into mysqltest.t3 values(1);
532
drop database mysqltest;
533
# Don't check error message
535
show tables from mysqltest;
538
# Test truncate table with and without auto_commit
542
create table t1 (a int not null) engine= innodb;
543
insert into t1 values(1),(2);
549
insert into t1 values(1),(2);
556
create table t1 (a int not null) engine= innodb;
557
insert into t1 values(1),(2);
559
insert into t1 values(1),(2);
562
insert into t1 values(1),(2);
568
# Test of how ORDER BY works when doing it on the whole table
571
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
572
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
574
explain select * from t1 order by a;
576
explain select * from t1 order by b;
578
explain select * from t1 order by c;
580
explain select a from t1 order by a;
582
explain select b from t1 order by b;
584
explain select a,b from t1 order by b;
586
explain select a,b from t1;
588
explain select a,b,c from t1;
595
create table t1 (t int not null default 1, key (t)) engine=innodb;
600
# A simple test with some isolation levels
601
# TODO: Make this into a test using replication to really test how
605
create table t1 (id int not null auto_increment, code int not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
608
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
609
SELECT @@tx_isolation,@@global.tx_isolation;
610
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
611
select id, code, name from t1 order by id;
615
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
616
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
617
select id, code, name from t1 order by id;
621
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
622
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
623
select id, code, name from t1 order by id;
630
create table t1 (a int, b int) engine=innodb;
631
insert into t1 values(20,null);
632
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
634
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
635
t2.b=t3.a order by 1;
636
insert into t1 values(10,null);
637
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
638
t2.b=t3.a order by 1;
642
# Test of read_through not existing const_table
645
create TEMPORARY table t1 (a varchar(10) not null) engine=myisam;
646
create table t2 (b varchar(10) not null unique) engine=innodb;
647
select t1.a from t1,t2 where t1.a=t2.b;
649
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
650
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
651
insert into t1 values (10, 20);
652
insert into t2 values (10, 20);
656
# Test of range_optimizer
661
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
663
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
665
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
667
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
670
INSERT INTO t1 VALUES("this-key", "will disappear");
671
INSERT INTO t2 VALUES("this-key", "will also disappear");
672
DELETE FROM t3 WHERE id1="my-test-1";
682
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
688
# Check update with conflicting key
691
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
692
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
693
# We need the a < 1000 test here to quard against the halloween problems
694
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
699
# Test that MySQL priorities clustered indexes
701
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
702
create table t2 (a int not null auto_increment primary key, b int);
703
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
704
insert into t2 (a) select b from t1;
705
insert into t1 (b) select b from t2;
706
insert into t2 (a) select b from t1;
707
insert into t1 (a) select b from t2;
708
insert into t2 (a) select b from t1;
709
insert into t1 (a) select b from t2;
710
insert into t2 (a) select b from t1;
711
insert into t1 (a) select b from t2;
712
insert into t2 (a) select b from t1;
713
insert into t1 (a) select b from t2;
714
select count(*) from t1;
716
explain select * from t1 where c between 1 and 2500;
719
explain select * from t1 where c between 1 and 2500;
723
# Test of UPDATE ... ORDER BY
726
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
728
insert into t1 (id) values (null),(null),(null),(null),(null);
729
update t1 set fk=69 where fk is null order by id limit 1;
733
create table t1 (a int not null, b int not null, key (a));
734
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);
736
update t1 set b=(@tmp:=@tmp+1) order by a;
737
update t1 set b=99 where a=1 order by b asc limit 1;
738
update t1 set b=100 where a=1 order by b desc limit 2;
739
update t1 set a=a+10+b where a=1 order by b;
740
select * from t1 order by a,b;
744
# test autoincrement with TRUNCATE
748
create table t1 (a integer auto_increment primary key) engine=innodb;
749
insert into t1 (a) values (NULL),(NULL);
751
insert into t1 (a) values (NULL),(NULL);
756
# Test dictionary handling with spaceand quoting
759
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
760
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;
761
#show create table t2;
765
# test for recursion depth limit
771
foreign key(pid) references t1(id) on delete cascade) engine=innodb;
772
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
773
(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
774
delete from t1 where id=0;
775
delete from t1 where id=15;
776
delete from t1 where id=0;
784
CREATE TABLE t1 (col1 int) ENGINE=InnoDB;
785
CREATE TABLE t2 (col1 int, stamp TIMESTAMP,INDEX stamp_idx (stamp)) ENGINE=InnoDB;
786
insert into t1 values (1),(2),(3);
787
# Note that timestamp 3 is wrong
788
insert into t2 values (1, 20020204110000),(2, 20020204110001),(4,20020204110002 ),(5,20020204110003);
789
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
790
'20020204120000' GROUP BY col1;
794
# Test by Francois MASUREL
798
`id` int NOT NULL auto_increment,
799
`id_object` int default '0',
800
`id_version` int NOT NULL default '1',
801
`label` varchar(100) NOT NULL default '',
804
KEY `id_object` (`id_object`),
805
KEY `id_version` (`id_version`)
808
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);
811
`id` int NOT NULL auto_increment,
812
`id_version` int NOT NULL default '1',
814
KEY `id_version` (`id_version`)
817
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
819
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
820
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
821
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
824
create TEMPORARY table t1 (a int, b varchar(200), c text not null) engine=myisam;
825
create table t2 (a int, b varchar(200), c text not null) engine=innodb;
826
create table t3 (a int, b varchar(200), c text not null) engine=innodb;
827
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
828
insert t2 select * from t1;
829
insert t3 select * from t1;
830
checksum table t1, t2, t3, t4;
831
checksum table t1, t2, t3, t4;
832
checksum table t1, t2, t3, t4;
833
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
837
# Test problem with refering to different fields in same table in UNION
840
create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
841
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
842
select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
848
create table t1 (a int) engine=innodb;
849
create table t2 like t1;
853
# Test of automaticly created foreign keys
856
create table t1 (id int not null, id2 int not null, unique (id,id2)) engine=innodb;
857
create table t2 (id int not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
858
show create table t1;
859
show create table t2;
860
create index id on t2 (id);
861
show create table t2;
862
create index id2 on t2 (id);
863
show create table t2;
864
drop index id2 on t2;
867
show create table t2;
870
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;
871
show create table t2;
872
create unique index id on t2 (id,id2);
873
show create table t2;
876
# Check foreign key columns created in different order than key columns
877
create table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
878
show create table t2;
881
create table t2 (id int not null, id2 int not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;
882
show create table t2;
885
create table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
886
show create table t2;
889
create table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
890
show create table t2;
893
create table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
894
show create table t2;
895
alter table t2 add index id_test (id), add index id_test2 (id,id2);
896
show create table t2;
899
# Test error handling
901
# Embedded server doesn't chdir to data directory
902
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
903
--error ER_WRONG_FK_DEF
904
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
908
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
909
show create table t2;
911
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;
912
show create table t2;
917
# Bug #6126: Duplicate columns in keys gives misleading error message
920
create table t1 (c char(10), index (c,c)) engine=innodb;
922
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
924
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
926
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
927
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
929
alter table t1 add key (c1,c1);
931
alter table t1 add key (c2,c1,c1);
933
alter table t1 add key (c1,c2,c1);
935
alter table t1 add key (c1,c1,c2);
939
# Bug #4082: integer truncation
942
create table t1(a int, b int) engine=innodb;
943
insert into t1 values ('1111', '3333');
944
select distinct concat(a, b) from t1;
948
# check null values #1
952
CREATE TABLE t1 (a_id int NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=InnoDB;
953
INSERT INTO t1 VALUES (1),(2),(3);
954
CREATE TABLE t2 (b_id int NOT NULL default '0',b_a int NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
955
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB;
957
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
958
SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN (t2) on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
963
# Bug#11816 - Truncate table doesn't work with temporary innodb tables
964
# This is not an innodb bug, but we test it using innodb.
966
create temporary table t1 (a int) engine=innodb;
967
insert into t1 values (4711);
969
insert into t1 values (42);
972
# Show that it works with permanent tables too.
973
create table t1 (a int) engine=innodb;
974
insert into t1 values (4711);
976
insert into t1 values (42);
981
# Bug #13025 Server crash during filesort
984
create table t1 (a int not null, b int not null, c blob not null, d int not null, e int, primary key (a,b,c(255),d)) engine=innodb;
985
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
986
select * from t1 order by a,b,c,d;
987
explain select * from t1 order by a,b,c,d;
991
# BUG#11039,#13218 Wrong key length in min()
994
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
995
insert into t1 values ('8', '6'), ('4', '7');
996
select min(a) from t1;
997
select min(b) from t1 where a='8';
1003
# range optimizer problem
1006
create table t1 (x bigint not null primary key) engine=innodb;
1007
insert into t1(x) values (0x0ffffffffffffff0),(0x0ffffffffffffff1);
1009
select count(*) from t1 where x>0;
1010
select count(*) from t1 where x=0;
1011
select count(*) from t1 where x<0;
1012
select count(*) from t1 where x < -16;
1013
select count(*) from t1 where x = -16;
1014
explain select count(*) from t1 where x > -16;
1015
select count(*) from t1 where x > -16;
1016
select * from t1 where x > -16;
1017
select count(*) from t1 where x = 1152921504606846961;
1021
## Not deterministic.
1022
# Test for testable InnoDB status variables. This test
1023
# uses previous ones(pages_created, rows_deleted, ...).
1024
--replace_column 2 #
1025
show status like "Innodb_buffer_pool_pages_total";
1026
--replace_column 2 #
1027
show status like "Innodb_page_size";
1028
--replace_column 2 #
1029
show status like "Innodb_rows_deleted";
1030
--replace_column 2 #
1031
show status like "Innodb_rows_inserted";
1032
--replace_column 2 #
1033
show status like "Innodb_rows_updated";
1035
## Test for row locks InnoDB status variables.
1036
--replace_column 2 #
1037
show status like "Innodb_row_lock_waits";
1038
--replace_column 2 #
1039
show status like "Innodb_row_lock_current_waits";
1040
--replace_column 2 #
1041
show status like "Innodb_row_lock_time";
1042
--replace_column 2 #
1043
show status like "Innodb_row_lock_time_max";
1044
--replace_column 2 #
1045
show status like "Innodb_row_lock_time_avg";
1047
# Test for innodb_sync_spin_loops variable
1048
show variables like "innodb_sync_spin_loops";
1049
set global innodb_sync_spin_loops=1000;
1050
show variables like "innodb_sync_spin_loops";
1051
set global innodb_sync_spin_loops=0;
1052
show variables like "innodb_sync_spin_loops";
1053
set global innodb_sync_spin_loops=20;
1054
show variables like "innodb_sync_spin_loops";
1056
# Test for innodb_thread_concurrency variable
1057
show variables like "innodb_thread_concurrency";
1058
set global innodb_thread_concurrency=1001;
1059
show variables like "innodb_thread_concurrency";
1060
set global innodb_thread_concurrency=0;
1061
show variables like "innodb_thread_concurrency";
1062
set global innodb_thread_concurrency=16;
1063
show variables like "innodb_thread_concurrency";
1065
# Test for innodb_concurrency_tickets variable
1066
show variables like "innodb_concurrency_tickets";
1067
set global innodb_concurrency_tickets=1000;
1068
show variables like "innodb_concurrency_tickets";
1069
set global innodb_concurrency_tickets=0;
1070
show variables like "innodb_concurrency_tickets";
1071
set global innodb_concurrency_tickets=500;
1072
show variables like "innodb_concurrency_tickets";
1074
# Test for innodb_thread_sleep_delay variable
1075
show variables like "innodb_thread_sleep_delay";
1076
set global innodb_thread_sleep_delay=100000;
1077
show variables like "innodb_thread_sleep_delay";
1078
set global innodb_thread_sleep_delay=0;
1079
show variables like "innodb_thread_sleep_delay";
1080
set global innodb_thread_sleep_delay=10000;
1081
show variables like "innodb_thread_sleep_delay";
1087
let $default=`select @@storage_engine`;
1088
set storage_engine=INNODB;
1089
source include/varchar.inc;
1092
# Some errors/warnings on create
1095
# Embedded server doesn't chdir to data directory
1096
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1097
create table t1 (v varchar(16383), key(v));
1099
create table t1 (v varchar(16383));
1100
show create table t1;
1102
create table t1 (v varchar(16383));
1103
show create table t1;
1106
eval set storage_engine=$default;
1108
# InnoDB specific varchar tests
1109
create table t1 (v varchar(16383)) engine=innodb;
1113
# BUG#11039 Wrong key length in min()
1116
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1117
insert into t1 values ('8', '6'), ('4', '7');
1118
select min(a) from t1;
1119
select min(b) from t1 where a='8';
1123
# Bug #11080 & #11005 Multi-row REPLACE fails on a duplicate key error
1126
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
1127
insert into t1 (b) values (1);
1128
replace into t1 (b) values (2), (1), (3);
1131
insert into t1 (b) values (1);
1132
replace into t1 (b) values (2);
1133
replace into t1 (b) values (1);
1134
replace into t1 (b) values (3);
1138
create table t1 (rowid int not null auto_increment, val int not null,primary
1139
key (rowid), unique(val)) engine=innodb;
1140
replace into t1 (val) values ('1'),('2');
1141
replace into t1 (val) values ('1'),('2');
1142
--error ER_DUP_ENTRY
1143
insert into t1 (val) values ('1'),('2');
1148
# Test that update does not change internal auto-increment value
1151
create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
1152
insert into t1 (val) values (1);
1153
update t1 set a=2 where a=1;
1154
# We should get the following error because InnoDB does not update the counter
1155
--error ER_DUP_ENTRY
1156
insert into t1 (val) values (1);
1164
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
1166
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
1167
SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300;
1168
SELECT GRADE FROM t1 WHERE GRADE= 151;
1172
# Test that the slow TRUNCATE implementation resets autoincrement columns
1177
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
1181
id INTEGER NOT NULL,
1182
FOREIGN KEY (id) REFERENCES t1 (id)
1185
INSERT INTO t1 (id) VALUES (NULL);
1188
INSERT INTO t1 (id) VALUES (NULL);
1191
# continued from above; test that doing a slow TRUNCATE on a table with 0
1192
# rows resets autoincrement columns
1195
INSERT INTO t1 (id) VALUES (NULL);
1199
# Test that foreign keys in temporary tables are not accepted (bug #12084)
1206
CREATE TEMPORARY TABLE t2
1208
id INT NOT NULL PRIMARY KEY,
1210
FOREIGN KEY (b) REFERENCES test.t1(id)
1215
# Test that index column max sizes are honored (bug #13315)
1219
create table t1 (col1 varchar(2000), index (col1(767)))
1223
create table t2 (col1 char(255), index (col1))
1225
create table t4 (col1 varchar(767), index (col1))
1227
create table t5 (col1 varchar(190) primary key)
1229
create table t6 (col1 varbinary(254) primary key)
1231
create table t7 (col1 text, index(col1(767)))
1233
create table t8 (col1 blob, index(col1(767)))
1236
# multi-column indexes are allowed to be longer
1237
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
1240
show create table t9;
1242
drop table t1, t2, t4, t5, t6, t7, t8, t9;
1244
# these should have their index length trimmed
1245
create table t1 (col1 varchar(768), index(col1))
1247
create table t2 (col1 varbinary(768), index(col1))
1249
create table t3 (col1 text, index(col1(768)))
1251
create table t4 (col1 blob, index(col1(768)))
1254
show create table t1;
1256
drop table t1, t2, t3, t4;
1258
# these should be refused
1260
create table t1 (col1 varchar(768) primary key)
1263
create table t2 (col1 varbinary(768) primary key)
1266
create table t3 (col1 text, primary key(col1(768)))
1269
create table t4 (col1 blob, primary key(col1(768)))
1273
# Test improved foreign key error messages (bug #3443)
1284
CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
1288
INSERT INTO t2 VALUES(2);
1290
INSERT INTO t1 VALUES(1);
1291
INSERT INTO t2 VALUES(1);
1294
DELETE FROM t1 WHERE id = 1;
1299
SET FOREIGN_KEY_CHECKS=0;
1301
SET FOREIGN_KEY_CHECKS=1;
1304
INSERT INTO t2 VALUES(3);
1308
# Test that checksum table uses a consistent read Bug #12669
1310
connect (a,localhost,root,,);
1311
connect (b,localhost,root,,);
1313
create table t1(a int not null) engine=innodb;
1314
insert into t1 values (1),(2);
1318
insert into t1 values(3);
1321
# Here checksum should not see insert
1333
create table t1(a int not null) engine=innodb;
1334
insert into t1 values (1),(2);
1339
insert into t1 values(3);
1342
# Here checksum sees insert
1351
# tests for bugs #9802 and #13778
1353
# test that FKs between invalid types are not accepted
1355
set foreign_key_checks=0;
1356
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
1357
# Embedded server doesn't chdir to data directory
1358
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1359
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
1360
set foreign_key_checks=1;
1363
# test that invalid datatype conversions with ALTER are not allowed
1365
set foreign_key_checks=0;
1366
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
1367
create table t1(a varchar(10) primary key) engine = innodb;
1368
alter table t1 modify column a int;
1369
set foreign_key_checks=1;
1372
# test that foreign key errors are reported correctly (Bug #15550)
1374
create table t1(a int primary key) row_format=redundant engine=innodb;
1375
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
1376
create table t3(a int primary key) row_format=compact engine=innodb;
1377
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
1379
insert into t1 values(1);
1380
insert into t3 values(1);
1381
insert into t2 values(2);
1382
insert into t4 values(2);
1383
insert into t2 values(1);
1384
insert into t4 values(1);
1396
drop table t4,t3,t2,t1;
1400
# Test that we can create a large (>1K) key
1402
create table t1 (a varchar(255),
1406
key (a,b,c,d)) engine=innodb;
1408
--error ER_TOO_LONG_KEY
1409
create table t1 (a varchar(255),
1414
key (a,b,c,d,e)) engine=innodb;
1417
# test the padding of BINARY types and collations (Bug #14189)
1419
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
1420
create table t3 (s1 varchar(2) ,primary key (s1)) engine=innodb;
1421
create table t4 (s1 char(2) ,primary key (s1)) engine=innodb;
1423
insert into t1 values (0x41),(0x4120),(0x4100);
1424
insert into t3 values (0x41),(0x4120),(0x4100);
1425
insert into t3 values (0x41),(0x4100);
1426
insert into t4 values (0x41),(0x4120),(0x4100);
1427
insert into t4 values (0x41),(0x4100);
1428
select hex(s1) from t1;
1429
select hex(s1) from t3;
1430
select hex(s1) from t4;
1431
drop table t1,t3,t4;
1433
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
1434
create table t2 (s1 varbinary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
1436
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
1437
insert into t2 values(0x42);
1438
insert into t2 values(0x41);
1439
select hex(s1) from t2;
1440
update t1 set s1=0x123456 where a=2;
1441
select hex(s1) from t2;
1442
update t1 set s1=0x12 where a=1;
1443
update t1 set s1=0x12345678 where a=1;
1444
update t1 set s1=0x123457 where a=1;
1445
update t1 set s1=0x1220 where a=1;
1446
select hex(s1) from t2;
1447
update t1 set s1=0x1200 where a=1;
1448
select hex(s1) from t2;
1449
update t1 set s1=0x4200 where a=1;
1450
select hex(s1) from t2;
1451
delete from t1 where a=1;
1452
update t2 set s1=0x4120;
1454
delete from t1 where a!=3;
1455
select a,hex(s1) from t1;
1456
select hex(s1) from t2;
1460
create table t1 (a int primary key,s1 varchar(2) not null unique) engine=innodb;
1461
create table t2 (s1 char(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
1463
insert into t1 values(1,0x4100),(2,0x41);
1464
insert into t2 values(0x41);
1465
select hex(s1) from t2;
1466
update t1 set s1=0x1234 where a=1;
1467
select hex(s1) from t2;
1468
update t1 set s1=0x12 where a=2;
1469
select hex(s1) from t2;
1470
delete from t1 where a=1;
1471
delete from t1 where a=2;
1472
select a,hex(s1) from t1;
1473
select hex(s1) from t2;
1476
# Ensure that <tablename>_ibfk_0 is not mistreated as a
1477
# generated foreign key identifier. (Bug #16387)
1479
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
1480
CREATE TABLE t2(a INT) ENGINE=InnoDB;
1481
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
1482
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
1483
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
1484
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
1485
SHOW CREATE TABLE t2;
1489
# Test that cascading updates leading to duplicate keys give the correct
1490
# error message (bug #9680)
1494
field1 varchar(8) NOT NULL DEFAULT '',
1495
field2 varchar(8) NOT NULL DEFAULT '',
1496
PRIMARY KEY (field1, field2)
1500
field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
1501
FOREIGN KEY (field1) REFERENCES t1 (field1)
1502
ON DELETE CASCADE ON UPDATE CASCADE
1505
INSERT INTO t1 VALUES ('old', 'somevalu');
1506
INSERT INTO t1 VALUES ('other', 'anyvalue');
1508
INSERT INTO t2 VALUES ('old');
1509
INSERT INTO t2 VALUES ('other');
1511
--error ER_FOREIGN_DUPLICATE_KEY
1512
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
1518
# Bug#18477 - MySQL/InnoDB Ignoring Foreign Keys in ALTER TABLE
1532
alter table t1 add constraint c2_fk foreign key (c2)
1533
references t2(c1) on delete cascade;
1534
show create table t1;
1536
alter table t1 drop foreign key c2_fk;
1537
show create table t1;
1542
# Bug #14360: problem with intervals
1545
create table t1(a date) engine=innodb;
1546
create table t2(a date, key(a)) engine=innodb;
1547
insert into t1 values('2005-10-01');
1548
insert into t2 values('2005-10-01');
1549
select * from t1, t2
1550
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
1553
create table t1 (id int not null, f_id int not null, f int not null,
1554
primary key(f_id, id)) engine=innodb;
1555
create table t2 (id int not null,s_id int not null,s varchar(200),
1556
primary key(id)) engine=innodb;
1557
INSERT INTO t1 VALUES (8, 1, 3);
1558
INSERT INTO t1 VALUES (1, 2, 1);
1559
INSERT INTO t2 VALUES (1, 0, '');
1560
INSERT INTO t2 VALUES (8, 1, '');
1562
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
1563
where mm.id is null lock in share mode;
1567
# Test case where X-locks on unused rows should be released in a
1568
# update (because READ COMMITTED isolation level)
1571
connect (a,localhost,root,,);
1572
connect (b,localhost,root,,);
1574
create table t1(a int not null, b int, primary key(a)) engine=innodb;
1575
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
1578
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1579
update t1 set b = 5 where b = 1;
1582
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1584
# X-lock to record (7,3) should be released in a update
1586
select * from t1 where a = 7 and b = 3 for update;
1597
# Test case where no locks should be released (because we are not
1598
# using READ COMMITTED isolation level)
1601
connect (a,localhost,root,,);
1602
connect (b,localhost,root,,);
1604
create table t1(a int not null, b int, primary key(a)) engine=innodb;
1605
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
1608
select * from t1 lock in share mode;
1609
update t1 set b = 5 where b = 1;
1613
# S-lock to records (2,2),(4,2), and (6,2) should not be released in a update
1616
select * from t1 where a = 2 and b = 2 for update;
1618
# X-lock to record (1,1),(3,1),(5,1) should not be released in a update
1631
# Consistent read should be used in following selects
1633
# 1) INSERT INTO ... SELECT
1634
# 2) UPDATE ... = ( SELECT ...)
1635
# 3) CREATE ... SELECT
1637
connect (a,localhost,root,,);
1638
connect (b,localhost,root,,);
1640
create table t1(a int not null, b int, primary key(a)) engine=innodb;
1641
insert into t1 values (1,2),(5,3),(4,2);
1642
create table t2(d int not null, e int, primary key(d)) engine=innodb;
1643
insert into t2 values (8,6),(12,1),(3,1);
1646
select * from t2 for update;
1649
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1650
insert into t1 select * from t2;
1651
update t1 set b = (select e from t2 where a = d);
1652
create table t3(d int not null, e int, primary key(d)) engine=innodb
1660
drop table t1, t2, t3;
1663
# Consistent read should not be used if
1665
# (a) isolation level is serializable OR
1666
# (b) select ... lock in share mode OR
1667
# (c) select ... for update
1669
# in following queries:
1671
# 1) INSERT INTO ... SELECT
1672
# 2) UPDATE ... = ( SELECT ...)
1673
# 3) CREATE ... SELECT
1675
connect (a,localhost,root,,);
1676
connect (b,localhost,root,,);
1677
connect (c,localhost,root,,);
1678
connect (d,localhost,root,,);
1679
connect (e,localhost,root,,);
1680
connect (f,localhost,root,,);
1681
connect (g,localhost,root,,);
1682
connect (h,localhost,root,,);
1683
connect (i,localhost,root,,);
1684
connect (j,localhost,root,,);
1686
create table t1(a int not null, b int, primary key(a)) engine=innodb;
1687
insert into t1 values (1,2),(5,3),(4,2);
1688
create table t2(a int not null, b int, primary key(a)) engine=innodb;
1689
insert into t2 values (8,6),(12,1),(3,1);
1690
create table t3(d int not null, b int, primary key(d)) engine=innodb;
1691
insert into t3 values (8,6),(12,1),(3,1);
1692
create table t5(a int not null, b int, primary key(a)) engine=innodb;
1693
insert into t5 values (1,2),(5,3),(4,2);
1694
create table t6(d int not null, e int, primary key(d)) engine=innodb;
1695
insert into t6 values (8,6),(12,1),(3,1);
1696
create table t8(a int not null, b int, primary key(a)) engine=innodb;
1697
insert into t8 values (1,2),(5,3),(4,2);
1698
create table t9(d int not null, e int, primary key(d)) engine=innodb;
1699
insert into t9 values (8,6),(12,1),(3,1);
1702
select * from t2 for update;
1705
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
1707
insert into t1 select * from t2;
1710
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
1712
update t3 set b = (select b from t2 where a = d);
1715
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
1717
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
1720
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1722
insert into t5 (select * from t2 lock in share mode);
1725
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1727
update t6 set e = (select b from t2 where a = d lock in share mode);
1730
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1732
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
1735
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1737
insert into t8 (select * from t2 for update);
1740
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1742
update t9 set e = (select b from t2 where a = d for update);
1745
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1747
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
1799
drop table t1, t2, t3, t5, t6, t8, t9;
1801
# bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID"
1803
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
1806
# Bug #17152: Wrong result with BINARY comparison on aliased column
1816
b VARCHAR(128) NOT NULL,
1819
KEY idx_t2_b_c (b,c(200)),
1820
CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a)
1824
INSERT INTO t1 VALUES (1);
1825
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
1826
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
1827
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
1828
INSERT INTO t2 VALUES (1, 'customer_over', '1');
1830
SELECT * FROM t2 WHERE b = 'customer_over';
1831
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
1832
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
1833
/* Bang: Empty result set, above was expected: */
1834
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
1835
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
1840
# Test optimize on table with open transaction
1843
CREATE TABLE t1 ( a int ) ENGINE=innodb;
1845
INSERT INTO t1 VALUES (1);
1846
ALTER TABLE t1 ENGINE=innodb;
1850
# Bug #24741 (existing cascade clauses disappear when adding foreign keys)
1853
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
1855
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
1856
CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
1857
ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
1859
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
1860
DELETE CASCADE ON UPDATE CASCADE;
1862
SHOW CREATE TABLE t2;
1866
# Bug #25927: Prevent ALTER TABLE ... MODIFY ... NOT NULL on columns
1867
# for which there is a foreign key constraint ON ... SET NULL.
1870
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
1871
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
1872
INSERT INTO t1 VALUES (1);
1873
INSERT INTO t2 VALUES (1);
1874
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
1875
# mysqltest first does replace_regex, then replace_result
1876
--replace_regex /'[^']*test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
1877
# Embedded server doesn't chdir to data directory
1878
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1880
ALTER TABLE t2 MODIFY a INT NOT NULL;
1885
# Bug #26835: table corruption after delete+insert
1888
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
1890
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
1892
INSERT INTO t1 VALUES ('DDD');
1897
# Bug #23313 (AUTO_INCREMENT=# not reported back for InnoDB tables)
1898
# Bug #21404 (AUTO_INCREMENT value reset when Adding FKEY (or ALTER?))
1901
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
1904
INSERT INTO t1 VALUES (NULL),(347),(NULL);
1907
SHOW CREATE TABLE t1;
1909
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
1910
INSERT INTO t2 VALUES(42),(347),(348);
1911
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
1912
SHOW CREATE TABLE t1;
1917
# Bug #31860 InnoDB assumes AUTOINC values can only be positive.
1919
DROP TABLE IF EXISTS t1;
1921
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
1923
INSERT INTO t1 VALUES(-10);
1926
# NOTE: The server really needs to be restarted at this point
1927
# for the test to be useful.
1929
# Without the fix InnoDB would trip over an assertion here.
1930
INSERT INTO t1 VALUES(NULL);
1931
# The next value should be 1 and not -9 or a -ve number
1935
#######################################################################
1937
# Please, DO NOT TOUCH this file as well as the innodb.result file. #
1938
# These files are to be modified ONLY BY INNOBASE guys. #
1940
# Use innodb_mysql.[test|result] files instead. #
1942
# If nevertheless you need to make some changes here, please, forward #
1943
# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com #
1944
# (otherwise your changes may be erased). #
1946
#######################################################################