1
drop table if exists t1,t2,t3,t4;
2
drop database if exists mysqltest;
3
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;
4
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
5
select id, code, name from t1 order by id;
14
update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
15
select id, code, name from t1 order by id;
24
update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
25
select id, code, name from t1 order by id;
36
id int NOT NULL auto_increment,
37
parent_id int DEFAULT '0' NOT NULL,
38
level int DEFAULT '0' NOT NULL,
40
KEY parent_id (parent_id),
43
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);
44
update t1 set parent_id=parent_id+100;
45
select * from t1 where parent_id=102;
50
update t1 set id=id+1000;
51
update t1 set id=1024 where id=1009;
52
Got one of the listed errors
94
update ignore t1 set id=id+1;
136
update ignore t1 set id=1023 where id=1010;
137
select * from t1 where parent_id=102;
142
explain select level from t1 where level=1;
143
id select_type table type possible_keys key key_len ref rows Extra
144
1 SIMPLE t1 ref level level 4 const # Using index
145
explain select level,id from t1 where level=1;
146
id select_type table type possible_keys key key_len ref rows Extra
147
1 SIMPLE t1 ref level level 4 const # Using index
148
explain select level,id,parent_id from t1 where level=1;
149
id select_type table type possible_keys key key_len ref rows Extra
150
1 SIMPLE t1 ref level level 4 const #
151
select level,id from t1 where level=1;
159
select level,id,parent_id from t1 where level=1;
168
Table Op Msg_type Msg_text
169
test.t1 optimize status OK
171
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
172
t1 0 PRIMARY 1 id A # NULL NULL BTREE
173
t1 1 parent_id 1 parent_id A # NULL NULL BTREE
174
t1 1 level 1 level A # NULL NULL BTREE
177
gesuchnr int DEFAULT '0' NOT NULL,
178
benutzer_id int DEFAULT '0' NOT NULL,
179
PRIMARY KEY (gesuchnr,benutzer_id)
181
replace into t1 (gesuchnr,benutzer_id) values (2,1);
182
replace into t1 (gesuchnr,benutzer_id) values (1,1);
183
replace into t1 (gesuchnr,benutzer_id) values (1,1);
189
create table t1 (a int) engine=innodb;
190
insert into t1 values (1), (2);
192
Table Op Msg_type Msg_text
193
test.t1 optimize status OK
194
delete from t1 where a = 1;
199
Table Op Msg_type Msg_text
200
test.t1 check status OK
202
create table t1 (a int,b varchar(20)) engine=innodb;
203
insert into t1 values (1,""), (2,"testing");
204
delete from t1 where a = 1;
208
create index skr on t1 (a);
209
insert into t1 values (3,""), (4,"testing");
211
Table Op Msg_type Msg_text
212
test.t1 analyze status OK
214
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
215
t1 1 skr 1 a A # NULL NULL YES BTREE
217
create table t1 (a int,b varchar(20),key(a)) engine=innodb;
218
insert into t1 values (1,""), (2,"testing");
219
select * from t1 where a = 1;
223
create table t1 (n int not null primary key) engine=innodb;
225
insert into t1 values (4);
227
select n, "after rollback" from t1;
229
insert into t1 values (4);
231
select n, "after commit" from t1;
235
insert into t1 values (5);
236
insert into t1 values (4);
237
ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
239
select n, "after commit" from t1;
244
insert into t1 values (6);
245
insert into t1 values (4);
246
ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
254
savepoint `my_savepoint`;
255
insert into t1 values (7);
257
insert into t1 values (3);
266
rollback to savepoint savept2;
267
rollback to savepoint savept3;
268
ERROR 42000: SAVEPOINT savept3 does not exist
269
rollback to savepoint savept2;
270
release savepoint `my_savepoint`;
277
rollback to savepoint `my_savepoint`;
278
ERROR 42000: SAVEPOINT my_savepoint does not exist
279
rollback to savepoint savept2;
280
ERROR 42000: SAVEPOINT savept2 does not exist
281
insert into t1 values (8);
288
create table t1 (n int not null primary key) engine=innodb;
290
insert into t1 values (4);
291
flush tables with read lock;
299
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
301
insert into t1 values(1,'hamdouni');
302
select id as afterbegin_id,nom as afterbegin_nom from t1;
303
afterbegin_id afterbegin_nom
306
select id as afterrollback_id,nom as afterrollback_nom from t1;
307
afterrollback_id afterrollback_nom
309
insert into t1 values(2,'mysql');
310
select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
311
afterautocommit0_id afterautocommit0_nom
314
select id as afterrollback_id,nom as afterrollback_nom from t1;
315
afterrollback_id afterrollback_nom
318
CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
319
insert into t1 values ('pippo', 12);
320
insert into t1 values ('pippo', 12);
321
ERROR 23000: Duplicate entry 'pippo' for key 'PRIMARY'
323
delete from t1 where id = 'pippo';
326
insert into t1 values ('pippo', 12);
338
create table t1 (a integer) engine=innodb;
340
rename table t1 to t2;
341
create table t1 (b integer) engine=innodb;
342
insert into t1 values (1);
345
rename table t2 to t1;
348
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
349
INSERT INTO t1 VALUES (1, 'Jochen');
354
CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
356
INSERT INTO t1 SET _userid='marc@anyware.co.uk';
361
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
367
user_id int DEFAULT '0' NOT NULL,
370
ref_email varchar(100) DEFAULT '' NOT NULL,
372
PRIMARY KEY (user_id,ref_email)
374
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');
375
select * from t1 where user_id=10292;
376
user_id name phone ref_email detail
377
10292 sanjeev 29153373 sansh777@hotmail.com xxx
378
10292 shirish 2333604 shirish@yahoo.com ddsds
379
10292 sonali 323232 sonali@bolly.com filmstar
380
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
381
select * from t1 where user_id=10292;
382
user_id name phone ref_email detail
383
10292 sanjeev 29153373 sansh777@hotmail.com xxx
384
10292 shirish 2333604 shirish@yahoo.com ddsds
385
10292 sonali 323232 sonali@bolly.com filmstar
386
select * from t1 where user_id>=10292;
387
user_id name phone ref_email detail
388
10292 sanjeev 29153373 sansh777@hotmail.com xxx
389
10292 shirish 2333604 shirish@yahoo.com ddsds
390
10292 sonali 323232 sonali@bolly.com filmstar
391
10293 shirish 2333604 shirish@yahoo.com ddsds
392
select * from t1 where user_id>10292;
393
user_id name phone ref_email detail
394
10293 shirish 2333604 shirish@yahoo.com ddsds
395
select * from t1 where user_id<10292;
396
user_id name phone ref_email detail
397
10291 sanjeev 29153373 sansh777@hotmail.com xxx
399
CREATE TABLE t1 (a int not null, b int not null,c int not null,
400
key(a),primary key(a,b), unique(c),key(a),unique(b));
402
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
403
t1 0 PRIMARY 1 a A # NULL NULL BTREE
404
t1 0 PRIMARY 2 b A # NULL NULL BTREE
405
t1 0 c 1 c A # NULL NULL BTREE
406
t1 0 b 1 b A # NULL NULL BTREE
407
t1 1 a 1 a A # NULL NULL BTREE
408
t1 1 a_2 1 a A # NULL NULL BTREE
410
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
411
alter table t1 engine=innodb;
412
insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
420
update t1 set col2='7' where col1='4';
428
alter table t1 add co3 int not null;
436
update t1 set col2='9' where col1='2';
445
create table t1 (a int not null , b int, primary key (a)) engine = innodb;
446
create table t2 (a int not null , b int, primary key (a)) engine = myisam;
447
insert into t1 VALUES (1,3) , (2,3), (3,3);
453
insert into t2 select * from t1;
459
delete from t1 where b = 3;
462
insert into t1 select * from t2;
475
user_name varchar(12),
478
user_id int DEFAULT '0' NOT NULL,
484
dummy_primary_key int NOT NULL auto_increment,
485
PRIMARY KEY (dummy_primary_key)
487
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
488
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
489
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);
490
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);
491
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
492
select user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
493
user_name password subscribed user_id quota weight access_date access_time approved dummy_primary_key
494
user_0 somepassword N 0 0 0 2000-09-07 23:06:59 2000-09-07 23:06:59 1
495
user_1 somepassword Y 1 1 1 2000-09-07 23:06:59 2000-09-07 23:06:59 2
496
user_2 somepassword N 2 2 1.4142135623731 2000-09-07 23:06:59 2000-09-07 23:06:59 3
497
user_3 somepassword Y 3 3 1.7320508075689 2000-09-07 23:06:59 2000-09-07 23:06:59 4
498
user_4 somepassword N 4 4 2 2000-09-07 23:06:59 2000-09-07 23:06:59 5
501
id int NOT NULL auto_increment,
502
parent_id int DEFAULT '0' NOT NULL,
503
level int DEFAULT '0' NOT NULL,
505
KEY parent_id (parent_id),
508
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);
509
INSERT INTO t1 values (179,5,2);
510
update t1 set parent_id=parent_id+100;
511
select * from t1 where parent_id=102;
516
update t1 set id=id+1000;
517
update t1 set id=1024 where id=1009;
559
update ignore t1 set id=id+1;
601
update ignore t1 set id=1023 where id=1010;
602
select * from t1 where parent_id=102;
607
explain select level from t1 where level=1;
608
id select_type table type possible_keys key key_len ref rows Extra
609
1 SIMPLE t1 ref level level 4 const # Using index
610
select level,id from t1 where level=1;
618
select level,id,parent_id from t1 where level=1;
626
select level,id from t1 where level=1 order by id;
634
delete from t1 where level=1;
672
sca_code char(6) NOT NULL,
673
cat_code char(6) NOT NULL,
674
sca_desc varchar(50),
675
lan_code char(2) NOT NULL,
676
sca_pic varchar(100),
677
sca_sdesc varchar(50),
678
sca_sch_desc varchar(16),
679
PRIMARY KEY (sca_code, cat_code, lan_code),
680
INDEX sca_pic (sca_pic)
682
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');
683
select count(*) from t1 where sca_code = 'PD';
686
select count(*) from t1 where sca_code <= 'PD';
689
select count(*) from t1 where sca_pic is null;
692
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
693
select count(*) from t1 where sca_code='PD' and sca_pic is null;
696
select count(*) from t1 where cat_code='E';
699
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
700
select count(*) from t1 where sca_code='PD' and sca_pic is null;
703
select count(*) from t1 where sca_pic >= 'n';
706
select sca_pic from t1 where sca_pic is null;
710
update t1 set sca_pic="test" where sca_pic is null;
711
delete from t1 where sca_code='pd';
714
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
715
insert into t1 (a) values(1),(2),(3);
716
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
721
select a from t1 natural join t1 as t2 where b >= @a order by a;
726
update t1 set a=5 where a=1;
733
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
734
insert into t1 values("hello",1),("world",2);
735
select * from t1 order by b desc;
740
Table Op Msg_type Msg_text
741
test.t1 optimize status OK
743
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
744
t1 0 PRIMARY 1 a A # NULL NULL BTREE
746
create table t1 (i int, j int ) ENGINE=innodb;
747
insert into t1 values (1,2);
748
select * from t1 where i=1 and j=2;
751
create index ax1 on t1 (i,j);
752
select * from t1 where i=1 and j=2;
761
INSERT INTO t1 VALUES (1, 1);
762
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
766
CREATE TABLE t1 (a int NOT NULL) engine=innodb;
767
INSERT INTO t1 VALUES (1);
772
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;
773
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);
774
explain select * from t1 where a > 0 and a < 50;
775
id select_type table type possible_keys key key_len ref rows Extra
776
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where
778
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;
779
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
780
LOCK TABLES t1 WRITE;
781
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
782
ERROR 23000: Duplicate entry '1-1' for key 'PRIMARY'
795
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;
796
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
797
LOCK TABLES t1 WRITE;
799
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
800
ERROR 23000: Duplicate entry '1-1' for key 'PRIMARY'
806
insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
808
select id,id3 from t1;
816
create table t1 (a char(20), unique (a(5))) engine=innodb;
818
create table t1 (a char(20), index (a(5))) engine=innodb;
819
show create table t1;
821
t1 CREATE TABLE `t1` (
826
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
827
insert into t1 values (NULL),(NULL),(NULL);
828
delete from t1 where a=3;
829
insert into t1 values (NULL);
835
alter table t1 add b int;
844
id int auto_increment primary key,
845
name varchar(32) not null,
850
insert into t1 values (1,'one','one value',101),
851
(2,'two','two value',102),(3,'three','three value',103);
852
replace into t1 (value,name,uid) values ('other value','two',102);
853
delete from t1 where uid=102;
854
replace into t1 (value,name,uid) values ('other value','two',102);
855
replace into t1 (value,name,uid) values ('other value','two',102);
859
3 three three value 103
860
6 two other value 102
862
create database mysqltest;
863
create table mysqltest.t1 (a int not null) engine= innodb;
864
insert into mysqltest.t1 values(1);
865
create table mysqltest.t2 (a int not null) engine= myisam;
866
insert into mysqltest.t2 values(1);
867
create table mysqltest.t3 (a int not null) engine= heap;
868
insert into mysqltest.t3 values(1);
870
drop database mysqltest;
871
show tables from mysqltest;
872
ERROR 42000: Unknown database 'mysqltest'
874
create table t1 (a int not null) engine= innodb;
875
insert into t1 values(1),(2);
882
insert into t1 values(1),(2);
889
create table t1 (a int not null) engine= innodb;
890
insert into t1 values(1),(2);
892
insert into t1 values(1),(2);
898
insert into t1 values(1),(2);
903
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
904
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
905
explain select * from t1 order by a;
906
id select_type table type possible_keys key key_len ref rows Extra
907
1 SIMPLE t1 index NULL PRIMARY 4 NULL #
908
explain select * from t1 order by b;
909
id select_type table type possible_keys key key_len ref rows Extra
910
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
911
explain select * from t1 order by c;
912
id select_type table type possible_keys key key_len ref rows Extra
913
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
914
explain select a from t1 order by a;
915
id select_type table type possible_keys key key_len ref rows Extra
916
1 SIMPLE t1 index NULL PRIMARY 4 NULL # Using index
917
explain select b from t1 order by b;
918
id select_type table type possible_keys key key_len ref rows Extra
919
1 SIMPLE t1 index NULL b 4 NULL # Using index
920
explain select a,b from t1 order by b;
921
id select_type table type possible_keys key key_len ref rows Extra
922
1 SIMPLE t1 index NULL b 4 NULL # Using index
923
explain select a,b from t1;
924
id select_type table type possible_keys key key_len ref rows Extra
925
1 SIMPLE t1 index NULL PRIMARY 4 NULL #
926
explain select a,b,c from t1;
927
id select_type table type possible_keys key key_len ref rows Extra
928
1 SIMPLE t1 ALL NULL NULL NULL NULL #
930
create table t1 (t int not null default 1, key (t)) engine=innodb;
932
Field Type Null Key Default Extra
936
number bigint NOT NULL default '0',
937
cname char(15) NOT NULL default '',
938
carrier_id int NOT NULL default '0',
939
privacy int NOT NULL default '0',
940
last_mod_date timestamp NOT NULL,
941
last_mod_id int NOT NULL default '0',
942
last_app_date timestamp NOT NULL,
943
last_app_id int default '-1',
944
version int NOT NULL default '0',
945
assigned_scps int default '0',
946
status int default '0'
948
INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
949
INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
950
INSERT INTO t1 VALUES (650,'San Francisco',0,0,20011227111336,342,00000000000000,-1,1,24,1);
951
INSERT INTO t1 VALUES (302467,'Sue\'s Subshop',90,3,20020109113241,500,20020102115111,501,7,24,0);
952
INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
953
INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
955
number bigint NOT NULL default '0',
956
cname char(15) NOT NULL default '',
957
carrier_id int NOT NULL default '0',
958
privacy int NOT NULL default '0',
959
last_mod_date timestamp NOT NULL,
960
last_mod_id int NOT NULL default '0',
961
last_app_date timestamp NOT NULL,
962
last_app_id int default '-1',
963
version int NOT NULL default '0',
964
assigned_scps int default '0',
965
status int default '0'
967
INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
968
INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
969
INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,00000000000000,-1,1,24,1);
970
INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
972
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
973
4077711111 SeanWheeler 90 2 2002-01-11 11:28:46 500 0000-00-00 00:00:00 -1 2 3 1
974
9197722223 berry 90 3 2002-01-11 11:28:09 500 2002-01-02 11:45:32 501 4 10 0
975
650 San Francisco 0 0 2001-12-27 11:13:36 342 0000-00-00 00:00:00 -1 1 24 1
976
302467 Sue's Subshop 90 3 2002-01-09 11:32:41 500 2002-01-02 11:51:11 501 7 24 0
977
6014911113 SudzCarwash 520 1 2002-01-02 11:52:34 500 2002-01-02 11:52:59 501 33 32768 0
978
333 tubs 99 2 2002-01-09 11:34:40 501 2002-01-09 11:34:40 500 3 10 0
980
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
981
4077711111 SeanWheeler 0 2 2002-01-11 11:28:53 500 0000-00-00 00:00:00 -1 2 3 1
982
9197722223 berry 90 3 2002-01-11 11:28:18 500 2002-01-02 11:45:32 501 4 10 0
983
650 San Francisco 90 0 2002-01-09 11:31:58 342 0000-00-00 00:00:00 -1 1 24 1
984
333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
985
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);
987
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
988
6014911113 SudzCarwash 520 1 2002-01-02 11:52:34 500 2002-01-02 11:52:59 501 33 32768 0
989
333 tubs 99 2 2002-01-09 11:34:40 501 2002-01-09 11:34:40 500 3 10 0
991
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
992
333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
994
number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
995
333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
997
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;
999
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
1000
SELECT @@tx_isolation,@@global.tx_isolation;
1001
@@tx_isolation @@global.tx_isolation
1002
SERIALIZABLE REPEATABLE-READ
1003
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
1004
select id, code, name from t1 order by id;
1011
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
1012
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
1013
select id, code, name from t1 order by id;
1022
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
1023
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
1024
select id, code, name from t1 order by id;
1035
create table t1 (n int, d int) engine=innodb;
1036
create table t2 (n int, d int) engine=innodb;
1037
insert into t1 values(1,1),(1,2);
1038
insert into t2 values(1,10),(2,20);
1039
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
1049
create table t1 (a int, b int) engine=innodb;
1050
insert into t1 values(20,null);
1051
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
1053
b ifnull(t2.b,"this is null")
1055
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
1056
t2.b=t3.a order by 1;
1057
b ifnull(t2.b,"this is null")
1059
insert into t1 values(10,null);
1060
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
1061
t2.b=t3.a order by 1;
1062
b ifnull(t2.b,"this is null")
1066
create table t1 (a varchar(10) not null) engine=myisam;
1067
create table t2 (b varchar(10) not null unique) engine=innodb;
1068
select t1.a from t1,t2 where t1.a=t2.b;
1071
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
1072
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
1073
insert into t1 values (10, 20);
1074
insert into t2 values (10, 20);
1075
update t1, t2 set t1.b = 150, t2.b = t1.b where t2.a = t1.a and t1.a = 10;
1077
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
1078
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;
1079
insert into t1 set id=1;
1080
insert into t2 set id=1, t1_id=1;
1081
delete t1,t2 from t1,t2 where t1.id=t2.t1_id;
1087
CREATE TABLE t1(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
1088
CREATE TABLE t2(id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id) ) ENGINE=INNODB;
1089
INSERT INTO t1 VALUES(1);
1090
INSERT INTO t2 VALUES(1, 1);
1094
UPDATE t1,t2 SET t1.id=t1.id+1, t2.t1_id=t1.id+1;
1098
UPDATE t1,t2 SET t1.id=t1.id+1 where t1.id!=t2.id;
1104
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
1105
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
1106
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
1107
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
1109
INSERT INTO t1 VALUES("this-key", "will disappear");
1110
INSERT INTO t2 VALUES("this-key", "will also disappear");
1111
DELETE FROM t3 WHERE id1="my-test-1";
1114
this-key will disappear
1117
this-key will also disappear
1128
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
1133
DROP TABLE t1,t2,t3;
1134
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
1135
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
1136
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
1149
CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) engine=innodb;
1150
CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) engine=innodb;
1151
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);
1152
INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
1153
update t1,t2 set t1.a=t1.a+100;
1168
update t1,t2 set t1.a=t1.a+100 where t1.a=101;
1183
update t1,t2 set t1.b=t1.b+10 where t1.b=2;
1198
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;
1225
CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) ENGINE=MyISAM;
1226
CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB;
1228
INSERT INTO t1 ( B_ID ) VALUES ( 1 );
1229
INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );
1232
Warning 1196 Some non-transactional changed tables couldn't be rolled back
1236
create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) engine = innodb;
1237
insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2);
1238
select distinct parent,child from t1 order by parent;
1245
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
1246
create table t2 (a int not null auto_increment primary key, b int);
1247
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
1248
insert into t2 (a) select b from t1;
1249
insert into t1 (b) select b from t2;
1250
insert into t2 (a) select b from t1;
1251
insert into t1 (a) select b from t2;
1252
insert into t2 (a) select b from t1;
1253
insert into t1 (a) select b from t2;
1254
insert into t2 (a) select b from t1;
1255
insert into t1 (a) select b from t2;
1256
insert into t2 (a) select b from t1;
1257
insert into t1 (a) select b from t2;
1258
select count(*) from t1;
1261
explain select * from t1 where c between 1 and 2500;
1262
id select_type table type possible_keys key key_len ref rows Extra
1263
1 SIMPLE t1 range c c 5 NULL # Using where; Using MRR
1265
explain select * from t1 where c between 1 and 2500;
1266
id select_type table type possible_keys key key_len ref rows Extra
1267
1 SIMPLE t1 ALL c NULL NULL NULL # Using where
1269
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
1270
insert into t1 (id) values (null),(null),(null),(null),(null);
1271
update t1 set fk=69 where fk is null order by id limit 1;
1280
create table t1 (a int not null, b int not null, key (a));
1281
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);
1283
update t1 set b=(@tmp:=@tmp+1) order by a;
1284
update t1 set b=99 where a=1 order by b asc limit 1;
1285
update t1 set b=100 where a=1 order by b desc limit 2;
1286
update t1 set a=a+10+b where a=1 order by b;
1287
select * from t1 order by a,b;
1302
create table t1 ( c char(8) not null ) engine=innodb;
1303
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
1304
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
1305
alter table t1 add b char(8) not null;
1306
alter table t1 add a char(8) not null;
1307
alter table t1 add primary key (a,b,c);
1308
update t1 set a=c, b=c;
1309
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;
1310
insert into t2 select * from t1;
1311
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
1314
create table t1 (a integer auto_increment primary key) engine=innodb;
1315
insert into t1 (a) values (NULL),(NULL);
1317
insert into t1 (a) values (NULL),(NULL);
1323
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
1324
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;
1326
create table `t1` (`id` int not null ,primary key ( `id` )) engine = innodb;
1327
insert into `t1`values ( 1 ) ;
1328
create table `t2` (`id` int not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = innodb;
1329
insert into `t2`values ( 1 ) ;
1330
create table `t3` (`id` int not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb;
1331
insert into `t3`values ( 1 ) ;
1332
delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
1333
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))
1334
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;
1335
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))
1336
update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
1337
ERROR 42S22: Unknown column 't1.id' in 'where clause'
1338
drop table t3,t2,t1;
1343
foreign key(pid) references t1(id) on delete cascade) engine=innodb;
1344
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
1345
(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
1346
delete from t1 where id=0;
1347
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `t1` (`id`) ON DELETE CASCADE)
1348
delete from t1 where id=15;
1349
delete from t1 where id=0;
1351
CREATE TABLE t1 (col1 int) ENGINE=InnoDB;
1352
CREATE TABLE t2 (col1 int, stamp TIMESTAMP,INDEX stamp_idx (stamp)) ENGINE=InnoDB;
1353
insert into t1 values (1),(2),(3);
1354
insert into t2 values (1, 20020204110000),(2, 20020204110001),(4,20020204110002 ),(5,20020204110003);
1355
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
1356
'20020204120000' GROUP BY col1;
1365
`id` int NOT NULL auto_increment,
1366
`id_object` int default '0',
1367
`id_version` int NOT NULL default '1',
1368
`label` varchar(100) NOT NULL default '',
1371
KEY `id_object` (`id_object`),
1372
KEY `id_version` (`id_version`)
1374
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);
1376
`id` int NOT NULL auto_increment,
1377
`id_version` int NOT NULL default '1',
1379
KEY `id_version` (`id_version`)
1381
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
1382
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
1383
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
1384
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
1391
3525 Fournisseur Test
1393
create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=myisam;
1394
create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=innodb;
1395
create table t3 (a int, b varchar(200), c text not null) checksum=1 engine=innodb;
1396
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
1397
insert t2 select * from t1;
1398
insert t3 select * from t1;
1399
checksum table t1, t2, t3, t4 quick;
1406
Error 1146 Table 'test.t4' doesn't exist
1407
checksum table t1, t2, t3, t4;
1414
Error 1146 Table 'test.t4' doesn't exist
1415
checksum table t1, t2, t3, t4 extended;
1422
Error 1146 Table 'test.t4' doesn't exist
1423
drop table t1,t2,t3;
1424
create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
1425
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
1426
select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
1438
create table t1 (a int) engine=innodb;
1439
create table t2 like t1;
1441
create table t1 (id int not null, id2 int not null, unique (id,id2)) engine=innodb;
1442
create table t2 (id int not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
1443
show create table t1;
1445
t1 CREATE TABLE `t1` (
1448
UNIQUE KEY `id` (`id`,`id2`)
1450
show create table t2;
1452
t2 CREATE TABLE `t2` (
1454
KEY `t1_id_fk` (`id`),
1455
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1457
create index id on t2 (id);
1458
show create table t2;
1460
t2 CREATE TABLE `t2` (
1463
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1465
create index id2 on t2 (id);
1466
show create table t2;
1468
t2 CREATE TABLE `t2` (
1472
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1474
drop index id2 on t2;
1475
drop index id on t2;
1476
Got one of the listed errors
1477
show create table t2;
1479
t2 CREATE TABLE `t2` (
1482
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1485
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;
1486
show create table t2;
1488
t2 CREATE TABLE `t2` (
1491
KEY `t1_id_fk` (`id`,`id2`),
1492
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1494
create unique index id on t2 (id,id2);
1495
show create table t2;
1497
t2 CREATE TABLE `t2` (
1500
UNIQUE KEY `id` (`id`,`id2`),
1501
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1504
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;
1505
show create table t2;
1507
t2 CREATE TABLE `t2` (
1510
UNIQUE KEY `id` (`id`,`id2`),
1511
KEY `t1_id_fk` (`id2`,`id`),
1512
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1515
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;
1516
show create table t2;
1518
t2 CREATE TABLE `t2` (
1521
UNIQUE KEY `id` (`id`,`id2`),
1522
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1525
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;
1526
show create table t2;
1528
t2 CREATE TABLE `t2` (
1531
UNIQUE KEY `id` (`id`,`id2`),
1532
KEY `t1_id_fk` (`id2`,`id`),
1533
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1536
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;
1537
show create table t2;
1539
t2 CREATE TABLE `t2` (
1540
`id` int NOT NULL AUTO_INCREMENT,
1543
KEY `id` (`id`,`id2`),
1544
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1547
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;
1548
show create table t2;
1550
t2 CREATE TABLE `t2` (
1551
`id` int NOT NULL AUTO_INCREMENT,
1553
KEY `t1_id_fk` (`id`),
1554
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1556
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1557
show create table t2;
1559
t2 CREATE TABLE `t2` (
1560
`id` int NOT NULL AUTO_INCREMENT,
1562
KEY `id_test` (`id`),
1563
KEY `id_test2` (`id`,`id2`),
1564
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1567
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
1568
ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match
1569
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
1570
show create table t2;
1572
t2 CREATE TABLE `t2` (
1573
`a` int NOT NULL AUTO_INCREMENT,
1576
UNIQUE KEY `b_2` (`b`),
1578
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1581
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;
1582
show create table t2;
1584
t2 CREATE TABLE `t2` (
1585
`a` int NOT NULL AUTO_INCREMENT,
1588
UNIQUE KEY `b` (`b`),
1589
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
1590
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1593
create table t1 (c char(10), index (c,c)) engine=innodb;
1594
ERROR 42S21: Duplicate column name 'c'
1595
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
1596
ERROR 42S21: Duplicate column name 'c1'
1597
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
1598
ERROR 42S21: Duplicate column name 'c1'
1599
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
1600
ERROR 42S21: Duplicate column name 'c1'
1601
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
1602
alter table t1 add key (c1,c1);
1603
ERROR 42S21: Duplicate column name 'c1'
1604
alter table t1 add key (c2,c1,c1);
1605
ERROR 42S21: Duplicate column name 'c1'
1606
alter table t1 add key (c1,c2,c1);
1607
ERROR 42S21: Duplicate column name 'c1'
1608
alter table t1 add key (c1,c1,c2);
1609
ERROR 42S21: Duplicate column name 'c1'
1611
create table t1(a int, b int) engine=innodb;
1612
insert into t1 values ('1111', '3333');
1613
select distinct concat(a, b) from t1;
1617
CREATE TABLE t1 (a_id int NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=InnoDB;
1618
INSERT INTO t1 VALUES (1),(2),(3);
1619
CREATE TABLE t2 (b_id int NOT NULL default '0',b_a int NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
1620
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB;
1621
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
1622
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;
1629
create temporary table t1 (a int) engine=innodb;
1630
insert into t1 values (4711);
1632
insert into t1 values (42);
1637
create table t1 (a int) engine=innodb;
1638
insert into t1 values (4711);
1640
insert into t1 values (42);
1645
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;
1646
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
1647
select * from t1 order by a,b,c,d;
1652
explain select * from t1 order by a,b,c,d;
1653
id select_type table type possible_keys key key_len ref rows Extra
1654
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
1656
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1657
insert into t1 values ('8', '6'), ('4', '7');
1658
select min(a) from t1;
1661
select min(b) from t1 where a='8';
1665
create table t1 (x bigint not null primary key) engine=innodb;
1666
insert into t1(x) values (0x0ffffffffffffff0),(0x0ffffffffffffff1);
1671
select count(*) from t1 where x>0;
1674
select count(*) from t1 where x=0;
1677
select count(*) from t1 where x<0;
1680
select count(*) from t1 where x < -16;
1683
select count(*) from t1 where x = -16;
1686
explain select count(*) from t1 where x > -16;
1687
id select_type table type possible_keys key key_len ref rows Extra
1688
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL 1 Using where; Using index
1689
select count(*) from t1 where x > -16;
1692
select * from t1 where x > -16;
1696
select count(*) from t1 where x = 1152921504606846961;
1700
show variables like "innodb_sync_spin_loops";
1702
innodb_sync_spin_loops 20
1703
set global innodb_sync_spin_loops=1000;
1704
show variables like "innodb_sync_spin_loops";
1706
innodb_sync_spin_loops 1000
1707
set global innodb_sync_spin_loops=0;
1708
show variables like "innodb_sync_spin_loops";
1710
innodb_sync_spin_loops 0
1711
set global innodb_sync_spin_loops=20;
1712
show variables like "innodb_sync_spin_loops";
1714
innodb_sync_spin_loops 20
1715
show variables like "innodb_thread_concurrency";
1717
innodb_thread_concurrency 8
1718
set global innodb_thread_concurrency=1001;
1720
Warning 1292 Truncated incorrect thread_concurrency value: '1001'
1721
show variables like "innodb_thread_concurrency";
1723
innodb_thread_concurrency 1000
1724
set global innodb_thread_concurrency=0;
1725
show variables like "innodb_thread_concurrency";
1727
innodb_thread_concurrency 0
1728
set global innodb_thread_concurrency=16;
1729
show variables like "innodb_thread_concurrency";
1731
innodb_thread_concurrency 16
1732
show variables like "innodb_concurrency_tickets";
1734
innodb_concurrency_tickets 500
1735
set global innodb_concurrency_tickets=1000;
1736
show variables like "innodb_concurrency_tickets";
1738
innodb_concurrency_tickets 1000
1739
set global innodb_concurrency_tickets=0;
1741
Warning 1292 Truncated incorrect concurrency_tickets value: '0'
1742
show variables like "innodb_concurrency_tickets";
1744
innodb_concurrency_tickets 1
1745
set global innodb_concurrency_tickets=500;
1746
show variables like "innodb_concurrency_tickets";
1748
innodb_concurrency_tickets 500
1749
show variables like "innodb_thread_sleep_delay";
1751
innodb_thread_sleep_delay 10000
1752
set global innodb_thread_sleep_delay=100000;
1753
show variables like "innodb_thread_sleep_delay";
1755
innodb_thread_sleep_delay 100000
1756
set global innodb_thread_sleep_delay=0;
1757
show variables like "innodb_thread_sleep_delay";
1759
innodb_thread_sleep_delay 0
1760
set global innodb_thread_sleep_delay=10000;
1761
show variables like "innodb_thread_sleep_delay";
1763
innodb_thread_sleep_delay 10000
1764
set storage_engine=INNODB;
1765
drop table if exists t1,t2,t3;
1766
--- Testing varchar ---
1767
--- Testing varchar ---
1768
create table t1 (v varchar(10), c char(10), t text);
1769
insert into t1 values('+ ', '+ ', '+ ');
1770
set @a=repeat(' ',20);
1771
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1773
Note 1265 Data truncated for column 'v' at row 1
1774
Note 1265 Data truncated for column 'c' at row 1
1775
select concat('*',v,'*',c,'*',t,'*') from t1;
1776
concat('*',v,'*',c,'*',t,'*')
1779
show create table t1;
1781
t1 CREATE TABLE `t1` (
1786
create table t2 like t1;
1787
show create table t2;
1789
t2 CREATE TABLE `t2` (
1794
create table t3 select * from t1;
1795
show create table t3;
1797
t3 CREATE TABLE `t3` (
1802
alter table t1 modify c varchar(10);
1803
show create table t1;
1805
t1 CREATE TABLE `t1` (
1810
alter table t1 modify v char(10);
1811
show create table t1;
1813
t1 CREATE TABLE `t1` (
1818
alter table t1 modify t varchar(10);
1820
Note 1265 Data truncated for column 't' at row 2
1821
show create table t1;
1823
t1 CREATE TABLE `t1` (
1828
select concat('*',v,'*',c,'*',t,'*') from t1;
1829
concat('*',v,'*',c,'*',t,'*')
1832
drop table t1,t2,t3;
1833
create table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
1834
show create table t1;
1836
t1 CREATE TABLE `t1` (
1844
select count(*) from t1;
1847
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
1848
select count(*) from t1 where v='a';
1851
select count(*) from t1 where c='a';
1854
select count(*) from t1 where t='a';
1857
select count(*) from t1 where v='a ';
1860
select count(*) from t1 where c='a ';
1863
select count(*) from t1 where t='a ';
1866
select count(*) from t1 where v between 'a' and 'a ';
1869
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1872
select count(*) from t1 where v like 'a%';
1875
select count(*) from t1 where c like 'a%';
1878
select count(*) from t1 where t like 'a%';
1881
select count(*) from t1 where v like 'a %';
1884
explain select count(*) from t1 where v='a ';
1885
id select_type table type possible_keys key key_len ref rows Extra
1886
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1887
explain select count(*) from t1 where c='a ';
1888
id select_type table type possible_keys key key_len ref rows Extra
1889
1 SIMPLE t1 ref c c 43 const # Using where; Using index
1890
explain select count(*) from t1 where t='a ';
1891
id select_type table type possible_keys key key_len ref rows Extra
1892
1 SIMPLE t1 ref t t 43 const # Using where
1893
explain select count(*) from t1 where v like 'a%';
1894
id select_type table type possible_keys key key_len ref rows Extra
1895
1 SIMPLE t1 range v v 43 NULL # Using where; Using index
1896
explain select count(*) from t1 where v between 'a' and 'a ';
1897
id select_type table type possible_keys key key_len ref rows Extra
1898
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1899
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1900
id select_type table type possible_keys key key_len ref rows Extra
1901
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1902
alter table t1 add unique(v);
1903
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
1904
alter table t1 add key(v);
1905
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
1917
explain select * from t1 where v='a';
1918
id select_type table type possible_keys key key_len ref rows Extra
1919
1 SIMPLE t1 ref v,v_2 # 43 const # Using where
1920
select v,count(*) from t1 group by v limit 10;
1932
select v,count(t) from t1 group by v limit 10;
1944
select v,count(c) from t1 group by v limit 10;
1956
select sql_big_result v,count(t) from t1 group by v limit 10;
1968
select sql_big_result v,count(c) from t1 group by v limit 10;
1980
select c,count(*) from t1 group by c limit 10;
1992
select c,count(t) from t1 group by c limit 10;
2004
select sql_big_result c,count(t) from t1 group by c limit 10;
2016
select t,count(*) from t1 group by t limit 10;
2028
select t,count(t) from t1 group by t limit 10;
2040
select sql_big_result t,count(t) from t1 group by t limit 10;
2052
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
2054
Warning 1071 Specified key was too long; max key length is 767 bytes
2055
Warning 1071 Specified key was too long; max key length is 767 bytes
2056
Warning 1071 Specified key was too long; max key length is 767 bytes
2057
show create table t1;
2059
t1 CREATE TABLE `t1` (
2067
select count(*) from t1 where v='a';
2070
select count(*) from t1 where v='a ';
2073
select count(*) from t1 where v between 'a' and 'a ';
2076
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
2079
select count(*) from t1 where v like 'a%';
2082
select count(*) from t1 where v like 'a %';
2085
explain select count(*) from t1 where v='a ';
2086
id select_type table type possible_keys key key_len ref rows Extra
2087
1 SIMPLE t1 ref v v 767 const # Using where
2088
explain select count(*) from t1 where v like 'a%';
2089
id select_type table type possible_keys key key_len ref rows Extra
2090
1 SIMPLE t1 range v v 767 NULL # Using where
2091
explain select count(*) from t1 where v between 'a' and 'a ';
2092
id select_type table type possible_keys key key_len ref rows Extra
2093
1 SIMPLE t1 ref v v 767 const # Using where
2094
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
2095
id select_type table type possible_keys key key_len ref rows Extra
2096
1 SIMPLE t1 ref v v 767 const # Using where
2097
explain select * from t1 where v='a';
2098
id select_type table type possible_keys key key_len ref rows Extra
2099
1 SIMPLE t1 ref v v 767 const # Using where
2100
select v,count(*) from t1 group by v limit 10;
2112
select v,count(t) from t1 group by v limit 10;
2124
select sql_big_result v,count(t) from t1 group by v limit 10;
2136
alter table t1 drop key v, add key v (v(30));
2137
show create table t1;
2139
t1 CREATE TABLE `t1` (
2147
select count(*) from t1 where v='a';
2150
select count(*) from t1 where v='a ';
2153
select count(*) from t1 where v between 'a' and 'a ';
2156
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
2159
select count(*) from t1 where v like 'a%';
2162
select count(*) from t1 where v like 'a %';
2165
explain select count(*) from t1 where v='a ';
2166
id select_type table type possible_keys key key_len ref rows Extra
2167
1 SIMPLE t1 ref v v 123 const # Using where
2168
explain select count(*) from t1 where v like 'a%';
2169
id select_type table type possible_keys key key_len ref rows Extra
2170
1 SIMPLE t1 range v v 123 NULL # Using where
2171
explain select count(*) from t1 where v between 'a' and 'a ';
2172
id select_type table type possible_keys key key_len ref rows Extra
2173
1 SIMPLE t1 ref v v 123 const # Using where
2174
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
2175
id select_type table type possible_keys key key_len ref rows Extra
2176
1 SIMPLE t1 ref v v 123 const # Using where
2177
explain select * from t1 where v='a';
2178
id select_type table type possible_keys key key_len ref rows Extra
2179
1 SIMPLE t1 ref v v 123 const # Using where
2180
select v,count(*) from t1 group by v limit 10;
2192
select v,count(t) from t1 group by v limit 10;
2204
select sql_big_result v,count(t) from t1 group by v limit 10;
2216
alter table t1 modify v varchar(600), drop key v, add key v (v);
2218
Warning 1071 Specified key was too long; max key length is 767 bytes
2219
Warning 1071 Specified key was too long; max key length is 767 bytes
2220
Warning 1071 Specified key was too long; max key length is 767 bytes
2221
show create table t1;
2223
t1 CREATE TABLE `t1` (
2231
select v,count(*) from t1 group by v limit 10;
2243
select v,count(t) from t1 group by v limit 10;
2255
select sql_big_result v,count(t) from t1 group by v limit 10;
2268
create table t1 (a char(10), unique (a));
2269
insert into t1 values ('a ');
2270
insert into t1 values ('a ');
2271
ERROR 23000: Duplicate entry 'a ' for key 'a'
2272
alter table t1 modify a varchar(10);
2273
insert into t1 values ('a '),('a '),('a '),('a ');
2274
ERROR 23000: Duplicate entry 'a ' for key 'a'
2275
insert into t1 values ('a ');
2276
ERROR 23000: Duplicate entry 'a ' for key 'a'
2277
insert into t1 values ('a ');
2278
ERROR 23000: Duplicate entry 'a ' for key 'a'
2279
insert into t1 values ('a ');
2280
ERROR 23000: Duplicate entry 'a ' for key 'a'
2281
update t1 set a='a ' where a like 'a%';
2282
select concat(a,'.') from t1;
2285
update t1 set a='abc ' where a like 'a ';
2286
select concat(a,'.') from t1;
2289
update t1 set a='a ' where a like 'a %';
2290
select concat(a,'.') from t1;
2293
update t1 set a='a ' where a like 'a ';
2294
select concat(a,'.') from t1;
2298
create table t1 (v varchar(10), c char(10), t text, key(v(5)), key(c(5)), key(t(5)));
2299
show create table t1;
2301
t1 CREATE TABLE `t1` (
2310
create table t1 (v char(10));
2311
show create table t1;
2313
t1 CREATE TABLE `t1` (
2317
create table t1 (v varchar(10), c char(10)) row_format=fixed;
2319
Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT.
2320
show create table t1;
2322
t1 CREATE TABLE `t1` (
2325
) ENGINE=InnoDB ROW_FORMAT=FIXED
2326
insert into t1 values('a','a'),('a ','a ');
2327
select concat('*',v,'*',c,'*') from t1;
2328
concat('*',v,'*',c,'*')
2332
create table t1(a int, b varchar(12), key ba(b, a));
2333
insert into t1 values (1, 'A'), (20, NULL);
2334
explain select * from t1 where a=20 and b is null;
2335
id select_type table type possible_keys key key_len ref rows Extra
2336
1 SIMPLE t1 ref ba ba 56 const,const 1 Using where; Using index
2337
select * from t1 where a=20 and b is null;
2341
create table t1 (v varchar(16383), key(v));
2343
Warning 1071 Specified key was too long; max key length is 767 bytes
2345
create table t1 (v varchar(16383));
2346
show create table t1;
2348
t1 CREATE TABLE `t1` (
2352
create table t1 (v varchar(16383));
2353
show create table t1;
2355
t1 CREATE TABLE `t1` (
2359
set storage_engine=InnoDB;
2360
create table t1 (v varchar(16383)) engine=innodb;
2362
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
2363
insert into t1 values ('8', '6'), ('4', '7');
2364
select min(a) from t1;
2367
select min(b) from t1 where a='8';
2371
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
2372
insert into t1 (b) values (1);
2373
replace into t1 (b) values (2), (1), (3);
2380
insert into t1 (b) values (1);
2381
replace into t1 (b) values (2);
2382
replace into t1 (b) values (1);
2383
replace into t1 (b) values (3);
2390
create table t1 (rowid int not null auto_increment, val int not null,primary
2391
key (rowid), unique(val)) engine=innodb;
2392
replace into t1 (val) values ('1'),('2');
2393
replace into t1 (val) values ('1'),('2');
2394
insert into t1 (val) values ('1'),('2');
2395
ERROR 23000: Duplicate entry '1' for key 'val'
2401
create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
2402
insert into t1 (val) values (1);
2403
update t1 set a=2 where a=1;
2404
insert into t1 (val) values (1);
2405
ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
2410
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
2411
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
2412
SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300;
2415
SELECT GRADE FROM t1 WHERE GRADE= 151;
2419
create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb;
2420
create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb;
2421
insert into t2 values ('aa','cc');
2422
insert into t1 values ('aa','bb'),('aa','cc');
2423
delete t1 from t1,t2 where f1=f3 and f4='cc';
2428
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
2431
id INTEGER NOT NULL,
2432
FOREIGN KEY (id) REFERENCES t1 (id)
2434
INSERT INTO t1 (id) VALUES (NULL);
2439
INSERT INTO t1 (id) VALUES (NULL);
2445
INSERT INTO t1 (id) VALUES (NULL);
2454
CREATE TEMPORARY TABLE t2
2456
id INT NOT NULL PRIMARY KEY,
2458
FOREIGN KEY (b) REFERENCES test.t1(id)
2460
Got one of the listed errors
2462
create table t1 (col1 varchar(2000), index (col1(767)))
2465
Warning 1071 Specified key was too long; max key length is 767 bytes
2466
create table t2 (col1 char(255), index (col1))
2469
Warning 1071 Specified key was too long; max key length is 767 bytes
2470
create table t4 (col1 varchar(767), index (col1))
2473
Warning 1071 Specified key was too long; max key length is 767 bytes
2474
create table t5 (col1 varchar(190) primary key)
2476
create table t6 (col1 varbinary(254) primary key)
2478
create table t7 (col1 text, index(col1(767)))
2481
Warning 1071 Specified key was too long; max key length is 767 bytes
2482
create table t8 (col1 blob, index(col1(767)))
2484
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
2487
Warning 1071 Specified key was too long; max key length is 767 bytes
2488
Warning 1071 Specified key was too long; max key length is 767 bytes
2489
show create table t9;
2491
t9 CREATE TABLE `t9` (
2492
`col1` varchar(512),
2493
`col2` varchar(512),
2494
KEY `col1` (`col1`(),`col2`())
2496
drop table t1, t2, t4, t5, t6, t7, t8, t9;
2497
create table t1 (col1 varchar(768), index(col1))
2500
Warning 1071 Specified key was too long; max key length is 767 bytes
2501
create table t2 (col1 varbinary(768), index(col1))
2504
Warning 1071 Specified key was too long; max key length is 767 bytes
2505
create table t3 (col1 text, index(col1(768)))
2508
Warning 1071 Specified key was too long; max key length is 767 bytes
2509
create table t4 (col1 blob, index(col1(768)))
2512
Warning 1071 Specified key was too long; max key length is 767 bytes
2513
show create table t1;
2515
t1 CREATE TABLE `t1` (
2516
`col1` varchar(768),
2517
KEY `col1` (`col1`())
2519
drop table t1, t2, t3, t4;
2520
create table t1 (col1 varchar(768) primary key)
2522
ERROR 42000: Specified key was too long; max key length is 767 bytes
2523
create table t2 (col1 varbinary(768) primary key)
2525
ERROR 42000: Specified key was too long; max key length is 767 bytes
2526
create table t3 (col1 text, primary key(col1(768)))
2528
ERROR 42000: Specified key was too long; max key length is 767 bytes
2529
create table t4 (col1 blob, primary key(col1(768)))
2531
ERROR 42000: Specified key was too long; max key length is 767 bytes
2539
CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
2541
INSERT INTO t2 VALUES(2);
2542
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2543
INSERT INTO t1 VALUES(1);
2544
INSERT INTO t2 VALUES(1);
2545
DELETE FROM t1 WHERE id = 1;
2546
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2548
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
2549
SET FOREIGN_KEY_CHECKS=0;
2551
SET FOREIGN_KEY_CHECKS=1;
2552
INSERT INTO t2 VALUES(3);
2553
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2555
create table t1(a int not null) engine=innodb;
2556
insert into t1 values (1),(2);
2561
insert into t1 values(3);
2571
create table t1(a int not null) engine=innodb;
2572
insert into t1 values (1),(2);
2578
insert into t1 values(3);
2583
set foreign_key_checks=0;
2584
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
2585
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
2586
ERROR HY000: Can't create table 'test.t1' (errno: 150)
2587
set foreign_key_checks=1;
2589
set foreign_key_checks=0;
2590
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
2591
create table t1(a varchar(10) primary key) engine = innodb;
2592
alter table t1 modify column a int;
2593
Got one of the listed errors
2594
set foreign_key_checks=1;
2596
create table t1(a int primary key) row_format=redundant engine=innodb;
2597
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
2598
create table t3(a int primary key) row_format=compact engine=innodb;
2599
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
2600
insert into t1 values(1);
2601
insert into t3 values(1);
2602
insert into t2 values(2);
2603
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
2604
insert into t4 values(2);
2605
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
2606
insert into t2 values(1);
2607
insert into t4 values(1);
2609
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
2611
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
2613
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
2615
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
2617
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
2619
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
2624
drop table t4,t3,t2,t1;
2625
create table t1 (a varchar(255),
2629
key (a,b,c,d)) engine=innodb;
2631
Warning 1071 Specified key was too long; max key length is 767 bytes
2632
Warning 1071 Specified key was too long; max key length is 767 bytes
2633
Warning 1071 Specified key was too long; max key length is 767 bytes
2634
Warning 1071 Specified key was too long; max key length is 767 bytes
2636
create table t1 (a varchar(255),
2641
key (a,b,c,d,e)) engine=innodb;
2642
ERROR 42000: Specified key was too long; max key length is 3500 bytes
2643
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
2644
create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb;
2645
create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb;
2646
insert into t1 values (0x41),(0x4120),(0x4100);
2647
insert into t3 values (0x41),(0x4120),(0x4100);
2648
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2649
insert into t3 values (0x41),(0x4100);
2650
insert into t4 values (0x41),(0x4120),(0x4100);
2651
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2652
insert into t4 values (0x41),(0x4100);
2653
select hex(s1) from t1;
2658
select hex(s1) from t3;
2662
select hex(s1) from t4;
2666
drop table t1,t3,t4;
2667
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
2668
create table t2 (s1 varbinary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
2669
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
2670
insert into t2 values(0x42);
2671
insert into t2 values(0x41);
2672
select hex(s1) from t2;
2676
update t1 set s1=0x123456 where a=2;
2677
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
2678
select hex(s1) from t2;
2682
update t1 set s1=0x12 where a=1;
2683
update t1 set s1=0x12345678 where a=1;
2684
ERROR 22001: Data too long for column 's1' at row 1
2685
update t1 set s1=0x123457 where a=1;
2686
update t1 set s1=0x1220 where a=1;
2687
select hex(s1) from t2;
2691
update t1 set s1=0x1200 where a=1;
2692
select hex(s1) from t2;
2696
update t1 set s1=0x4200 where a=1;
2697
select hex(s1) from t2;
2701
delete from t1 where a=1;
2702
update t2 set s1=0x4120;
2704
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
2705
delete from t1 where a!=3;
2706
select a,hex(s1) from t1;
2709
select hex(s1) from t2;
2714
create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=innodb;
2715
create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
2716
insert into t1 values(1,0x4100),(2,0x41);
2717
insert into t2 values(0x41);
2718
select hex(s1) from t2;
2721
update t1 set s1=0x1234 where a=1;
2722
select hex(s1) from t2;
2725
update t1 set s1=0x12 where a=2;
2726
select hex(s1) from t2;
2729
delete from t1 where a=1;
2730
delete from t1 where a=2;
2731
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
2732
select a,hex(s1) from t1;
2735
select hex(s1) from t2;
2739
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
2740
CREATE TABLE t2(a INT) ENGINE=InnoDB;
2741
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
2742
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
2743
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
2744
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
2745
SHOW CREATE TABLE t2;
2747
t2 CREATE TABLE `t2` (
2749
KEY `t2_ibfk_0` (`a`)
2753
field1 varchar(8) NOT NULL DEFAULT '',
2754
field2 varchar(8) NOT NULL DEFAULT '',
2755
PRIMARY KEY (field1, field2)
2758
field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
2759
FOREIGN KEY (field1) REFERENCES t1 (field1)
2760
ON DELETE CASCADE ON UPDATE CASCADE
2762
INSERT INTO t1 VALUES ('old', 'somevalu');
2763
INSERT INTO t1 VALUES ('other', 'anyvalue');
2764
INSERT INTO t2 VALUES ('old');
2765
INSERT INTO t2 VALUES ('other');
2766
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
2767
ERROR 23000: Upholding foreign key constraints for table 't1', entry 'other-somevalu', key 1 would lead to a duplicate entry
2780
alter table t1 add constraint c2_fk foreign key (c2)
2781
references t2(c1) on delete cascade;
2782
show create table t1;
2784
t1 CREATE TABLE `t1` (
2785
`c1` bigint NOT NULL,
2786
`c2` bigint NOT NULL,
2788
UNIQUE KEY `c2` (`c2`),
2789
CONSTRAINT `c2_fk` FOREIGN KEY (`c2`) REFERENCES `t2` (`c1`) ON DELETE CASCADE
2791
alter table t1 drop foreign key c2_fk;
2792
show create table t1;
2794
t1 CREATE TABLE `t1` (
2795
`c1` bigint NOT NULL,
2796
`c2` bigint NOT NULL,
2798
UNIQUE KEY `c2` (`c2`)
2801
create table t1(a date) engine=innodb;
2802
create table t2(a date, key(a)) engine=innodb;
2803
insert into t1 values('2005-10-01');
2804
insert into t2 values('2005-10-01');
2805
select * from t1, t2
2806
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
2808
2005-10-01 2005-10-01
2810
create table t1 (id int not null, f_id int not null, f int not null,
2811
primary key(f_id, id)) engine=innodb;
2812
create table t2 (id int not null,s_id int not null,s varchar(200),
2813
primary key(id)) engine=innodb;
2814
INSERT INTO t1 VALUES (8, 1, 3);
2815
INSERT INTO t1 VALUES (1, 2, 1);
2816
INSERT INTO t2 VALUES (1, 0, '');
2817
INSERT INTO t2 VALUES (8, 1, '');
2819
DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
2820
WHERE mm.id IS NULL;
2821
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
2822
where mm.id is null lock in share mode;
2825
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2826
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
2829
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2830
update t1 set b = 5 where b = 1;
2832
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2833
select * from t1 where a = 7 and b = 3 for update;
2839
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2840
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
2843
select * from t1 lock in share mode;
2851
update t1 set b = 5 where b = 1;
2853
select * from t1 where a = 2 and b = 2 for update;
2854
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2858
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2859
insert into t1 values (1,2),(5,3),(4,2);
2860
create table t2(d int not null, e int, primary key(d)) engine=innodb;
2861
insert into t2 values (8,6),(12,1),(3,1);
2864
select * from t2 for update;
2870
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2871
insert into t1 select * from t2;
2872
update t1 set b = (select e from t2 where a = d);
2873
create table t3(d int not null, e int, primary key(d)) engine=innodb
2877
drop table t1, t2, t3;
2878
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2879
insert into t1 values (1,2),(5,3),(4,2);
2880
create table t2(a int not null, b int, primary key(a)) engine=innodb;
2881
insert into t2 values (8,6),(12,1),(3,1);
2882
create table t3(d int not null, b int, primary key(d)) engine=innodb;
2883
insert into t3 values (8,6),(12,1),(3,1);
2884
create table t5(a int not null, b int, primary key(a)) engine=innodb;
2885
insert into t5 values (1,2),(5,3),(4,2);
2886
create table t6(d int not null, e int, primary key(d)) engine=innodb;
2887
insert into t6 values (8,6),(12,1),(3,1);
2888
create table t8(a int not null, b int, primary key(a)) engine=innodb;
2889
insert into t8 values (1,2),(5,3),(4,2);
2890
create table t9(d int not null, e int, primary key(d)) engine=innodb;
2891
insert into t9 values (8,6),(12,1),(3,1);
2894
select * from t2 for update;
2900
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2901
insert into t1 select * from t2;
2903
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2904
update t3 set b = (select b from t2 where a = d);
2906
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2907
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
2909
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2910
insert into t5 (select * from t2 lock in share mode);
2912
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2913
update t6 set e = (select b from t2 where a = d lock in share mode);
2915
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2916
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
2918
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2919
insert into t8 (select * from t2 for update);
2921
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2922
update t9 set e = (select b from t2 where a = d for update);
2924
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2925
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
2926
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2927
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2928
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2929
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2930
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2931
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2932
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2933
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2934
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2936
drop table t1, t2, t3, t5, t6, t8, t9;
2937
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
2938
ERROR HY000: Can't create table 'test.t1' (errno: -1)
2945
b VARCHAR(128) NOT NULL,
2948
KEY idx_t2_b_c (b,c(200)),
2949
CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a)
2953
Warning 1071 Specified key was too long; max key length is 767 bytes
2954
INSERT INTO t1 VALUES (1);
2955
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
2956
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
2957
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
2958
INSERT INTO t2 VALUES (1, 'customer_over', '1');
2959
SELECT * FROM t2 WHERE b = 'customer_over';
2962
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
2965
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
2968
/* Bang: Empty result set, above was expected: */
2969
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2972
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2976
CREATE TABLE t1 ( a int ) ENGINE=innodb;
2978
INSERT INTO t1 VALUES (1);
2980
Table Op Msg_type Msg_text
2981
test.t1 optimize status OK
2983
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
2984
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
2985
CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
2986
ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
2987
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
2988
DELETE CASCADE ON UPDATE CASCADE;
2989
SHOW CREATE TABLE t2;
2991
t2 CREATE TABLE `t2` (
2996
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f`) REFERENCES `t1` (`f`) ON DELETE CASCADE ON UPDATE CASCADE,
2997
CONSTRAINT `t2_t1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
3000
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
3001
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
3002
INSERT INTO t1 VALUES (1);
3003
INSERT INTO t2 VALUES (1);
3004
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
3005
ALTER TABLE t2 MODIFY a INT NOT NULL;
3006
ERROR HY000: Error on rename of '#sql-temporary' to './test/t2' (errno: 150)
3009
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
3011
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
3013
INSERT INTO t1 VALUES ('DDD');
3018
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
3020
INSERT INTO t1 VALUES (0),(347),(0);
3026
SHOW CREATE TABLE t1;
3028
t1 CREATE TABLE `t1` (
3029
`id` int NOT NULL AUTO_INCREMENT,
3031
) ENGINE=InnoDB AUTO_INCREMENT=349
3032
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
3033
INSERT INTO t2 VALUES(42),(347),(348);
3034
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
3035
SHOW CREATE TABLE t1;
3037
t1 CREATE TABLE `t1` (
3038
`id` int NOT NULL AUTO_INCREMENT,
3040
CONSTRAINT `t1_t2` FOREIGN KEY (`id`) REFERENCES `t2` (`id`)
3041
) ENGINE=InnoDB AUTO_INCREMENT=349
3043
DROP TABLE IF EXISTS t1;
3045
Note 1051 Unknown table 't1'
3047
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
3049
INSERT INTO t1 VALUES(-10);
3053
INSERT INTO t1 VALUES(NULL);