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
#######################################################################
14
-- source include/have_innodb.inc
17
# Small basic test with ignore
21
drop table if exists t1,t2,t3,t4;
22
drop database if exists mysqltest;
25
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
27
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
28
select id, code, name from t1 order by id;
30
update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
31
select id, code, name from t1 order by id;
32
update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
33
select id, code, name from t1 order by id;
39
# The 'replace_column' statements are needed because the cardinality calculated
40
# by innodb is not always the same between runs
44
id int(11) NOT NULL auto_increment,
45
parent_id int(11) DEFAULT '0' NOT NULL,
46
level tinyint(4) DEFAULT '0' NOT NULL,
48
KEY parent_id (parent_id),
51
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);
52
update t1 set parent_id=parent_id+100;
53
select * from t1 where parent_id=102;
54
update t1 set id=id+1000;
55
-- error ER_DUP_ENTRY,1022
56
update t1 set id=1024 where id=1009;
58
update ignore t1 set id=id+1; # This will change all rows
60
update ignore t1 set id=1023 where id=1010;
61
select * from t1 where parent_id=102;
63
explain select level from t1 where level=1;
65
explain select level,id from t1 where level=1;
67
explain select level,id,parent_id from t1 where level=1;
68
select level,id from t1 where level=1;
69
select level,id,parent_id from t1 where level=1;
80
gesuchnr int(11) DEFAULT '0' NOT NULL,
81
benutzer_id int(11) DEFAULT '0' NOT NULL,
82
PRIMARY KEY (gesuchnr,benutzer_id)
85
replace into t1 (gesuchnr,benutzer_id) values (2,1);
86
replace into t1 (gesuchnr,benutzer_id) values (1,1);
87
replace into t1 (gesuchnr,benutzer_id) values (1,1);
92
# test delete using hidden_primary_key
95
create table t1 (a int) engine=innodb;
96
insert into t1 values (1), (2);
98
delete from t1 where a = 1;
103
create table t1 (a int,b varchar(20)) engine=innodb;
104
insert into t1 values (1,""), (2,"testing");
105
delete from t1 where a = 1;
107
create index skr on t1 (a);
108
insert into t1 values (3,""), (4,"testing");
115
# Test of reading on secondary key with may be null
117
create table t1 (a int,b varchar(20),key(a)) engine=innodb;
118
insert into t1 values (1,""), (2,"testing");
119
select * from t1 where a = 1;
126
create table t1 (n int not null primary key) engine=innodb;
128
insert into t1 values (4);
130
select n, "after rollback" from t1;
131
insert into t1 values (4);
133
select n, "after commit" from t1;
135
insert into t1 values (5);
136
-- error ER_DUP_ENTRY
137
insert into t1 values (4);
139
select n, "after commit" from t1;
141
insert into t1 values (6);
142
-- error ER_DUP_ENTRY
143
insert into t1 values (4);
150
savepoint `my_savepoint`;
151
insert into t1 values (7);
153
insert into t1 values (3);
156
rollback to savepoint savept2;
158
rollback to savepoint savept3;
159
rollback to savepoint savept2;
160
release savepoint `my_savepoint`;
163
rollback to savepoint `my_savepoint`;
165
rollback to savepoint savept2;
166
insert into t1 values (8);
176
# Test for commit and FLUSH TABLES WITH READ LOCK
179
create table t1 (n int not null primary key) engine=innodb;
181
insert into t1 values (4);
182
flush tables with read lock;
184
# Current code can't handle a read lock in middle of transaction
193
# Testing transactions
196
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
198
insert into t1 values(1,'hamdouni');
199
select id as afterbegin_id,nom as afterbegin_nom from t1;
201
select id as afterrollback_id,nom as afterrollback_nom from t1;
203
insert into t1 values(2,'mysql');
204
select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
206
select id as afterrollback_id,nom as afterrollback_nom from t1;
211
# Simple not autocommit test
214
CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
215
insert into t1 values ('pippo', 12);
216
-- error ER_DUP_ENTRY
217
insert into t1 values ('pippo', 12); # Gives error
219
delete from t1 where id = 'pippo';
222
insert into t1 values ('pippo', 12);
233
# Test of active transactions
236
create table t1 (a integer) engine=innodb;
238
rename table t1 to t2;
239
create table t1 (b integer) engine=innodb;
240
insert into t1 values (1);
243
rename table t2 to t1;
248
# The following simple tests failed at some point
251
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
252
INSERT INTO t1 VALUES (1, 'Jochen');
256
CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
258
INSERT INTO t1 SET _userid='marc@anyware.co.uk';
261
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
266
# Test when reading on part of unique key
269
user_id int(10) DEFAULT '0' NOT NULL,
272
ref_email varchar(100) DEFAULT '' NOT NULL,
274
PRIMARY KEY (user_id,ref_email)
277
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');
278
select * from t1 where user_id=10292;
279
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
280
select * from t1 where user_id=10292;
281
select * from t1 where user_id>=10292;
282
select * from t1 where user_id>10292;
283
select * from t1 where user_id<10292;
287
# Test that keys are created in right order
290
CREATE TABLE t1 (a int not null, b int not null,c int not null,
291
key(a),primary key(a,b), unique(c),key(a),unique(b));
297
# Test of ALTER TABLE and innodb tables
300
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
301
alter table t1 engine=innodb;
302
insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
304
update t1 set col2='7' where col1='4';
306
alter table t1 add co3 int not null;
308
update t1 set col2='9' where col1='2';
313
# INSERT INTO innodb tables
316
create table t1 (a int not null , b int, primary key (a)) engine = innodb;
317
create table t2 (a int not null , b int, primary key (a)) engine = myisam;
318
insert into t1 VALUES (1,3) , (2,3), (3,3);
320
insert into t2 select * from t1;
322
delete from t1 where b = 3;
324
insert into t1 select * from t2;
330
# ORDER BY on not primary key
334
user_name varchar(12),
337
user_id int(11) DEFAULT '0' NOT NULL,
343
dummy_primary_key int(11) NOT NULL auto_increment,
344
PRIMARY KEY (dummy_primary_key)
346
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
347
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
348
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','23:06:59','2000-09-07 23:06:59',3);
349
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','23:06:59','2000-09-07 23:06:59',4);
350
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
351
select user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
355
# Testing of tables without primary keys
359
id int(11) NOT NULL auto_increment,
360
parent_id int(11) DEFAULT '0' NOT NULL,
361
level tinyint(4) DEFAULT '0' NOT NULL,
363
KEY parent_id (parent_id),
366
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);
367
INSERT INTO t1 values (179,5,2);
368
update t1 set parent_id=parent_id+100;
369
select * from t1 where parent_id=102;
370
update t1 set id=id+1000;
371
update t1 set id=1024 where id=1009;
373
update ignore t1 set id=id+1; # This will change all rows
375
update ignore t1 set id=1023 where id=1010;
376
select * from t1 where parent_id=102;
378
explain select level from t1 where level=1;
379
select level,id from t1 where level=1;
380
select level,id,parent_id from t1 where level=1;
381
select level,id from t1 where level=1 order by id;
382
delete from t1 where level=1;
387
# Test of index only reads
390
sca_code char(6) NOT NULL,
391
cat_code char(6) NOT NULL,
392
sca_desc varchar(50),
393
lan_code char(2) NOT NULL,
394
sca_pic varchar(100),
395
sca_sdesc varchar(50),
396
sca_sch_desc varchar(16),
397
PRIMARY KEY (sca_code, cat_code, lan_code),
398
INDEX sca_pic (sca_pic)
401
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');
402
select count(*) from t1 where sca_code = 'PD';
403
select count(*) from t1 where sca_code <= 'PD';
404
select count(*) from t1 where sca_pic is null;
405
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
406
select count(*) from t1 where sca_code='PD' and sca_pic is null;
407
select count(*) from t1 where cat_code='E';
409
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
410
select count(*) from t1 where sca_code='PD' and sca_pic is null;
411
select count(*) from t1 where sca_pic >= 'n';
412
select sca_pic from t1 where sca_pic is null;
413
update t1 set sca_pic="test" where sca_pic is null;
414
delete from t1 where sca_code='pd';
418
# Test of opening table twice and timestamps
421
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
422
insert into t1 (a) values(1),(2),(3);
423
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
424
select a from t1 natural join t1 as t2 where b >= @a order by a;
425
update t1 set a=5 where a=1;
430
# Test with variable length primary key
432
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
433
insert into t1 values("hello",1),("world",2);
434
select * from t1 order by b desc;
441
# Test of create index with NULL columns
443
create table t1 (i int, j int ) ENGINE=innodb;
444
insert into t1 values (1,2);
445
select * from t1 where i=1 and j=2;
446
create index ax1 on t1 (i,j);
447
select * from t1 where i=1 and j=2;
451
# Test min-max optimization
455
a int3 unsigned NOT NULL,
456
b int1 unsigned NOT NULL,
460
INSERT INTO t1 VALUES (1, 1);
461
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
465
# Test INSERT DELAYED
468
CREATE TABLE t1 (a int unsigned NOT NULL) engine=innodb;
469
# Can't test this in 3.23
470
# INSERT DELAYED INTO t1 VALUES (1);
471
INSERT INTO t1 VALUES (1);
477
# Crash when using many tables (Test case by Jeremy D Zawodny)
480
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;
481
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);
483
explain select * from t1 where a > 0 and a < 50;
490
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
491
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
492
LOCK TABLES t1 WRITE;
494
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
500
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
501
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
502
LOCK TABLES t1 WRITE;
505
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
507
insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
509
select id,id3 from t1;
516
create table t1 (a char(20), unique (a(5))) engine=innodb;
518
create table t1 (a char(20), index (a(5))) engine=innodb;
519
show create table t1;
523
# Test using temporary table and auto_increment
526
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
527
insert into t1 values (NULL),(NULL),(NULL);
528
delete from t1 where a=3;
529
insert into t1 values (NULL);
531
alter table t1 add b int;
538
id int auto_increment primary key,
539
name varchar(32) not null,
544
insert into t1 values (1,'one','one value',101),
545
(2,'two','two value',102),(3,'three','three value',103);
547
replace into t1 (value,name,uid) values ('other value','two',102);
548
delete from t1 where uid=102;
550
replace into t1 (value,name,uid) values ('other value','two',102);
552
replace into t1 (value,name,uid) values ('other value','two',102);
560
create database mysqltest;
561
create table mysqltest.t1 (a int not null) engine= innodb;
562
insert into mysqltest.t1 values(1);
563
create table mysqltest.t2 (a int not null) engine= myisam;
564
insert into mysqltest.t2 values(1);
565
create table mysqltest.t3 (a int not null) engine= heap;
566
insert into mysqltest.t3 values(1);
568
drop database mysqltest;
569
# Don't check error message
571
show tables from mysqltest;
574
# Test truncate table with and without auto_commit
578
create table t1 (a int not null) engine= innodb;
579
insert into t1 values(1),(2);
585
insert into t1 values(1),(2);
592
create table t1 (a int not null) engine= innodb;
593
insert into t1 values(1),(2);
595
insert into t1 values(1),(2);
598
insert into t1 values(1),(2);
604
# Test of how ORDER BY works when doing it on the whole table
607
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
608
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
610
explain select * from t1 order by a;
612
explain select * from t1 order by b;
614
explain select * from t1 order by c;
616
explain select a from t1 order by a;
618
explain select b from t1 order by b;
620
explain select a,b from t1 order by b;
622
explain select a,b from t1;
624
explain select a,b,c from t1;
631
create table t1 (t int not null default 1, key (t)) engine=innodb;
636
# Test of multi-table-delete
640
number bigint(20) NOT NULL default '0',
641
cname char(15) NOT NULL default '',
642
carrier_id smallint(6) NOT NULL default '0',
643
privacy tinyint(4) NOT NULL default '0',
644
last_mod_date timestamp NOT NULL,
645
last_mod_id smallint(6) NOT NULL default '0',
646
last_app_date timestamp NOT NULL,
647
last_app_id smallint(6) default '-1',
648
version smallint(6) NOT NULL default '0',
649
assigned_scps int(11) default '0',
650
status tinyint(4) default '0'
652
INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
653
INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
654
INSERT INTO t1 VALUES (650,'San Francisco',0,0,20011227111336,342,00000000000000,-1,1,24,1);
655
INSERT INTO t1 VALUES (302467,'Sue\'s Subshop',90,3,20020109113241,500,20020102115111,501,7,24,0);
656
INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
657
INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
659
number bigint(20) NOT NULL default '0',
660
cname char(15) NOT NULL default '',
661
carrier_id smallint(6) NOT NULL default '0',
662
privacy tinyint(4) NOT NULL default '0',
663
last_mod_date timestamp NOT NULL,
664
last_mod_id smallint(6) NOT NULL default '0',
665
last_app_date timestamp NOT NULL,
666
last_app_id smallint(6) default '-1',
667
version smallint(6) NOT NULL default '0',
668
assigned_scps int(11) default '0',
669
status tinyint(4) default '0'
671
INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
672
INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
673
INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,00000000000000,-1,1,24,1);
674
INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
677
delete t1, t2 from t1 left join t2 on t1.number=t2.number where (t1.carrier_id=90 and t1.number=t2.number) or (t2.carrier_id=90 and t1.number=t2.number) or (t1.carrier_id=90 and t2.number is null);
684
# A simple test with some isolation levels
685
# TODO: Make this into a test using replication to really test how
689
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
692
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
693
SELECT @@tx_isolation,@@global.tx_isolation;
694
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
695
select id, code, name from t1 order by id;
699
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
700
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
701
select id, code, name from t1 order by id;
705
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
706
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
707
select id, code, name from t1 order by id;
712
# Test of multi-table-update
714
create table t1 (n int(10), d int(10)) engine=innodb;
715
create table t2 (n int(10), d int(10)) engine=innodb;
716
insert into t1 values(1,1),(1,2);
717
insert into t2 values(1,10),(2,20);
718
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
724
# Bug #29136 erred multi-delete on trans table does not rollback
729
drop table if exists t1, t2;
731
CREATE TABLE t1 (a int, PRIMARY KEY (a));
732
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
733
create trigger trg_del_t2 after delete on t2 for each row
734
insert into t1 values (1);
735
insert into t1 values (1);
736
insert into t2 values (1),(2);
739
# exec cases A, B - see multi_update.test
741
# A. send_error() w/o send_eof() branch
748
select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
756
# Bug #29136 erred multi-delete on trans table does not rollback
761
drop table if exists t1, t2;
763
CREATE TABLE t1 (a int, PRIMARY KEY (a));
764
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
765
create trigger trg_del_t2 after delete on t2 for each row
766
insert into t1 values (1);
767
insert into t1 values (1);
768
insert into t2 values (1),(2);
771
# exec cases A, B - see multi_update.test
773
# A. send_error() w/o send_eof() branch
780
select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
790
create table t1 (a int, b int) engine=innodb;
791
insert into t1 values(20,null);
792
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
794
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
795
t2.b=t3.a order by 1;
796
insert into t1 values(10,null);
797
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
798
t2.b=t3.a order by 1;
802
# Test of read_through not existing const_table
805
create table t1 (a varchar(10) not null) engine=myisam;
806
create table t2 (b varchar(10) not null unique) engine=innodb;
807
select t1.a from t1,t2 where t1.a=t2.b;
809
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
810
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
811
insert into t1 values (10, 20);
812
insert into t2 values (10, 20);
813
update t1, t2 set t1.b = 150, t2.b = t1.b where t2.a = t1.a and t1.a = 10;
817
# Test of multi-table-delete with foreign key constraints
820
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
821
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;
822
insert into t1 set id=1;
823
insert into t2 set id=1, t1_id=1;
824
delete t1,t2 from t1,t2 where t1.id=t2.t1_id;
828
CREATE TABLE t1(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
829
CREATE TABLE t2(id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id) ) ENGINE=INNODB;
830
INSERT INTO t1 VALUES(1);
831
INSERT INTO t2 VALUES(1, 1);
833
UPDATE t1,t2 SET t1.id=t1.id+1, t2.t1_id=t1.id+1;
835
UPDATE t1,t2 SET t1.id=t1.id+1 where t1.id!=t2.id;
840
# Test of range_optimizer
845
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
847
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
849
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
851
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
854
INSERT INTO t1 VALUES("this-key", "will disappear");
855
INSERT INTO t2 VALUES("this-key", "will also disappear");
856
DELETE FROM t3 WHERE id1="my-test-1";
866
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
872
# Check update with conflicting key
875
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
876
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
877
# We need the a < 1000 test here to quard against the halloween problems
878
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
883
# Test multi update with different join methods
886
CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) engine=innodb;
887
CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) engine=innodb;
888
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);
889
INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
891
# Full join, without key
892
update t1,t2 set t1.a=t1.a+100;
896
update t1,t2 set t1.a=t1.a+100 where t1.a=101;
900
update t1,t2 set t1.b=t1.b+10 where t1.b=2;
904
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;
909
CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) ENGINE=MyISAM;
910
CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB;
912
INSERT INTO t1 ( B_ID ) VALUES ( 1 );
913
INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );
917
create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) engine = innodb;
918
insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2);
919
select distinct parent,child from t1 order by parent;
923
# Test that MySQL priorities clustered indexes
925
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
926
create table t2 (a int not null auto_increment primary key, b int);
927
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
928
insert into t2 (a) select b from t1;
929
insert into t1 (b) select b from t2;
930
insert into t2 (a) select b from t1;
931
insert into t1 (a) select b from t2;
932
insert into t2 (a) select b from t1;
933
insert into t1 (a) select b from t2;
934
insert into t2 (a) select b from t1;
935
insert into t1 (a) select b from t2;
936
insert into t2 (a) select b from t1;
937
insert into t1 (a) select b from t2;
938
select count(*) from t1;
940
explain select * from t1 where c between 1 and 2500;
943
explain select * from t1 where c between 1 and 2500;
947
# Test of UPDATE ... ORDER BY
950
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
952
insert into t1 (id) values (null),(null),(null),(null),(null);
953
update t1 set fk=69 where fk is null order by id limit 1;
957
create table t1 (a int not null, b int not null, key (a));
958
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);
960
update t1 set b=(@tmp:=@tmp+1) order by a;
961
update t1 set b=99 where a=1 order by b asc limit 1;
962
update t1 set b=100 where a=1 order by b desc limit 2;
963
update t1 set a=a+10+b where a=1 order by b;
964
select * from t1 order by a,b;
968
# Test of multi-table-updates (bug #1980).
971
create table t1 ( c char(8) not null ) engine=innodb;
972
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
973
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
975
alter table t1 add b char(8) not null;
976
alter table t1 add a char(8) not null;
977
alter table t1 add primary key (a,b,c);
978
update t1 set a=c, b=c;
980
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;
981
insert into t2 select * from t1;
983
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
987
# test autoincrement with TRUNCATE
991
create table t1 (a integer auto_increment primary key) engine=innodb;
992
insert into t1 (a) values (NULL),(NULL);
994
insert into t1 (a) values (NULL),(NULL);
999
# Test dictionary handling with spaceand quoting
1002
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
1003
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;
1004
#show create table t2;
1008
# Test of multi updated and foreign keys
1011
create table `t1` (`id` int( 11 ) not null ,primary key ( `id` )) engine = innodb;
1012
insert into `t1`values ( 1 ) ;
1013
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;
1014
insert into `t2`values ( 1 ) ;
1015
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;
1016
insert into `t3`values ( 1 ) ;
1018
delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
1020
update 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;
1022
update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
1023
drop table t3,t2,t1;
1026
# test for recursion depth limit
1032
foreign key(pid) references t1(id) on delete cascade) engine=innodb;
1033
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
1034
(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
1036
delete from t1 where id=0;
1037
delete from t1 where id=15;
1038
delete from t1 where id=0;
1046
CREATE TABLE t1 (col1 int(1))ENGINE=InnoDB;
1047
CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx
1048
(stamp))ENGINE=InnoDB;
1049
insert into t1 values (1),(2),(3);
1050
# Note that timestamp 3 is wrong
1051
insert into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);
1052
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
1053
'20020204120000' GROUP BY col1;
1057
# Test by Francois MASUREL
1061
`id` int(10) unsigned NOT NULL auto_increment,
1062
`id_object` int(10) unsigned default '0',
1063
`id_version` int(10) unsigned NOT NULL default '1',
1064
`label` varchar(100) NOT NULL default '',
1067
KEY `id_object` (`id_object`),
1068
KEY `id_version` (`id_version`)
1071
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);
1074
`id` int(10) unsigned NOT NULL auto_increment,
1075
`id_version` int(10) unsigned NOT NULL default '1',
1077
KEY `id_version` (`id_version`)
1080
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
1082
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
1083
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
1084
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
1087
create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=myisam;
1088
create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=innodb;
1089
create table t3 (a int, b varchar(200), c text not null) checksum=1 engine=innodb;
1090
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
1091
insert t2 select * from t1;
1092
insert t3 select * from t1;
1093
checksum table t1, t2, t3, t4 quick;
1094
checksum table t1, t2, t3, t4;
1095
checksum table t1, t2, t3, t4 extended;
1097
drop table t1,t2,t3;
1100
# Test problem with refering to different fields in same table in UNION
1103
create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
1104
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
1105
select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
1111
create table t1 (a int) engine=innodb;
1112
create table t2 like t1;
1116
# Test of automaticly created foreign keys
1119
create table t1 (id int(11) not null, id2 int(11) not null, unique (id,id2)) engine=innodb;
1120
create table t2 (id int(11) not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
1121
show create table t1;
1122
show create table t2;
1123
create index id on t2 (id);
1124
show create table t2;
1125
create index id2 on t2 (id);
1126
show create table t2;
1127
drop index id2 on t2;
1128
--error ER_DROP_INDEX_FK
1129
drop index id on t2;
1130
show create table t2;
1133
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;
1134
show create table t2;
1135
create unique index id on t2 (id,id2);
1136
show create table t2;
1139
# Check foreign key columns created in different order than key columns
1140
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;
1141
show create table t2;
1144
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;
1145
show create table t2;
1148
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;
1149
show create table t2;
1152
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;
1153
show create table t2;
1156
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;
1157
show create table t2;
1158
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1159
show create table t2;
1162
# Test error handling
1164
# Embedded server doesn't chdir to data directory
1165
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1166
--error ER_WRONG_FK_DEF
1167
create 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;
1171
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
1172
show create table t2;
1174
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;
1175
show create table t2;
1180
# Bug #6126: Duplicate columns in keys gives misleading error message
1183
create table t1 (c char(10), index (c,c)) engine=innodb;
1185
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
1187
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
1189
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
1190
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
1192
alter table t1 add key (c1,c1);
1194
alter table t1 add key (c2,c1,c1);
1196
alter table t1 add key (c1,c2,c1);
1198
alter table t1 add key (c1,c1,c2);
1202
# Bug #4082: integer truncation
1205
create table t1(a int(1) , b int(1)) engine=innodb;
1206
insert into t1 values ('1111', '3333');
1207
select distinct concat(a, b) from t1;
1211
# BUG#7709 test case - Boolean fulltext query against unsupported
1212
# engines does not fail
1215
CREATE TABLE t1 ( a char(10) ) ENGINE=InnoDB;
1217
SELECT a FROM t1 WHERE MATCH (a) AGAINST ('test' IN BOOLEAN MODE);
1221
# check null values #1
1225
CREATE TABLE t1 (a_id tinyint(4) NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
1226
INSERT INTO t1 VALUES (1),(2),(3);
1227
CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
1228
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=latin1;
1230
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
1231
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;
1236
# Bug#11816 - Truncate table doesn't work with temporary innodb tables
1237
# This is not an innodb bug, but we test it using innodb.
1239
create temporary table t1 (a int) engine=innodb;
1240
insert into t1 values (4711);
1242
insert into t1 values (42);
1245
# Show that it works with permanent tables too.
1246
create table t1 (a int) engine=innodb;
1247
insert into t1 values (4711);
1249
insert into t1 values (42);
1254
# Bug #13025 Server crash during filesort
1257
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;
1258
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
1259
select * from t1 order by a,b,c,d;
1260
explain select * from t1 order by a,b,c,d;
1264
# BUG#11039,#13218 Wrong key length in min()
1267
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1268
insert into t1 values ('8', '6'), ('4', '7');
1269
select min(a) from t1;
1270
select min(b) from t1 where a='8';
1276
# range optimizer problem
1279
create table t1 (x bigint unsigned not null primary key) engine=innodb;
1280
insert into t1(x) values (0xfffffffffffffff0),(0xfffffffffffffff1);
1282
select count(*) from t1 where x>0;
1283
select count(*) from t1 where x=0;
1284
select count(*) from t1 where x<0;
1285
select count(*) from t1 where x < -16;
1286
select count(*) from t1 where x = -16;
1287
explain select count(*) from t1 where x > -16;
1288
select count(*) from t1 where x > -16;
1289
select * from t1 where x > -16;
1290
select count(*) from t1 where x = 18446744073709551601;
1294
# Test for testable InnoDB status variables. This test
1295
# uses previous ones(pages_created, rows_deleted, ...).
1296
--replace_result 512 511
1297
show status like "Innodb_buffer_pool_pages_total";
1298
show status like "Innodb_page_size";
1299
show status like "Innodb_rows_deleted";
1300
show status like "Innodb_rows_inserted";
1301
show status like "Innodb_rows_updated";
1303
# Test for row locks InnoDB status variables.
1304
show status like "Innodb_row_lock_waits";
1305
show status like "Innodb_row_lock_current_waits";
1306
show status like "Innodb_row_lock_time";
1307
show status like "Innodb_row_lock_time_max";
1308
show status like "Innodb_row_lock_time_avg";
1310
# Test for innodb_sync_spin_loops variable
1311
show variables like "innodb_sync_spin_loops";
1312
set global innodb_sync_spin_loops=1000;
1313
show variables like "innodb_sync_spin_loops";
1314
set global innodb_sync_spin_loops=0;
1315
show variables like "innodb_sync_spin_loops";
1316
set global innodb_sync_spin_loops=20;
1317
show variables like "innodb_sync_spin_loops";
1319
# Test for innodb_thread_concurrency variable
1320
show variables like "innodb_thread_concurrency";
1321
set global innodb_thread_concurrency=1001;
1322
show variables like "innodb_thread_concurrency";
1323
set global innodb_thread_concurrency=0;
1324
show variables like "innodb_thread_concurrency";
1325
set global innodb_thread_concurrency=16;
1326
show variables like "innodb_thread_concurrency";
1328
# Test for innodb_concurrency_tickets variable
1329
show variables like "innodb_concurrency_tickets";
1330
set global innodb_concurrency_tickets=1000;
1331
show variables like "innodb_concurrency_tickets";
1332
set global innodb_concurrency_tickets=0;
1333
show variables like "innodb_concurrency_tickets";
1334
set global innodb_concurrency_tickets=500;
1335
show variables like "innodb_concurrency_tickets";
1337
# Test for innodb_thread_sleep_delay variable
1338
show variables like "innodb_thread_sleep_delay";
1339
set global innodb_thread_sleep_delay=100000;
1340
show variables like "innodb_thread_sleep_delay";
1341
set global innodb_thread_sleep_delay=0;
1342
show variables like "innodb_thread_sleep_delay";
1343
set global innodb_thread_sleep_delay=10000;
1344
show variables like "innodb_thread_sleep_delay";
1350
let $default=`select @@storage_engine`;
1351
set storage_engine=INNODB;
1352
source include/varchar.inc;
1355
# Some errors/warnings on create
1358
# Embedded server doesn't chdir to data directory
1359
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1360
create table t1 (v varchar(65530), key(v));
1362
create table t1 (v varchar(65536));
1363
show create table t1;
1365
create table t1 (v varchar(65530) character set utf8);
1366
show create table t1;
1369
eval set storage_engine=$default;
1371
# InnoDB specific varchar tests
1372
create table t1 (v varchar(16384)) engine=innodb;
1376
# BUG#11039 Wrong key length in min()
1379
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1380
insert into t1 values ('8', '6'), ('4', '7');
1381
select min(a) from t1;
1382
select min(b) from t1 where a='8';
1386
# Bug #11080 & #11005 Multi-row REPLACE fails on a duplicate key error
1389
CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
1390
insert into t1 (b) values (1);
1391
replace into t1 (b) values (2), (1), (3);
1394
insert into t1 (b) values (1);
1395
replace into t1 (b) values (2);
1396
replace into t1 (b) values (1);
1397
replace into t1 (b) values (3);
1401
create table t1 (rowid int not null auto_increment, val int not null,primary
1402
key (rowid), unique(val)) engine=innodb;
1403
replace into t1 (val) values ('1'),('2');
1404
replace into t1 (val) values ('1'),('2');
1405
--error ER_DUP_ENTRY
1406
insert into t1 (val) values ('1'),('2');
1411
# Test that update does not change internal auto-increment value
1414
create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
1415
insert into t1 (val) values (1);
1416
update t1 set a=2 where a=1;
1417
# We should get the following error because InnoDB does not update the counter
1418
--error ER_DUP_ENTRY
1419
insert into t1 (val) values (1);
1427
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
1429
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
1430
SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300;
1431
SELECT GRADE FROM t1 WHERE GRADE= 151;
1435
# Bug #12340 multitable delete deletes only one record
1437
create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb;
1438
create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb;
1439
insert into t2 values ('aa','cc');
1440
insert into t1 values ('aa','bb'),('aa','cc');
1441
delete t1 from t1,t2 where f1=f3 and f4='cc';
1446
# Test that the slow TRUNCATE implementation resets autoincrement columns
1451
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
1455
id INTEGER NOT NULL,
1456
FOREIGN KEY (id) REFERENCES t1 (id)
1459
INSERT INTO t1 (id) VALUES (NULL);
1462
INSERT INTO t1 (id) VALUES (NULL);
1465
# continued from above; test that doing a slow TRUNCATE on a table with 0
1466
# rows resets autoincrement columns
1469
INSERT INTO t1 (id) VALUES (NULL);
1473
# Test that foreign keys in temporary tables are not accepted (bug #12084)
1480
CREATE TEMPORARY TABLE t2
1482
id INT NOT NULL PRIMARY KEY,
1484
FOREIGN KEY (b) REFERENCES test.t1(id)
1489
# Test that index column max sizes are honored (bug #13315)
1493
create table t1 (col1 varchar(2000), index (col1(767)))
1494
character set = latin1 engine = innodb;
1497
create table t2 (col1 char(255), index (col1))
1498
character set = latin1 engine = innodb;
1499
create table t3 (col1 binary(255), index (col1))
1500
character set = latin1 engine = innodb;
1501
create table t4 (col1 varchar(767), index (col1))
1502
character set = latin1 engine = innodb;
1503
create table t5 (col1 varchar(767) primary key)
1504
character set = latin1 engine = innodb;
1505
create table t6 (col1 varbinary(767) primary key)
1506
character set = latin1 engine = innodb;
1507
create table t7 (col1 text, index(col1(767)))
1508
character set = latin1 engine = innodb;
1509
create table t8 (col1 blob, index(col1(767)))
1510
character set = latin1 engine = innodb;
1512
# multi-column indexes are allowed to be longer
1513
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
1514
character set = latin1 engine = innodb;
1516
show create table t9;
1518
drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
1520
# these should have their index length trimmed
1521
create table t1 (col1 varchar(768), index(col1))
1522
character set = latin1 engine = innodb;
1523
create table t2 (col1 varbinary(768), index(col1))
1524
character set = latin1 engine = innodb;
1525
create table t3 (col1 text, index(col1(768)))
1526
character set = latin1 engine = innodb;
1527
create table t4 (col1 blob, index(col1(768)))
1528
character set = latin1 engine = innodb;
1530
show create table t1;
1532
drop table t1, t2, t3, t4;
1534
# these should be refused
1536
create table t1 (col1 varchar(768) primary key)
1537
character set = latin1 engine = innodb;
1539
create table t2 (col1 varbinary(768) primary key)
1540
character set = latin1 engine = innodb;
1542
create table t3 (col1 text, primary key(col1(768)))
1543
character set = latin1 engine = innodb;
1545
create table t4 (col1 blob, primary key(col1(768)))
1546
character set = latin1 engine = innodb;
1549
# Test improved foreign key error messages (bug #3443)
1560
CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
1564
INSERT INTO t2 VALUES(2);
1566
INSERT INTO t1 VALUES(1);
1567
INSERT INTO t2 VALUES(1);
1570
DELETE FROM t1 WHERE id = 1;
1575
SET FOREIGN_KEY_CHECKS=0;
1577
SET FOREIGN_KEY_CHECKS=1;
1580
INSERT INTO t2 VALUES(3);
1584
# Test that checksum table uses a consistent read Bug #12669
1586
connect (a,localhost,root,,);
1587
connect (b,localhost,root,,);
1589
create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
1590
insert into t1 values (1),(2);
1594
insert into t1 values(3);
1597
# Here checksum should not see insert
1609
create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
1610
insert into t1 values (1),(2);
1615
insert into t1 values(3);
1618
# Here checksum sees insert
1627
# tests for bugs #9802 and #13778
1629
# test that FKs between invalid types are not accepted
1631
set foreign_key_checks=0;
1632
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
1633
# Embedded server doesn't chdir to data directory
1634
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1636
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
1637
set foreign_key_checks=1;
1640
# test that FKs between different charsets are not accepted in CREATE even
1643
set foreign_key_checks=0;
1644
create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
1645
# Embedded server doesn't chdir to data directory
1646
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1648
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=utf8;
1649
set foreign_key_checks=1;
1652
# test that invalid datatype conversions with ALTER are not allowed
1654
set foreign_key_checks=0;
1655
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
1656
create table t1(a varchar(10) primary key) engine = innodb;
1658
alter table t1 modify column a int;
1659
set foreign_key_checks=1;
1662
# test that charset conversions with ALTER are allowed when f_k_c is 0
1664
set foreign_key_checks=0;
1665
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
1666
create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
1667
alter table t1 convert to character set utf8;
1668
set foreign_key_checks=1;
1671
# test that RENAME does not allow invalid charsets when f_k_c is 0
1673
set foreign_key_checks=0;
1674
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
1675
create table t3(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=utf8;
1676
# Embedded server doesn't chdir to data directory
1677
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1679
rename table t3 to t1;
1680
set foreign_key_checks=1;
1683
# test that foreign key errors are reported correctly (Bug #15550)
1685
create table t1(a int primary key) row_format=redundant engine=innodb;
1686
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
1687
create table t3(a int primary key) row_format=compact engine=innodb;
1688
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
1690
insert into t1 values(1);
1691
insert into t3 values(1);
1693
insert into t2 values(2);
1695
insert into t4 values(2);
1696
insert into t2 values(1);
1697
insert into t4 values(1);
1715
drop table t4,t3,t2,t1;
1719
# Test that we can create a large (>1K) key
1721
create table t1 (a varchar(255) character set utf8,
1722
b varchar(255) character set utf8,
1723
c varchar(255) character set utf8,
1724
d varchar(255) character set utf8,
1725
key (a,b,c,d)) engine=innodb;
1727
--error ER_TOO_LONG_KEY
1728
create table t1 (a varchar(255) character set utf8,
1729
b varchar(255) character set utf8,
1730
c varchar(255) character set utf8,
1731
d varchar(255) character set utf8,
1732
e varchar(255) character set utf8,
1733
key (a,b,c,d,e)) engine=innodb;
1736
# test the padding of BINARY types and collations (Bug #14189)
1738
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
1739
create table t2 (s1 binary(2),primary key (s1)) engine=innodb;
1740
create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb;
1741
create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb;
1743
insert into t1 values (0x41),(0x4120),(0x4100);
1744
-- error ER_DUP_ENTRY
1745
insert into t2 values (0x41),(0x4120),(0x4100);
1746
insert into t2 values (0x41),(0x4120);
1747
-- error ER_DUP_ENTRY
1748
insert into t3 values (0x41),(0x4120),(0x4100);
1749
insert into t3 values (0x41),(0x4100);
1750
-- error ER_DUP_ENTRY
1751
insert into t4 values (0x41),(0x4120),(0x4100);
1752
insert into t4 values (0x41),(0x4100);
1753
select hex(s1) from t1;
1754
select hex(s1) from t2;
1755
select hex(s1) from t3;
1756
select hex(s1) from t4;
1757
drop table t1,t2,t3,t4;
1759
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
1760
create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
1762
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
1764
insert into t2 values(0x42);
1765
insert into t2 values(0x41);
1766
select hex(s1) from t2;
1767
update t1 set s1=0x123456 where a=2;
1768
select hex(s1) from t2;
1770
update t1 set s1=0x12 where a=1;
1772
update t1 set s1=0x12345678 where a=1;
1774
update t1 set s1=0x123457 where a=1;
1775
update t1 set s1=0x1220 where a=1;
1776
select hex(s1) from t2;
1777
update t1 set s1=0x1200 where a=1;
1778
select hex(s1) from t2;
1779
update t1 set s1=0x4200 where a=1;
1780
select hex(s1) from t2;
1782
delete from t1 where a=1;
1783
delete from t1 where a=2;
1784
update t2 set s1=0x4120;
1787
delete from t1 where a!=3;
1788
select a,hex(s1) from t1;
1789
select hex(s1) from t2;
1793
create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=innodb;
1794
create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
1796
insert into t1 values(1,0x4100),(2,0x41);
1797
insert into t2 values(0x41);
1798
select hex(s1) from t2;
1799
update t1 set s1=0x1234 where a=1;
1800
select hex(s1) from t2;
1801
update t1 set s1=0x12 where a=2;
1802
select hex(s1) from t2;
1803
delete from t1 where a=1;
1805
delete from t1 where a=2;
1806
select a,hex(s1) from t1;
1807
select hex(s1) from t2;
1810
# Ensure that <tablename>_ibfk_0 is not mistreated as a
1811
# generated foreign key identifier. (Bug #16387)
1813
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
1814
CREATE TABLE t2(a INT) ENGINE=InnoDB;
1815
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
1816
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
1817
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
1818
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
1819
SHOW CREATE TABLE t2;
1823
# Test case for bug #16229: MySQL/InnoDB uses full explicit table locks in trigger processing
1826
connect (a,localhost,root,,);
1827
connect (b,localhost,root,,);
1829
create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1830
insert into t1(a) values (1),(2),(3);
1834
update t1 set b = 5 where a = 2;
1837
create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
1841
insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
1842
(11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
1843
(12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
1844
(13),(23),(33),(43),(53),(63),(73),(83),(93),(103),
1845
(14),(24),(34),(44),(54),(64),(74),(84),(94),(104);
1855
# Another trigger test
1857
connect (a,localhost,root,,);
1858
connect (b,localhost,root,,);
1860
create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1861
create table t2(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1862
create table t3(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1863
create table t4(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1864
create table t5(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1865
insert into t1(a) values (1),(2),(3);
1866
insert into t2(a) values (1),(2),(3);
1867
insert into t3(a) values (1),(2),(3);
1868
insert into t4(a) values (1),(2),(3);
1869
insert into t3(a) values (5),(7),(8);
1870
insert into t4(a) values (5),(7),(8);
1871
insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
1874
create trigger t1t before insert on t1 for each row begin
1875
INSERT INTO t2 SET a = NEW.a;
1878
create trigger t2t before insert on t2 for each row begin
1879
DELETE FROM t3 WHERE a = NEW.a;
1882
create trigger t3t before delete on t3 for each row begin
1883
UPDATE t4 SET b = b + 1 WHERE a = OLD.a;
1886
create trigger t4t before update on t4 for each row begin
1887
UPDATE t5 SET b = b + 1 where a = NEW.a;
1892
update t1 set b = b + 5 where a = 1;
1893
update t2 set b = b + 5 where a = 1;
1894
update t3 set b = b + 5 where a = 1;
1895
update t4 set b = b + 5 where a = 1;
1896
insert into t5(a) values(20);
1899
insert into t1(a) values(7);
1900
insert into t2(a) values(8);
1901
delete from t2 where a = 3;
1902
update t4 set b = b + 1 where a = 3;
1908
drop table t1, t2, t3, t4, t5;
1914
# Test that cascading updates leading to duplicate keys give the correct
1915
# error message (bug #9680)
1919
field1 varchar(8) NOT NULL DEFAULT '',
1920
field2 varchar(8) NOT NULL DEFAULT '',
1921
PRIMARY KEY (field1, field2)
1925
field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
1926
FOREIGN KEY (field1) REFERENCES t1 (field1)
1927
ON DELETE CASCADE ON UPDATE CASCADE
1930
INSERT INTO t1 VALUES ('old', 'somevalu');
1931
INSERT INTO t1 VALUES ('other', 'anyvalue');
1933
INSERT INTO t2 VALUES ('old');
1934
INSERT INTO t2 VALUES ('other');
1936
--error ER_FOREIGN_DUPLICATE_KEY
1937
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
1943
# Bug#18477 - MySQL/InnoDB Ignoring Foreign Keys in ALTER TABLE
1957
alter table t1 add constraint c2_fk foreign key (c2)
1958
references t2(c1) on delete cascade;
1959
show create table t1;
1961
alter table t1 drop foreign key c2_fk;
1962
show create table t1;
1967
# Bug #14360: problem with intervals
1970
create table t1(a date) engine=innodb;
1971
create table t2(a date, key(a)) engine=innodb;
1972
insert into t1 values('2005-10-01');
1973
insert into t2 values('2005-10-01');
1974
select * from t1, t2
1975
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
1978
create table t1 (id int not null, f_id int not null, f int not null,
1979
primary key(f_id, id)) engine=innodb;
1980
create table t2 (id int not null,s_id int not null,s varchar(200),
1981
primary key(id)) engine=innodb;
1982
INSERT INTO t1 VALUES (8, 1, 3);
1983
INSERT INTO t1 VALUES (1, 2, 1);
1984
INSERT INTO t2 VALUES (1, 0, '');
1985
INSERT INTO t2 VALUES (8, 1, '');
1987
DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
1988
WHERE mm.id IS NULL;
1989
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
1990
where mm.id is null lock in share mode;
1994
# Test case where X-locks on unused rows should be released in a
1995
# update (because READ COMMITTED isolation level)
1998
connect (a,localhost,root,,);
1999
connect (b,localhost,root,,);
2001
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2002
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
2005
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2006
update t1 set b = 5 where b = 1;
2009
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2011
# X-lock to record (7,3) should be released in a update
2013
select * from t1 where a = 7 and b = 3 for update;
2024
# Test case where no locks should be released (because we are not
2025
# using READ COMMITTED isolation level)
2028
connect (a,localhost,root,,);
2029
connect (b,localhost,root,,);
2031
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2032
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
2035
select * from t1 lock in share mode;
2036
update t1 set b = 5 where b = 1;
2040
# S-lock to records (2,2),(4,2), and (6,2) should not be released in a update
2043
select * from t1 where a = 2 and b = 2 for update;
2045
# X-lock to record (1,1),(3,1),(5,1) should not be released in a update
2058
# Consistent read should be used in following selects
2060
# 1) INSERT INTO ... SELECT
2061
# 2) UPDATE ... = ( SELECT ...)
2062
# 3) CREATE ... SELECT
2064
connect (a,localhost,root,,);
2065
connect (b,localhost,root,,);
2067
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2068
insert into t1 values (1,2),(5,3),(4,2);
2069
create table t2(d int not null, e int, primary key(d)) engine=innodb;
2070
insert into t2 values (8,6),(12,1),(3,1);
2073
select * from t2 for update;
2076
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2077
insert into t1 select * from t2;
2078
update t1 set b = (select e from t2 where a = d);
2079
create table t3(d int not null, e int, primary key(d)) engine=innodb
2087
drop table t1, t2, t3;
2090
# Consistent read should not be used if
2092
# (a) isolation level is serializable OR
2093
# (b) select ... lock in share mode OR
2094
# (c) select ... for update
2096
# in following queries:
2098
# 1) INSERT INTO ... SELECT
2099
# 2) UPDATE ... = ( SELECT ...)
2100
# 3) CREATE ... SELECT
2102
connect (a,localhost,root,,);
2103
connect (b,localhost,root,,);
2104
connect (c,localhost,root,,);
2105
connect (d,localhost,root,,);
2106
connect (e,localhost,root,,);
2107
connect (f,localhost,root,,);
2108
connect (g,localhost,root,,);
2109
connect (h,localhost,root,,);
2110
connect (i,localhost,root,,);
2111
connect (j,localhost,root,,);
2113
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2114
insert into t1 values (1,2),(5,3),(4,2);
2115
create table t2(a int not null, b int, primary key(a)) engine=innodb;
2116
insert into t2 values (8,6),(12,1),(3,1);
2117
create table t3(d int not null, b int, primary key(d)) engine=innodb;
2118
insert into t3 values (8,6),(12,1),(3,1);
2119
create table t5(a int not null, b int, primary key(a)) engine=innodb;
2120
insert into t5 values (1,2),(5,3),(4,2);
2121
create table t6(d int not null, e int, primary key(d)) engine=innodb;
2122
insert into t6 values (8,6),(12,1),(3,1);
2123
create table t8(a int not null, b int, primary key(a)) engine=innodb;
2124
insert into t8 values (1,2),(5,3),(4,2);
2125
create table t9(d int not null, e int, primary key(d)) engine=innodb;
2126
insert into t9 values (8,6),(12,1),(3,1);
2129
select * from t2 for update;
2132
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2134
insert into t1 select * from t2;
2137
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2139
update t3 set b = (select b from t2 where a = d);
2142
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2144
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
2147
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2149
insert into t5 (select * from t2 lock in share mode);
2152
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2154
update t6 set e = (select b from t2 where a = d lock in share mode);
2157
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2159
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
2162
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2164
insert into t8 (select * from t2 for update);
2167
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2169
update t9 set e = (select b from t2 where a = d for update);
2172
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2174
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
2226
drop table t1, t2, t3, t5, t6, t8, t9;
2228
# bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID"
2230
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
2233
# Bug #17152: Wrong result with BINARY comparison on aliased column
2237
a BIGINT(20) NOT NULL,
2239
) ENGINE=INNODB DEFAULT CHARSET=UTF8;
2242
a BIGINT(20) NOT NULL,
2243
b VARCHAR(128) NOT NULL,
2246
KEY idx_t2_b_c (b,c(200)),
2247
CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a)
2249
) ENGINE=INNODB DEFAULT CHARSET=UTF8;
2251
INSERT INTO t1 VALUES (1);
2252
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
2253
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
2254
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
2255
INSERT INTO t2 VALUES (1, 'customer_over', '1');
2257
SELECT * FROM t2 WHERE b = 'customer_over';
2258
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
2259
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
2260
/* Bang: Empty result set, above was expected: */
2261
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2262
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2267
# Test optimize on table with open transaction
2270
CREATE TABLE t1 ( a int ) ENGINE=innodb;
2272
INSERT INTO t1 VALUES (1);
2277
# Bug #24741 (existing cascade clauses disappear when adding foreign keys)
2280
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
2282
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
2283
CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
2284
ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
2286
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
2287
DELETE CASCADE ON UPDATE CASCADE;
2289
SHOW CREATE TABLE t2;
2293
# Bug #25927: Prevent ALTER TABLE ... MODIFY ... NOT NULL on columns
2294
# for which there is a foreign key constraint ON ... SET NULL.
2297
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
2298
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
2299
INSERT INTO t1 VALUES (1);
2300
INSERT INTO t2 VALUES (1);
2301
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
2302
# mysqltest first does replace_regex, then replace_result
2303
--replace_regex /'[^']*test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
2304
# Embedded server doesn't chdir to data directory
2305
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
2307
ALTER TABLE t2 MODIFY a INT NOT NULL;
2312
# Bug #26835: table corruption after delete+insert
2315
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
2317
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
2319
INSERT INTO t1 VALUES ('DDD');
2324
# Bug #23313 (AUTO_INCREMENT=# not reported back for InnoDB tables)
2325
# Bug #21404 (AUTO_INCREMENT value reset when Adding FKEY (or ALTER?))
2328
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
2331
INSERT INTO t1 VALUES (0),(347),(0);
2334
SHOW CREATE TABLE t1;
2336
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
2337
INSERT INTO t2 VALUES(42),(347),(348);
2338
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
2339
SHOW CREATE TABLE t1;
2344
# Bug #21101 (Prints wrong error message if max row size is too large)
2348
c01 CHAR(255), c02 CHAR(255), c03 CHAR(255), c04 CHAR(255),
2349
c05 CHAR(255), c06 CHAR(255), c07 CHAR(255), c08 CHAR(255),
2350
c09 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
2351
c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
2352
c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
2353
c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
2354
c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
2355
c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255)
2359
# Bug #31860 InnoDB assumes AUTOINC values can only be positive.
2361
DROP TABLE IF EXISTS t1;
2363
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY
2365
INSERT INTO t1 VALUES(-10);
2368
# NOTE: The server really needs to be restarted at this point
2369
# for the test to be useful.
2371
# Without the fix InnoDB would trip over an assertion here.
2372
INSERT INTO t1 VALUES(NULL);
2373
# The next value should be 1 and not -9 or a -ve number
2378
# Bug #21409 Incorrect result returned when in READ-COMMITTED with
2381
CONNECT (c1,localhost,root,,);
2382
CONNECT (c2,localhost,root,,);
2384
SET TX_ISOLATION='read-committed';
2386
DROP TABLE IF EXISTS t1, t2;
2387
CREATE TABLE t1 ( a int ) ENGINE=InnoDB;
2388
CREATE TABLE t2 LIKE t1;
2391
SET TX_ISOLATION='read-committed';
2393
INSERT INTO t1 VALUES (1);
2396
SELECT * FROM t1 WHERE a=1;
2399
CONNECT (c1,localhost,root,,);
2400
CONNECT (c2,localhost,root,,);
2402
SET TX_ISOLATION='read-committed';
2406
SET TX_ISOLATION='read-committed';
2408
INSERT INTO t1 VALUES (2);
2411
# The result set below should be the same for both selects
2412
SELECT * FROM t1 WHERE a=2;
2413
SELECT * FROM t1 WHERE a=2;
2421
# Bug #29157 UPDATE, changed rows incorrect
2423
create table t1 (i int, j int) engine=innodb;
2424
insert into t1 (i, j) values (1, 1), (2, 2);
2426
update t1 set j = 2;
2431
# Bug #32440 InnoDB free space info does not appear in SHOW TABLE STATUS or
2434
create table t1 (id int) comment='this is a comment' engine=innodb;
2435
select table_comment, data_free > 0 as data_free_is_set
2436
from information_schema.tables
2437
where table_schema='test' and table_name = 't1';
2445
c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
2446
c2 VARCHAR(128) NOT NULL,
2448
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
2451
c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
2452
c2 INT(10) UNSIGNED DEFAULT NULL,
2454
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
2456
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
2457
ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
2458
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
2463
# Bug #29507 TRUNCATE shows to many rows effected
2466
CREATE TABLE t1 (c1 int default NULL,
2468
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2473
INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
2479
# Bug#35537 Innodb doesn't increment handler_update and handler_delete.
2481
-- disable_query_log
2482
-- disable_result_log
2484
CONNECT (c1,localhost,root,,);
2486
DROP TABLE IF EXISTS bug35537;
2487
CREATE TABLE bug35537 (
2491
INSERT INTO bug35537 VALUES (1);
2493
-- enable_result_log
2495
SHOW SESSION STATUS LIKE 'Handler_update%';
2496
SHOW SESSION STATUS LIKE 'Handler_delete%';
2498
UPDATE bug35537 SET c1 = 2 WHERE c1 = 1;
2499
DELETE FROM bug35537 WHERE c1 = 2;
2501
SHOW SESSION STATUS LIKE 'Handler_update%';
2502
SHOW SESSION STATUS LIKE 'Handler_delete%';
2504
DROP TABLE bug35537;
2509
#######################################################################
2511
# Please, DO NOT TOUCH this file as well as the innodb.result file. #
2512
# These files are to be modified ONLY BY INNOBASE guys. #
2514
# Use innodb_mysql.[test|result] files instead. #
2516
# If nevertheless you need to make some changes here, please, forward #
2517
# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com #
2518
# (otherwise your changes may be erased). #
2520
#######################################################################