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 TEMPORARY 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,
483
dummy_primary_key int NOT NULL auto_increment,
484
PRIMARY KEY (dummy_primary_key)
486
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','2000-09-07 23:06:59',1);
487
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','2000-09-07 23:06:59',2);
488
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','2000-09-07 23:06:59',3);
489
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','2000-09-07 23:06:59',4);
490
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','2000-09-07 23:06:59',5);
491
select user_name, password , subscribed, user_id, quota, weight, access_date, approved, dummy_primary_key from t1 order by user_name;
492
user_name password subscribed user_id quota weight access_date approved dummy_primary_key
493
user_0 somepassword N 0 0 0 2000-09-07 2000-09-07 23:06:59 1
494
user_1 somepassword Y 1 1 1 2000-09-07 2000-09-07 23:06:59 2
495
user_2 somepassword N 2 2 1.4142135623731 2000-09-07 2000-09-07 23:06:59 3
496
user_3 somepassword Y 3 3 1.7320508075689 2000-09-07 2000-09-07 23:06:59 4
497
user_4 somepassword N 4 4 2 2000-09-07 2000-09-07 23:06:59 5
500
id int NOT NULL auto_increment,
501
parent_id int DEFAULT '0' NOT NULL,
502
level int DEFAULT '0' NOT NULL,
504
KEY parent_id (parent_id),
507
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);
508
INSERT INTO t1 values (179,5,2);
509
update t1 set parent_id=parent_id+100;
510
select * from t1 where parent_id=102;
515
update t1 set id=id+1000;
516
update t1 set id=1024 where id=1009;
558
update ignore t1 set id=id+1;
600
update ignore t1 set id=1023 where id=1010;
601
select * from t1 where parent_id=102;
606
explain select level from t1 where level=1;
607
id select_type table type possible_keys key key_len ref rows Extra
608
1 SIMPLE t1 ref level level 4 const # Using index
609
select level,id from t1 where level=1;
617
select level,id,parent_id from t1 where level=1;
625
select level,id from t1 where level=1 order by id;
633
delete from t1 where level=1;
671
sca_code char(6) NOT NULL,
672
cat_code char(6) NOT NULL,
673
sca_desc varchar(50),
674
lan_code char(2) NOT NULL,
675
sca_pic varchar(100),
676
sca_sdesc varchar(50),
677
sca_sch_desc varchar(16),
678
PRIMARY KEY (sca_code, cat_code, lan_code),
679
INDEX sca_pic (sca_pic)
681
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');
682
select count(*) from t1 where sca_code = 'PD';
685
select count(*) from t1 where sca_code <= 'PD';
688
select count(*) from t1 where sca_pic is null;
691
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
692
select count(*) from t1 where sca_code='PD' and sca_pic is null;
695
select count(*) from t1 where cat_code='E';
698
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
699
select count(*) from t1 where sca_code='PD' and sca_pic is null;
702
select count(*) from t1 where sca_pic >= 'n';
705
select sca_pic from t1 where sca_pic is null;
709
update t1 set sca_pic="test" where sca_pic is null;
710
delete from t1 where sca_code='pd';
713
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
714
insert into t1 (a) values(1),(2),(3);
715
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
720
select a from t1 natural join t1 as t2 where b >= @a order by a;
725
update t1 set a=5 where a=1;
732
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
733
insert into t1 values("hello",1),("world",2);
734
select * from t1 order by b desc;
739
Table Op Msg_type Msg_text
740
test.t1 optimize status OK
742
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
743
t1 0 PRIMARY 1 a A # NULL NULL BTREE
745
create table t1 (i int, j int ) ENGINE=innodb;
746
insert into t1 values (1,2);
747
select * from t1 where i=1 and j=2;
750
create index ax1 on t1 (i,j);
751
select * from t1 where i=1 and j=2;
760
INSERT INTO t1 VALUES (1, 1);
761
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
765
CREATE TABLE t1 (a int NOT NULL) engine=innodb;
766
INSERT INTO t1 VALUES (1);
771
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;
772
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);
773
explain select * from t1 where a > 0 and a < 50;
774
id select_type table type possible_keys key key_len ref rows Extra
775
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where
777
create table t1 (a char(20), unique (a(5))) engine=innodb;
779
create table t1 (a char(20), index (a(5))) engine=innodb;
780
show create table t1;
782
t1 CREATE TABLE `t1` (
783
`a` varchar(20) DEFAULT NULL,
787
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
788
insert into t1 values (NULL),(NULL),(NULL);
789
delete from t1 where a=3;
790
insert into t1 values (NULL);
796
alter table t1 add b int;
805
id int auto_increment primary key,
806
name varchar(32) not null,
811
insert into t1 values (1,'one','one value',101),
812
(2,'two','two value',102),(3,'three','three value',103);
813
replace into t1 (value,name,uid) values ('other value','two',102);
814
delete from t1 where uid=102;
815
replace into t1 (value,name,uid) values ('other value','two',102);
816
replace into t1 (value,name,uid) values ('other value','two',102);
820
3 three three value 103
821
6 two other value 102
823
create database mysqltest;
824
create table mysqltest.t1 (a int not null) engine= innodb;
825
insert into mysqltest.t1 values(1);
826
create TEMPORARY table mysqltest.t2 (a int not null) engine= myisam;
827
insert into mysqltest.t2 values(1);
828
create temporary table mysqltest.t3 (a int not null) engine= heap;
829
insert into mysqltest.t3 values(1);
831
drop database mysqltest;
832
show tables from mysqltest;
833
ERROR 42000: Unknown database 'mysqltest'
835
create table t1 (a int not null) engine= innodb;
836
insert into t1 values(1),(2);
843
insert into t1 values(1),(2);
850
create table t1 (a int not null) engine= innodb;
851
insert into t1 values(1),(2);
853
insert into t1 values(1),(2);
859
insert into t1 values(1),(2);
864
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
865
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
866
explain select * from t1 order by a;
867
id select_type table type possible_keys key key_len ref rows Extra
868
1 SIMPLE t1 index NULL PRIMARY 4 NULL #
869
explain select * from t1 order by b;
870
id select_type table type possible_keys key key_len ref rows Extra
871
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
872
explain select * from t1 order by c;
873
id select_type table type possible_keys key key_len ref rows Extra
874
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
875
explain select a from t1 order by a;
876
id select_type table type possible_keys key key_len ref rows Extra
877
1 SIMPLE t1 index NULL PRIMARY 4 NULL # Using index
878
explain select b from t1 order by b;
879
id select_type table type possible_keys key key_len ref rows Extra
880
1 SIMPLE t1 index NULL b 4 NULL # Using index
881
explain select a,b from t1 order by b;
882
id select_type table type possible_keys key key_len ref rows Extra
883
1 SIMPLE t1 index NULL b 4 NULL # Using index
884
explain select a,b from t1;
885
id select_type table type possible_keys key key_len ref rows Extra
886
1 SIMPLE t1 index NULL PRIMARY 4 NULL #
887
explain select a,b,c from t1;
888
id select_type table type possible_keys key key_len ref rows Extra
889
1 SIMPLE t1 ALL NULL NULL NULL NULL #
891
create table t1 (t int not null default 1, key (t)) engine=innodb;
893
Field Type Null Key Default Extra
896
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;
898
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
899
SELECT @@tx_isolation,@@global.tx_isolation;
900
@@tx_isolation @@global.tx_isolation
901
SERIALIZABLE REPEATABLE-READ
902
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
903
select id, code, name from t1 order by id;
910
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
911
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
912
select id, code, name from t1 order by id;
921
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
922
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
923
select id, code, name from t1 order by id;
934
create table t1 (a int, b int) engine=innodb;
935
insert into t1 values(20,null);
936
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
938
b ifnull(t2.b,"this is null")
940
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
941
t2.b=t3.a order by 1;
942
b ifnull(t2.b,"this is null")
944
insert into t1 values(10,null);
945
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
946
t2.b=t3.a order by 1;
947
b ifnull(t2.b,"this is null")
951
create TEMPORARY table t1 (a varchar(10) not null) engine=myisam;
952
create table t2 (b varchar(10) not null unique) engine=innodb;
953
select t1.a from t1,t2 where t1.a=t2.b;
956
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
957
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
958
insert into t1 values (10, 20);
959
insert into t2 values (10, 20);
962
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
963
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
964
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
965
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
967
INSERT INTO t1 VALUES("this-key", "will disappear");
968
INSERT INTO t2 VALUES("this-key", "will also disappear");
969
DELETE FROM t3 WHERE id1="my-test-1";
972
this-key will disappear
975
this-key will also disappear
986
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
992
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
993
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
994
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
1007
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
1008
create table t2 (a int not null auto_increment primary key, b int);
1009
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
1010
insert into t2 (a) select b from t1;
1011
insert into t1 (b) select b from t2;
1012
insert into t2 (a) select b from t1;
1013
insert into t1 (a) select b from t2;
1014
insert into t2 (a) select b from t1;
1015
insert into t1 (a) select b from t2;
1016
insert into t2 (a) select b from t1;
1017
insert into t1 (a) select b from t2;
1018
insert into t2 (a) select b from t1;
1019
insert into t1 (a) select b from t2;
1020
select count(*) from t1;
1023
explain select * from t1 where c between 1 and 2500;
1024
id select_type table type possible_keys key key_len ref rows Extra
1025
1 SIMPLE t1 range c c 5 NULL # Using where
1027
explain select * from t1 where c between 1 and 2500;
1028
id select_type table type possible_keys key key_len ref rows Extra
1029
1 SIMPLE t1 ALL c NULL NULL NULL # Using where
1031
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
1032
insert into t1 (id) values (null),(null),(null),(null),(null);
1033
update t1 set fk=69 where fk is null order by id limit 1;
1042
create table t1 (a int not null, b int not null, key (a));
1043
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);
1045
update t1 set b=(@tmp:=@tmp+1) order by a;
1046
update t1 set b=99 where a=1 order by b asc limit 1;
1047
update t1 set b=100 where a=1 order by b desc limit 2;
1048
update t1 set a=a+10+b where a=1 order by b;
1049
select * from t1 order by a,b;
1065
create table t1 (a integer auto_increment primary key) engine=innodb;
1066
insert into t1 (a) values (NULL),(NULL);
1068
insert into t1 (a) values (NULL),(NULL);
1074
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
1075
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;
1081
foreign key(pid) references t1(id) on delete cascade) engine=innodb;
1082
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
1083
(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
1084
delete from t1 where id=0;
1085
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)
1086
delete from t1 where id=15;
1087
delete from t1 where id=0;
1089
CREATE TABLE t1 (col1 int) ENGINE=InnoDB;
1090
CREATE TABLE t2 (col1 int, stamp TIMESTAMP,INDEX stamp_idx (stamp)) ENGINE=InnoDB;
1091
insert into t1 values (1),(2),(3);
1092
insert into t2 values (1, 20020204110000),(2, 20020204110001),(4,20020204110002 ),(5,20020204110003);
1093
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
1094
'20020204120000' GROUP BY col1;
1103
`id` int NOT NULL auto_increment,
1104
`id_object` int default '0',
1105
`id_version` int NOT NULL default '1',
1106
`label` varchar(100) NOT NULL default '',
1109
KEY `id_object` (`id_object`),
1110
KEY `id_version` (`id_version`)
1112
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);
1114
`id` int NOT NULL auto_increment,
1115
`id_version` int NOT NULL default '1',
1117
KEY `id_version` (`id_version`)
1119
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
1120
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
1121
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
1122
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
1129
3525 Fournisseur Test
1131
create TEMPORARY table t1 (a int, b varchar(200), c text not null) engine=myisam;
1132
create table t2 (a int, b varchar(200), c text not null) engine=innodb;
1133
create table t3 (a int, b varchar(200), c text not null) engine=innodb;
1134
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
1135
insert t2 select * from t1;
1136
insert t3 select * from t1;
1137
checksum table t1, t2, t3, t4 quick;
1144
Error 1146 Table 'test.t4' doesn't exist
1145
checksum table t1, t2, t3, t4;
1152
Error 1146 Table 'test.t4' doesn't exist
1153
checksum table t1, t2, t3, t4 extended;
1160
Error 1146 Table 'test.t4' doesn't exist
1161
drop table t1,t2,t3;
1162
create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
1163
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
1164
select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
1176
create table t1 (a int) engine=innodb;
1177
create table t2 like t1;
1179
create table t1 (id int not null, id2 int not null, unique (id,id2)) engine=innodb;
1180
create table t2 (id int not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
1181
show create table t1;
1183
t1 CREATE TABLE `t1` (
1186
UNIQUE KEY `id` (`id`,`id2`)
1188
show create table t2;
1190
t2 CREATE TABLE `t2` (
1192
KEY `t1_id_fk` (`id`),
1193
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1195
create index id on t2 (id);
1196
show create table t2;
1198
t2 CREATE TABLE `t2` (
1201
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1203
create index id2 on t2 (id);
1204
show create table t2;
1206
t2 CREATE TABLE `t2` (
1210
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1212
drop index id2 on t2;
1213
drop index id on t2;
1214
Got one of the listed errors
1215
show create table t2;
1217
t2 CREATE TABLE `t2` (
1220
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1223
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;
1224
show create table t2;
1226
t2 CREATE TABLE `t2` (
1229
KEY `t1_id_fk` (`id`,`id2`),
1230
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1232
create unique index id on t2 (id,id2);
1233
show create table t2;
1235
t2 CREATE TABLE `t2` (
1238
UNIQUE KEY `id` (`id`,`id2`),
1239
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1242
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;
1243
show create table t2;
1245
t2 CREATE TABLE `t2` (
1248
UNIQUE KEY `id` (`id`,`id2`),
1249
KEY `t1_id_fk` (`id2`,`id`),
1250
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1253
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;
1254
show create table t2;
1256
t2 CREATE TABLE `t2` (
1259
UNIQUE KEY `id` (`id`,`id2`),
1260
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1263
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;
1264
show create table t2;
1266
t2 CREATE TABLE `t2` (
1269
UNIQUE KEY `id` (`id`,`id2`),
1270
KEY `t1_id_fk` (`id2`,`id`),
1271
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1274
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;
1275
show create table t2;
1277
t2 CREATE TABLE `t2` (
1278
`id` int NOT NULL AUTO_INCREMENT,
1281
KEY `id` (`id`,`id2`),
1282
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1285
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;
1286
show create table t2;
1288
t2 CREATE TABLE `t2` (
1289
`id` int NOT NULL AUTO_INCREMENT,
1291
KEY `t1_id_fk` (`id`),
1292
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1294
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1295
show create table t2;
1297
t2 CREATE TABLE `t2` (
1298
`id` int NOT NULL AUTO_INCREMENT,
1300
KEY `id_test` (`id`),
1301
KEY `id_test2` (`id`,`id2`),
1302
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1305
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
1306
ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match
1307
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
1308
show create table t2;
1310
t2 CREATE TABLE `t2` (
1311
`a` int NOT NULL AUTO_INCREMENT,
1312
`b` int DEFAULT NULL,
1314
UNIQUE KEY `b_2` (`b`),
1316
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1319
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;
1320
show create table t2;
1322
t2 CREATE TABLE `t2` (
1323
`a` int NOT NULL AUTO_INCREMENT,
1324
`b` int DEFAULT NULL,
1326
UNIQUE KEY `b` (`b`),
1327
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
1328
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1331
create table t1 (c char(10), index (c,c)) engine=innodb;
1332
ERROR 42S21: Duplicate column name 'c'
1333
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
1334
ERROR 42S21: Duplicate column name 'c1'
1335
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
1336
ERROR 42S21: Duplicate column name 'c1'
1337
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
1338
ERROR 42S21: Duplicate column name 'c1'
1339
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
1340
alter table t1 add key (c1,c1);
1341
ERROR 42S21: Duplicate column name 'c1'
1342
alter table t1 add key (c2,c1,c1);
1343
ERROR 42S21: Duplicate column name 'c1'
1344
alter table t1 add key (c1,c2,c1);
1345
ERROR 42S21: Duplicate column name 'c1'
1346
alter table t1 add key (c1,c1,c2);
1347
ERROR 42S21: Duplicate column name 'c1'
1349
create table t1(a int, b int) engine=innodb;
1350
insert into t1 values ('1111', '3333');
1351
select distinct concat(a, b) from t1;
1355
CREATE TABLE t1 (a_id int NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=InnoDB;
1356
INSERT INTO t1 VALUES (1),(2),(3);
1357
CREATE TABLE t2 (b_id int NOT NULL default '0',b_a int NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
1358
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB;
1359
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
1360
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;
1367
create temporary table t1 (a int) engine=innodb;
1368
insert into t1 values (4711);
1370
insert into t1 values (42);
1375
create table t1 (a int) engine=innodb;
1376
insert into t1 values (4711);
1378
insert into t1 values (42);
1383
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;
1384
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
1385
select * from t1 order by a,b,c,d;
1390
explain select * from t1 order by a,b,c,d;
1391
id select_type table type possible_keys key key_len ref rows Extra
1392
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
1394
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1395
insert into t1 values ('8', '6'), ('4', '7');
1396
select min(a) from t1;
1399
select min(b) from t1 where a='8';
1403
create table t1 (x bigint not null primary key) engine=innodb;
1404
insert into t1(x) values (0x0ffffffffffffff0),(0x0ffffffffffffff1);
1409
select count(*) from t1 where x>0;
1412
select count(*) from t1 where x=0;
1415
select count(*) from t1 where x<0;
1418
select count(*) from t1 where x < -16;
1421
select count(*) from t1 where x = -16;
1424
explain select count(*) from t1 where x > -16;
1425
id select_type table type possible_keys key key_len ref rows Extra
1426
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL 1 Using where; Using index
1427
select count(*) from t1 where x > -16;
1430
select * from t1 where x > -16;
1434
select count(*) from t1 where x = 1152921504606846961;
1438
show variables like "innodb_sync_spin_loops";
1440
innodb_sync_spin_loops 20
1441
set global innodb_sync_spin_loops=1000;
1442
show variables like "innodb_sync_spin_loops";
1444
innodb_sync_spin_loops 1000
1445
set global innodb_sync_spin_loops=0;
1446
show variables like "innodb_sync_spin_loops";
1448
innodb_sync_spin_loops 0
1449
set global innodb_sync_spin_loops=20;
1450
show variables like "innodb_sync_spin_loops";
1452
innodb_sync_spin_loops 20
1453
show variables like "innodb_thread_concurrency";
1455
innodb_thread_concurrency 0
1456
set global innodb_thread_concurrency=1001;
1458
Error 1292 Truncated incorrect thread_concurrency value: '1001'
1459
show variables like "innodb_thread_concurrency";
1461
innodb_thread_concurrency 1000
1462
set global innodb_thread_concurrency=0;
1463
show variables like "innodb_thread_concurrency";
1465
innodb_thread_concurrency 0
1466
set global innodb_thread_concurrency=16;
1467
show variables like "innodb_thread_concurrency";
1469
innodb_thread_concurrency 16
1470
show variables like "innodb_concurrency_tickets";
1472
innodb_concurrency_tickets 500
1473
set global innodb_concurrency_tickets=1000;
1474
show variables like "innodb_concurrency_tickets";
1476
innodb_concurrency_tickets 1000
1477
set global innodb_concurrency_tickets=0;
1479
Error 1292 Truncated incorrect concurrency_tickets value: '0'
1480
show variables like "innodb_concurrency_tickets";
1482
innodb_concurrency_tickets 1
1483
set global innodb_concurrency_tickets=500;
1484
show variables like "innodb_concurrency_tickets";
1486
innodb_concurrency_tickets 500
1487
show variables like "innodb_thread_sleep_delay";
1489
innodb_thread_sleep_delay 10000
1490
set global innodb_thread_sleep_delay=100000;
1491
show variables like "innodb_thread_sleep_delay";
1493
innodb_thread_sleep_delay 100000
1494
set global innodb_thread_sleep_delay=0;
1495
show variables like "innodb_thread_sleep_delay";
1497
innodb_thread_sleep_delay 0
1498
set global innodb_thread_sleep_delay=10000;
1499
show variables like "innodb_thread_sleep_delay";
1501
innodb_thread_sleep_delay 10000
1502
set storage_engine=INNODB;
1503
drop table if exists t1,t2,t3;
1504
--- Testing varchar ---
1505
--- Testing varchar ---
1506
create table t1 (v varchar(10), c char(10), t text);
1507
insert into t1 values('+ ', '+ ', '+ ');
1508
set @a=repeat(' ',20);
1509
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1511
Note 1265 Data truncated for column 'v' at row 1
1512
Note 1265 Data truncated for column 'c' at row 1
1513
select concat('*',v,'*',c,'*',t,'*') from t1;
1514
concat('*',v,'*',c,'*',t,'*')
1517
show create table t1;
1519
t1 CREATE TABLE `t1` (
1520
`v` varchar(10) DEFAULT NULL,
1521
`c` varchar(10) DEFAULT NULL,
1524
create table t2 like t1;
1525
show create table t2;
1527
t2 CREATE TABLE `t2` (
1528
`v` varchar(10) DEFAULT NULL,
1529
`c` varchar(10) DEFAULT NULL,
1532
create table t3 select * from t1;
1533
show create table t3;
1535
t3 CREATE TABLE `t3` (
1536
`v` varchar(10) DEFAULT NULL,
1537
`c` varchar(10) DEFAULT NULL,
1540
alter table t1 modify c varchar(10);
1541
show create table t1;
1543
t1 CREATE TABLE `t1` (
1544
`v` varchar(10) DEFAULT NULL,
1545
`c` varchar(10) DEFAULT NULL,
1548
alter table t1 modify v char(10);
1549
show create table t1;
1551
t1 CREATE TABLE `t1` (
1552
`v` varchar(10) DEFAULT NULL,
1553
`c` varchar(10) DEFAULT NULL,
1556
alter table t1 modify t varchar(10);
1558
Note 1265 Data truncated for column 't' at row 2
1559
show create table t1;
1561
t1 CREATE TABLE `t1` (
1562
`v` varchar(10) DEFAULT NULL,
1563
`c` varchar(10) DEFAULT NULL,
1564
`t` varchar(10) DEFAULT NULL
1566
select concat('*',v,'*',c,'*',t,'*') from t1;
1567
concat('*',v,'*',c,'*',t,'*')
1570
drop table t1,t2,t3;
1571
create table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
1572
show create table t1;
1574
t1 CREATE TABLE `t1` (
1575
`v` varchar(10) DEFAULT NULL,
1576
`c` varchar(10) DEFAULT NULL,
1582
select count(*) from t1;
1585
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
1586
select count(*) from t1 where v='a';
1589
select count(*) from t1 where c='a';
1592
select count(*) from t1 where t='a';
1595
select count(*) from t1 where v='a ';
1598
select count(*) from t1 where c='a ';
1601
select count(*) from t1 where t='a ';
1604
select count(*) from t1 where v between 'a' and 'a ';
1607
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1610
select count(*) from t1 where v like 'a%';
1613
select count(*) from t1 where c like 'a%';
1616
select count(*) from t1 where t like 'a%';
1619
select count(*) from t1 where v like 'a %';
1622
explain select count(*) from t1 where v='a ';
1623
id select_type table type possible_keys key key_len ref rows Extra
1624
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1625
explain select count(*) from t1 where c='a ';
1626
id select_type table type possible_keys key key_len ref rows Extra
1627
1 SIMPLE t1 ref c c 43 const # Using where; Using index
1628
explain select count(*) from t1 where t='a ';
1629
id select_type table type possible_keys key key_len ref rows Extra
1630
1 SIMPLE t1 ref t t 43 const # Using where
1631
explain select count(*) from t1 where v like 'a%';
1632
id select_type table type possible_keys key key_len ref rows Extra
1633
1 SIMPLE t1 range v v 43 NULL # Using where; Using index
1634
explain select count(*) from t1 where v between 'a' and 'a ';
1635
id select_type table type possible_keys key key_len ref rows Extra
1636
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1637
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1638
id select_type table type possible_keys key key_len ref rows Extra
1639
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1640
alter table t1 add unique(v);
1641
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
1642
alter table t1 add key(v);
1643
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
1655
explain select * from t1 where v='a';
1656
id select_type table type possible_keys key key_len ref rows Extra
1657
1 SIMPLE t1 ref v,v_2 # 43 const # Using where
1658
select v,count(*) from t1 group by v limit 10;
1670
select v,count(t) from t1 group by v limit 10;
1682
select v,count(c) from t1 group by v limit 10;
1694
select sql_big_result v,count(t) from t1 group by v limit 10;
1706
select sql_big_result v,count(c) from t1 group by v limit 10;
1718
select c,count(*) from t1 group by c limit 10;
1730
select c,count(t) from t1 group by c limit 10;
1742
select sql_big_result c,count(t) from t1 group by c limit 10;
1754
select t,count(*) from t1 group by t limit 10;
1766
select t,count(t) from t1 group by t limit 10;
1778
select sql_big_result t,count(t) from t1 group by t limit 10;
1790
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
1792
Warning 1071 Specified key was too long; max key length is 767 bytes
1793
show create table t1;
1795
t1 CREATE TABLE `t1` (
1796
`v` varchar(300) DEFAULT NULL,
1797
`c` varchar(10) DEFAULT NULL,
1803
select count(*) from t1 where v='a';
1806
select count(*) from t1 where v='a ';
1809
select count(*) from t1 where v between 'a' and 'a ';
1812
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1815
select count(*) from t1 where v like 'a%';
1818
select count(*) from t1 where v like 'a %';
1821
explain select count(*) from t1 where v='a ';
1822
id select_type table type possible_keys key key_len ref rows Extra
1823
1 SIMPLE t1 ref v v 767 const # Using where
1824
explain select count(*) from t1 where v like 'a%';
1825
id select_type table type possible_keys key key_len ref rows Extra
1826
1 SIMPLE t1 range v v 767 NULL # Using where
1827
explain select count(*) from t1 where v between 'a' and 'a ';
1828
id select_type table type possible_keys key key_len ref rows Extra
1829
1 SIMPLE t1 ref v v 767 const # Using where
1830
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1831
id select_type table type possible_keys key key_len ref rows Extra
1832
1 SIMPLE t1 ref v v 767 const # Using where
1833
explain select * from t1 where v='a';
1834
id select_type table type possible_keys key key_len ref rows Extra
1835
1 SIMPLE t1 ref v v 767 const # Using where
1836
select v,count(*) from t1 group by v limit 10;
1848
select v,count(t) from t1 group by v limit 10;
1860
select sql_big_result v,count(t) from t1 group by v limit 10;
1872
alter table t1 drop key v, add key v (v(30));
1873
show create table t1;
1875
t1 CREATE TABLE `t1` (
1876
`v` varchar(300) DEFAULT NULL,
1877
`c` varchar(10) DEFAULT NULL,
1883
select count(*) from t1 where v='a';
1886
select count(*) from t1 where v='a ';
1889
select count(*) from t1 where v between 'a' and 'a ';
1892
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1895
select count(*) from t1 where v like 'a%';
1898
select count(*) from t1 where v like 'a %';
1901
explain select count(*) from t1 where v='a ';
1902
id select_type table type possible_keys key key_len ref rows Extra
1903
1 SIMPLE t1 ref v v 123 const # Using where
1904
explain select count(*) from t1 where v like 'a%';
1905
id select_type table type possible_keys key key_len ref rows Extra
1906
1 SIMPLE t1 range v v 123 NULL # Using where
1907
explain select count(*) from t1 where v between 'a' and 'a ';
1908
id select_type table type possible_keys key key_len ref rows Extra
1909
1 SIMPLE t1 ref v v 123 const # Using where
1910
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1911
id select_type table type possible_keys key key_len ref rows Extra
1912
1 SIMPLE t1 ref v v 123 const # Using where
1913
explain select * from t1 where v='a';
1914
id select_type table type possible_keys key key_len ref rows Extra
1915
1 SIMPLE t1 ref v v 123 const # Using where
1916
select v,count(*) from t1 group by v limit 10;
1928
select v,count(t) from t1 group by v limit 10;
1940
select sql_big_result v,count(t) from t1 group by v limit 10;
1952
alter table t1 modify v varchar(600), drop key v, add key v (v);
1954
Warning 1071 Specified key was too long; max key length is 767 bytes
1955
show create table t1;
1957
t1 CREATE TABLE `t1` (
1958
`v` varchar(600) DEFAULT NULL,
1959
`c` varchar(10) DEFAULT NULL,
1965
select v,count(*) from t1 group by v limit 10;
1977
select v,count(t) from t1 group by v limit 10;
1989
select sql_big_result v,count(t) from t1 group by v limit 10;
2002
create table t1 (a char(10), unique (a));
2003
insert into t1 values ('a ');
2004
insert into t1 values ('a ');
2005
ERROR 23000: Duplicate entry 'a ' for key 'a'
2006
alter table t1 modify a varchar(10);
2007
insert into t1 values ('a '),('a '),('a '),('a ');
2008
ERROR 23000: Duplicate entry 'a ' for key 'a'
2009
insert into t1 values ('a ');
2010
ERROR 23000: Duplicate entry 'a ' for key 'a'
2011
insert into t1 values ('a ');
2012
ERROR 23000: Duplicate entry 'a ' for key 'a'
2013
insert into t1 values ('a ');
2014
ERROR 23000: Duplicate entry 'a ' for key 'a'
2015
update t1 set a='a ' where a like 'a%';
2016
select concat(a,'.') from t1;
2019
update t1 set a='abc ' where a like 'a ';
2020
select concat(a,'.') from t1;
2023
update t1 set a='a ' where a like 'a %';
2024
select concat(a,'.') from t1;
2027
update t1 set a='a ' where a like 'a ';
2028
select concat(a,'.') from t1;
2032
create table t1 (v varchar(10), c char(10), t text, key(v(5)), key(c(5)), key(t(5)));
2033
show create table t1;
2035
t1 CREATE TABLE `t1` (
2036
`v` varchar(10) DEFAULT NULL,
2037
`c` varchar(10) DEFAULT NULL,
2044
create table t1 (v char(10));
2045
show create table t1;
2047
t1 CREATE TABLE `t1` (
2048
`v` varchar(10) DEFAULT NULL
2051
create table t1 (v varchar(10), c char(10)) row_format=fixed;
2053
Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT.
2054
show create table t1;
2056
t1 CREATE TABLE `t1` (
2057
`v` varchar(10) DEFAULT NULL,
2058
`c` varchar(10) DEFAULT NULL
2059
) ENGINE=InnoDB ROW_FORMAT=FIXED
2060
insert into t1 values('a','a'),('a ','a ');
2061
select concat('*',v,'*',c,'*') from t1;
2062
concat('*',v,'*',c,'*')
2066
create table t1(a int, b varchar(12), key ba(b, a));
2067
insert into t1 values (1, 'A'), (20, NULL);
2068
explain select * from t1 where a=20 and b is null;
2069
id select_type table type possible_keys key key_len ref rows Extra
2070
1 SIMPLE t1 ref ba ba 56 const,const 1 Using where; Using index
2071
select * from t1 where a=20 and b is null;
2075
create table t1 (v varchar(16383), key(v));
2077
Warning 1071 Specified key was too long; max key length is 767 bytes
2079
create table t1 (v varchar(16383));
2080
show create table t1;
2082
t1 CREATE TABLE `t1` (
2083
`v` varchar(16383) DEFAULT NULL
2086
create table t1 (v varchar(16383));
2087
show create table t1;
2089
t1 CREATE TABLE `t1` (
2090
`v` varchar(16383) DEFAULT NULL
2093
set storage_engine=InnoDB;
2094
create table t1 (v varchar(16383)) engine=innodb;
2096
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
2097
insert into t1 values ('8', '6'), ('4', '7');
2098
select min(a) from t1;
2101
select min(b) from t1 where a='8';
2105
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
2106
insert into t1 (b) values (1);
2107
replace into t1 (b) values (2), (1), (3);
2114
insert into t1 (b) values (1);
2115
replace into t1 (b) values (2);
2116
replace into t1 (b) values (1);
2117
replace into t1 (b) values (3);
2124
create table t1 (rowid int not null auto_increment, val int not null,primary
2125
key (rowid), unique(val)) engine=innodb;
2126
replace into t1 (val) values ('1'),('2');
2127
replace into t1 (val) values ('1'),('2');
2128
insert into t1 (val) values ('1'),('2');
2129
ERROR 23000: Duplicate entry '1' for key 'val'
2135
create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
2136
insert into t1 (val) values (1);
2137
update t1 set a=2 where a=1;
2138
insert into t1 (val) values (1);
2139
ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
2144
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
2145
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
2146
SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300;
2149
SELECT GRADE FROM t1 WHERE GRADE= 151;
2154
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
2157
id INTEGER NOT NULL,
2158
FOREIGN KEY (id) REFERENCES t1 (id)
2160
INSERT INTO t1 (id) VALUES (NULL);
2165
INSERT INTO t1 (id) VALUES (NULL);
2171
INSERT INTO t1 (id) VALUES (NULL);
2180
CREATE TEMPORARY TABLE t2
2182
id INT NOT NULL PRIMARY KEY,
2184
FOREIGN KEY (b) REFERENCES test.t1(id)
2186
Got one of the listed errors
2188
create table t1 (col1 varchar(2000), index (col1(767)))
2191
Warning 1071 Specified key was too long; max key length is 767 bytes
2192
create table t2 (col1 char(255), index (col1))
2195
Warning 1071 Specified key was too long; max key length is 767 bytes
2196
create table t4 (col1 varchar(767), index (col1))
2199
Warning 1071 Specified key was too long; max key length is 767 bytes
2200
create table t5 (col1 varchar(190) primary key)
2202
create table t6 (col1 varbinary(254) primary key)
2204
create table t7 (col1 text, index(col1(767)))
2207
Warning 1071 Specified key was too long; max key length is 767 bytes
2208
create table t8 (col1 blob, index(col1(767)))
2210
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
2213
Warning 1071 Specified key was too long; max key length is 767 bytes
2214
Warning 1071 Specified key was too long; max key length is 767 bytes
2215
show create table t9;
2217
t9 CREATE TABLE `t9` (
2218
`col1` varchar(512) DEFAULT NULL,
2219
`col2` varchar(512) DEFAULT NULL,
2220
KEY `col1` (`col1`(191),`col2`(191))
2222
drop table t1, t2, t4, t5, t6, t7, t8, t9;
2223
create table t1 (col1 varchar(768), index(col1))
2226
Warning 1071 Specified key was too long; max key length is 767 bytes
2227
create table t2 (col1 varbinary(768), index(col1))
2230
Warning 1071 Specified key was too long; max key length is 767 bytes
2231
create table t3 (col1 text, index(col1(768)))
2234
Warning 1071 Specified key was too long; max key length is 767 bytes
2235
create table t4 (col1 blob, index(col1(768)))
2238
Warning 1071 Specified key was too long; max key length is 767 bytes
2239
show create table t1;
2241
t1 CREATE TABLE `t1` (
2242
`col1` varchar(768) DEFAULT NULL,
2243
KEY `col1` (`col1`(191))
2245
drop table t1, t2, t3, t4;
2246
create table t1 (col1 varchar(768) primary key)
2248
ERROR 42000: Specified key was too long; max key length is 767 bytes
2249
create table t2 (col1 varbinary(768) primary key)
2251
ERROR 42000: Specified key was too long; max key length is 767 bytes
2252
create table t3 (col1 text, primary key(col1(768)))
2254
ERROR 42000: Specified key was too long; max key length is 767 bytes
2255
create table t4 (col1 blob, primary key(col1(768)))
2257
ERROR 42000: Specified key was too long; max key length is 767 bytes
2265
CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
2267
INSERT INTO t2 VALUES(2);
2268
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2269
INSERT INTO t1 VALUES(1);
2270
INSERT INTO t2 VALUES(1);
2271
DELETE FROM t1 WHERE id = 1;
2272
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2274
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
2275
SET FOREIGN_KEY_CHECKS=0;
2277
SET FOREIGN_KEY_CHECKS=1;
2278
INSERT INTO t2 VALUES(3);
2279
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2281
create table t1(a int not null) engine=innodb;
2282
insert into t1 values (1),(2);
2287
insert into t1 values(3);
2297
create table t1(a int not null) engine=innodb;
2298
insert into t1 values (1),(2);
2304
insert into t1 values(3);
2309
set foreign_key_checks=0;
2310
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
2311
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
2312
ERROR HY000: Can't create table 'test.t1' (errno: 150)
2313
set foreign_key_checks=1;
2315
set foreign_key_checks=0;
2316
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
2317
create table t1(a varchar(10) primary key) engine = innodb;
2318
alter table t1 modify column a int;
2319
Got one of the listed errors
2320
set foreign_key_checks=1;
2322
create table t1(a int primary key) row_format=redundant engine=innodb;
2323
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
2324
create table t3(a int primary key) row_format=compact engine=innodb;
2325
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
2326
insert into t1 values(1);
2327
insert into t3 values(1);
2328
insert into t2 values(2);
2329
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`))
2330
insert into t4 values(2);
2331
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`))
2332
insert into t2 values(1);
2333
insert into t4 values(1);
2335
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`))
2337
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`))
2339
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`))
2341
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`))
2343
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`))
2345
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`))
2350
drop table t4,t3,t2,t1;
2351
create table t1 (a varchar(255),
2355
key (a,b,c,d)) engine=innodb;
2357
Warning 1071 Specified key was too long; max key length is 767 bytes
2358
Warning 1071 Specified key was too long; max key length is 767 bytes
2359
Warning 1071 Specified key was too long; max key length is 767 bytes
2360
Warning 1071 Specified key was too long; max key length is 767 bytes
2362
create table t1 (a varchar(255),
2367
key (a,b,c,d,e)) engine=innodb;
2368
ERROR 42000: Specified key was too long; max key length is 3500 bytes
2369
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
2370
create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb;
2371
create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb;
2372
insert into t1 values (0x41),(0x4120),(0x4100);
2373
insert into t3 values (0x41),(0x4120),(0x4100);
2374
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2375
insert into t3 values (0x41),(0x4100);
2376
insert into t4 values (0x41),(0x4120),(0x4100);
2377
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2378
insert into t4 values (0x41),(0x4100);
2379
select hex(s1) from t1;
2384
select hex(s1) from t3;
2388
select hex(s1) from t4;
2392
drop table t1,t3,t4;
2393
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
2394
create table t2 (s1 varbinary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
2395
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
2396
insert into t2 values(0x42);
2397
insert into t2 values(0x41);
2398
select hex(s1) from t2;
2402
update t1 set s1=0x123456 where a=2;
2403
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)
2404
select hex(s1) from t2;
2408
update t1 set s1=0x12 where a=1;
2409
update t1 set s1=0x12345678 where a=1;
2410
ERROR 22001: Data too long for column 's1' at row 1
2411
update t1 set s1=0x123457 where a=1;
2412
update t1 set s1=0x1220 where a=1;
2413
select hex(s1) from t2;
2417
update t1 set s1=0x1200 where a=1;
2418
select hex(s1) from t2;
2422
update t1 set s1=0x4200 where a=1;
2423
select hex(s1) from t2;
2427
delete from t1 where a=1;
2428
update t2 set s1=0x4120;
2430
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)
2431
delete from t1 where a!=3;
2432
select a,hex(s1) from t1;
2435
select hex(s1) from t2;
2440
create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=innodb;
2441
create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
2442
insert into t1 values(1,0x4100),(2,0x41);
2443
insert into t2 values(0x41);
2444
select hex(s1) from t2;
2447
update t1 set s1=0x1234 where a=1;
2448
select hex(s1) from t2;
2451
update t1 set s1=0x12 where a=2;
2452
select hex(s1) from t2;
2455
delete from t1 where a=1;
2456
delete from t1 where a=2;
2457
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)
2458
select a,hex(s1) from t1;
2461
select hex(s1) from t2;
2465
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
2466
CREATE TABLE t2(a INT) ENGINE=InnoDB;
2467
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
2468
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
2469
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
2470
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
2471
SHOW CREATE TABLE t2;
2473
t2 CREATE TABLE `t2` (
2474
`a` int DEFAULT NULL,
2475
KEY `t2_ibfk_0` (`a`)
2479
field1 varchar(8) NOT NULL DEFAULT '',
2480
field2 varchar(8) NOT NULL DEFAULT '',
2481
PRIMARY KEY (field1, field2)
2484
field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
2485
FOREIGN KEY (field1) REFERENCES t1 (field1)
2486
ON DELETE CASCADE ON UPDATE CASCADE
2488
INSERT INTO t1 VALUES ('old', 'somevalu');
2489
INSERT INTO t1 VALUES ('other', 'anyvalue');
2490
INSERT INTO t2 VALUES ('old');
2491
INSERT INTO t2 VALUES ('other');
2492
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
2493
ERROR 23000: Upholding foreign key constraints for table 't1', entry 'other-somevalu', key 1 would lead to a duplicate entry
2506
alter table t1 add constraint c2_fk foreign key (c2)
2507
references t2(c1) on delete cascade;
2508
show create table t1;
2510
t1 CREATE TABLE `t1` (
2511
`c1` bigint NOT NULL,
2512
`c2` bigint NOT NULL,
2514
UNIQUE KEY `c2` (`c2`),
2515
CONSTRAINT `c2_fk` FOREIGN KEY (`c2`) REFERENCES `t2` (`c1`) ON DELETE CASCADE
2517
alter table t1 drop foreign key c2_fk;
2518
show create table t1;
2520
t1 CREATE TABLE `t1` (
2521
`c1` bigint NOT NULL,
2522
`c2` bigint NOT NULL,
2524
UNIQUE KEY `c2` (`c2`)
2527
create table t1(a date) engine=innodb;
2528
create table t2(a date, key(a)) engine=innodb;
2529
insert into t1 values('2005-10-01');
2530
insert into t2 values('2005-10-01');
2531
select * from t1, t2
2532
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
2534
2005-10-01 2005-10-01
2536
create table t1 (id int not null, f_id int not null, f int not null,
2537
primary key(f_id, id)) engine=innodb;
2538
create table t2 (id int not null,s_id int not null,s varchar(200),
2539
primary key(id)) engine=innodb;
2540
INSERT INTO t1 VALUES (8, 1, 3);
2541
INSERT INTO t1 VALUES (1, 2, 1);
2542
INSERT INTO t2 VALUES (1, 0, '');
2543
INSERT INTO t2 VALUES (8, 1, '');
2545
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
2546
where mm.id is null lock in share mode;
2549
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2550
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
2553
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2554
update t1 set b = 5 where b = 1;
2556
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2557
select * from t1 where a = 7 and b = 3 for update;
2563
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2564
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
2567
select * from t1 lock in share mode;
2575
update t1 set b = 5 where b = 1;
2577
select * from t1 where a = 2 and b = 2 for update;
2578
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2582
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2583
insert into t1 values (1,2),(5,3),(4,2);
2584
create table t2(d int not null, e int, primary key(d)) engine=innodb;
2585
insert into t2 values (8,6),(12,1),(3,1);
2588
select * from t2 for update;
2594
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2595
insert into t1 select * from t2;
2596
update t1 set b = (select e from t2 where a = d);
2597
create table t3(d int not null, e int, primary key(d)) engine=innodb
2601
drop table t1, t2, t3;
2602
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2603
insert into t1 values (1,2),(5,3),(4,2);
2604
create table t2(a int not null, b int, primary key(a)) engine=innodb;
2605
insert into t2 values (8,6),(12,1),(3,1);
2606
create table t3(d int not null, b int, primary key(d)) engine=innodb;
2607
insert into t3 values (8,6),(12,1),(3,1);
2608
create table t5(a int not null, b int, primary key(a)) engine=innodb;
2609
insert into t5 values (1,2),(5,3),(4,2);
2610
create table t6(d int not null, e int, primary key(d)) engine=innodb;
2611
insert into t6 values (8,6),(12,1),(3,1);
2612
create table t8(a int not null, b int, primary key(a)) engine=innodb;
2613
insert into t8 values (1,2),(5,3),(4,2);
2614
create table t9(d int not null, e int, primary key(d)) engine=innodb;
2615
insert into t9 values (8,6),(12,1),(3,1);
2618
select * from t2 for update;
2624
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2625
insert into t1 select * from t2;
2627
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2628
update t3 set b = (select b from t2 where a = d);
2630
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2631
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
2633
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2634
insert into t5 (select * from t2 lock in share mode);
2636
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2637
update t6 set e = (select b from t2 where a = d lock in share mode);
2639
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2640
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
2642
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2643
insert into t8 (select * from t2 for update);
2645
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2646
update t9 set e = (select b from t2 where a = d for update);
2648
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2649
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
2650
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2651
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2652
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2653
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2654
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2655
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2656
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2657
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2658
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2660
drop table t1, t2, t3, t5, t6, t8, t9;
2661
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
2662
ERROR HY000: Can't create table 'test.t1' (errno: -1)
2669
b VARCHAR(128) NOT NULL,
2672
KEY idx_t2_b_c (b,c(200)),
2673
CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a)
2677
Warning 1071 Specified key was too long; max key length is 767 bytes
2678
INSERT INTO t1 VALUES (1);
2679
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
2680
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
2681
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
2682
INSERT INTO t2 VALUES (1, 'customer_over', '1');
2683
SELECT * FROM t2 WHERE b = 'customer_over';
2686
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
2689
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
2692
/* Bang: Empty result set, above was expected: */
2693
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2696
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2700
CREATE TABLE t1 ( a int ) ENGINE=innodb;
2702
INSERT INTO t1 VALUES (1);
2704
Table Op Msg_type Msg_text
2705
test.t1 optimize status OK
2707
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
2708
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
2709
CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
2710
ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
2711
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
2712
DELETE CASCADE ON UPDATE CASCADE;
2713
SHOW CREATE TABLE t2;
2715
t2 CREATE TABLE `t2` (
2720
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f`) REFERENCES `t1` (`f`) ON DELETE CASCADE ON UPDATE CASCADE,
2721
CONSTRAINT `t2_t1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2724
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
2725
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
2726
INSERT INTO t1 VALUES (1);
2727
INSERT INTO t2 VALUES (1);
2728
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
2729
ALTER TABLE t2 MODIFY a INT NOT NULL;
2730
ERROR HY000: Error on rename of '#sql-temporary' to './test/t2' (errno: 150)
2733
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
2735
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
2737
INSERT INTO t1 VALUES ('DDD');
2742
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
2744
INSERT INTO t1 VALUES (NULL),(347),(NULL);
2750
SHOW CREATE TABLE t1;
2752
t1 CREATE TABLE `t1` (
2753
`id` int NOT NULL AUTO_INCREMENT,
2756
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
2757
INSERT INTO t2 VALUES(42),(347),(348);
2758
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
2759
SHOW CREATE TABLE t1;
2761
t1 CREATE TABLE `t1` (
2762
`id` int NOT NULL AUTO_INCREMENT,
2764
CONSTRAINT `t1_t2` FOREIGN KEY (`id`) REFERENCES `t2` (`id`)
2767
DROP TABLE IF EXISTS t1;
2769
Note 1051 Unknown table 't1'
2771
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
2773
INSERT INTO t1 VALUES(-10);
2777
INSERT INTO t1 VALUES(NULL);