1
SET @orig_lock_wait_timeout= @@innodb_lock_wait_timeout;
2
SET GLOBAL innodb_lock_wait_timeout=2;
3
drop table if exists t1,t2,t3,t4;
4
drop database if exists mysqltest;
5
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;
6
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
7
select id, code, name from t1 order by id;
16
update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
17
select id, code, name from t1 order by id;
26
update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
27
select id, code, name from t1 order by id;
38
id int NOT NULL auto_increment,
39
parent_id int DEFAULT '0' NOT NULL,
40
level int DEFAULT '0' NOT NULL,
42
KEY parent_id (parent_id),
45
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);
46
update t1 set parent_id=parent_id+100;
47
select * from t1 where parent_id=102;
52
update t1 set id=id+1000;
53
update t1 set id=1024 where id=1009;
54
Got one of the listed errors
96
update ignore t1 set id=id+1;
138
update ignore t1 set id=1023 where id=1010;
139
select * from t1 where parent_id=102;
144
explain select level from t1 where level=1;
145
id select_type table type possible_keys key key_len ref rows Extra
146
1 SIMPLE t1 ref level level 4 const # Using index
147
explain select level,id from t1 where level=1;
148
id select_type table type possible_keys key key_len ref rows Extra
149
1 SIMPLE t1 ref level level 4 const # Using index
150
explain select level,id,parent_id from t1 where level=1;
151
id select_type table type possible_keys key key_len ref rows Extra
152
1 SIMPLE t1 ref level level 4 const #
153
select level,id from t1 where level=1;
161
select level,id,parent_id from t1 where level=1;
169
alter table t1 ENGINE=innodb;
171
Table Unique Key_name Seq_in_index Column_name
173
t1 NO parent_id 1 parent_id
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);
191
alter table t1 engine=innodb;
192
delete from t1 where a = 1;
197
Table Op Msg_type Msg_text
198
test.t1 check status OK
200
create table t1 (a int,b varchar(20)) engine=innodb;
201
insert into t1 values (1,""), (2,"testing");
202
delete from t1 where a = 1;
206
create index skr on t1 (a);
207
insert into t1 values (3,""), (4,"testing");
209
Table Op Msg_type Msg_text
210
test.t1 analyze status OK
212
Table Unique Key_name Seq_in_index Column_name
215
create table t1 (a int,b varchar(20),key(a)) engine=innodb;
216
insert into t1 values (1,""), (2,"testing");
217
select * from t1 where a = 1;
221
create table t1 (n int not null primary key) engine=innodb;
223
insert into t1 values (4);
225
select n, "after rollback" from t1;
227
insert into t1 values (4);
229
select n, "after commit" from t1;
233
insert into t1 values (5);
234
insert into t1 values (4);
235
ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
237
select n, "after commit" from t1;
242
insert into t1 values (6);
243
insert into t1 values (4);
244
ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
252
savepoint `my_savepoint`;
253
insert into t1 values (7);
255
insert into t1 values (3);
264
rollback to savepoint savept2;
265
rollback to savepoint savept3;
266
ERROR 42000: SAVEPOINT savept3 does not exist
267
rollback to savepoint savept2;
268
release savepoint `my_savepoint`;
275
rollback to savepoint `my_savepoint`;
276
ERROR 42000: SAVEPOINT my_savepoint does not exist
277
rollback to savepoint savept2;
278
insert into t1 values (8);
285
create table t1 (n int not null primary key) engine=innodb;
287
insert into t1 values (4);
288
flush tables with read lock;
296
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
298
insert into t1 values(1,'hamdouni');
299
select id as afterbegin_id,nom as afterbegin_nom from t1;
300
afterbegin_id afterbegin_nom
303
select id as afterrollback_id,nom as afterrollback_nom from t1;
304
afterrollback_id afterrollback_nom
306
insert into t1 values(2,'mysql');
307
select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
308
afterautocommit0_id afterautocommit0_nom
311
select id as afterrollback_id,nom as afterrollback_nom from t1;
312
afterrollback_id afterrollback_nom
315
CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
316
insert into t1 values ('pippo', 12);
317
insert into t1 values ('pippo', 12);
318
ERROR 23000: Duplicate entry 'pippo' for key 'PRIMARY'
320
delete from t1 where id = 'pippo';
323
insert into t1 values ('pippo', 12);
335
create table t1 (a integer) engine=innodb;
337
rename table t1 to t2;
338
create table t1 (b integer) engine=innodb;
339
insert into t1 values (1);
342
rename table t2 to t1;
345
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
346
INSERT INTO t1 VALUES (1, 'Jochen');
351
CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
353
INSERT INTO t1 SET _userid='marc@anyware.co.uk';
358
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
364
user_id int DEFAULT '0' NOT NULL,
367
ref_email varchar(100) DEFAULT '' NOT NULL,
369
PRIMARY KEY (user_id,ref_email)
371
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');
372
select * from t1 where user_id=10292;
373
user_id name phone ref_email detail
374
10292 sanjeev 29153373 sansh777@hotmail.com xxx
375
10292 shirish 2333604 shirish@yahoo.com ddsds
376
10292 sonali 323232 sonali@bolly.com filmstar
377
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
378
select * from t1 where user_id=10292;
379
user_id name phone ref_email detail
380
10292 sanjeev 29153373 sansh777@hotmail.com xxx
381
10292 shirish 2333604 shirish@yahoo.com ddsds
382
10292 sonali 323232 sonali@bolly.com filmstar
383
select * from t1 where user_id>=10292;
384
user_id name phone ref_email detail
385
10292 sanjeev 29153373 sansh777@hotmail.com xxx
386
10292 shirish 2333604 shirish@yahoo.com ddsds
387
10292 sonali 323232 sonali@bolly.com filmstar
388
10293 shirish 2333604 shirish@yahoo.com ddsds
389
select * from t1 where user_id>10292;
390
user_id name phone ref_email detail
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
10291 sanjeev 29153373 sansh777@hotmail.com xxx
396
CREATE TABLE t1 (a int not null, b int not null,c int not null,
397
key(a),primary key(a,b), unique(c),key(a),unique(b));
399
Table Unique Key_name Seq_in_index Column_name
407
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
408
alter table t1 engine=innodb;
409
insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
417
update t1 set col2='7' where col1='4';
425
alter table t1 add co3 int not null;
433
update t1 set col2='9' where col1='2';
442
create table t1 (a int not null , b int, primary key (a)) engine = innodb;
443
create TEMPORARY table t2 (a int not null , b int, primary key (a)) engine = myisam;
444
insert into t1 VALUES (1,3) , (2,3), (3,3);
450
insert into t2 select * from t1;
456
delete from t1 where b = 3;
459
insert into t1 select * from t2;
472
user_name varchar(12),
475
user_id int DEFAULT '0' NOT NULL,
480
dummy_primary_key int NOT NULL auto_increment,
481
PRIMARY KEY (dummy_primary_key)
483
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','2000-09-07 23:06:59',1);
484
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','2000-09-07 23:06:59',2);
485
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','2000-09-07 23:06:59',3);
486
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','2000-09-07 23:06:59',4);
487
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','2000-09-07 23:06:59',5);
488
select user_name, password , subscribed, user_id, quota, weight, access_date, approved, dummy_primary_key from t1 order by user_name;
489
user_name password subscribed user_id quota weight access_date approved dummy_primary_key
490
user_0 somepassword N 0 0 0 2000-09-07 2000-09-07 23:06:59 1
491
user_1 somepassword Y 1 1 1 2000-09-07 2000-09-07 23:06:59 2
492
user_2 somepassword N 2 2 1.4142135623731 2000-09-07 2000-09-07 23:06:59 3
493
user_3 somepassword Y 3 3 1.7320508075689 2000-09-07 2000-09-07 23:06:59 4
494
user_4 somepassword N 4 4 2 2000-09-07 2000-09-07 23:06:59 5
497
id int NOT NULL auto_increment,
498
parent_id int DEFAULT '0' NOT NULL,
499
level int DEFAULT '0' NOT NULL,
501
KEY parent_id (parent_id),
504
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);
505
INSERT INTO t1 values (179,5,2);
506
update t1 set parent_id=parent_id+100;
507
select * from t1 where parent_id=102;
512
update t1 set id=id+1000;
513
update t1 set id=1024 where id=1009;
555
update ignore t1 set id=id+1;
597
update ignore t1 set id=1023 where id=1010;
598
select * from t1 where parent_id=102;
603
explain select level from t1 where level=1;
604
id select_type table type possible_keys key key_len ref rows Extra
605
1 SIMPLE t1 ref level level 4 const # Using index
606
select level,id from t1 where level=1;
614
select level,id,parent_id from t1 where level=1;
622
select level,id from t1 where level=1 order by id;
630
delete from t1 where level=1;
668
sca_code char(6) NOT NULL,
669
cat_code char(6) NOT NULL,
670
sca_desc varchar(50),
671
lan_code char(2) NOT NULL,
672
sca_pic varchar(100),
673
sca_sdesc varchar(50),
674
sca_sch_desc varchar(16),
675
PRIMARY KEY (sca_code, cat_code, lan_code),
676
INDEX sca_pic (sca_pic)
678
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');
679
select count(*) from t1 where sca_code = 'PD';
682
select count(*) from t1 where sca_code <= 'PD';
685
select count(*) from t1 where sca_pic is null;
688
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
689
select count(*) from t1 where sca_code='PD' and sca_pic is null;
692
select count(*) from t1 where cat_code='E';
695
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
696
select count(*) from t1 where sca_code='PD' and sca_pic is null;
699
select count(*) from t1 where sca_pic >= 'n';
702
select sca_pic from t1 where sca_pic is null;
706
update t1 set sca_pic="test" where sca_pic is null;
707
delete from t1 where sca_code='pd';
710
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
711
insert into t1 (a) values(1),(2),(3);
712
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
717
select a from t1 natural join t1 as t2 where b >= @a order by a;
722
update t1 set a=5 where a=1;
729
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
730
insert into t1 values("hello",1),("world",2);
731
select * from t1 order by b desc;
735
alter table t1 engine=innodb;
737
Table Unique Key_name Seq_in_index Column_name
740
create table t1 (i int, j int ) ENGINE=innodb;
741
insert into t1 values (1,2);
742
select * from t1 where i=1 and j=2;
745
create index ax1 on t1 (i,j);
746
select * from t1 where i=1 and j=2;
755
INSERT INTO t1 VALUES (1, 1);
756
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
760
CREATE TABLE t1 (a int NOT NULL) engine=innodb;
761
INSERT INTO t1 VALUES (1);
766
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;
767
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);
768
explain select * from t1 where a > 0 and a < 50;
769
id select_type table type possible_keys key key_len ref rows Extra
770
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where
772
create table t1 (a char(20), unique (a(5))) engine=innodb;
774
create table t1 (a char(20), index (a(5))) engine=innodb;
775
show create table t1;
777
t1 CREATE TABLE `t1` (
778
`a` VARCHAR(20) COLLATE utf8_general_ci DEFAULT NULL,
780
) ENGINE=InnoDB COLLATE = utf8_general_ci
782
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
783
insert into t1 values (NULL),(NULL),(NULL);
784
delete from t1 where a=3;
785
insert into t1 values (NULL);
791
alter table t1 add b int;
800
id int auto_increment primary key,
801
name varchar(32) not null,
806
insert into t1 values (1,'one','one value',101),
807
(2,'two','two value',102),(3,'three','three value',103);
808
replace into t1 (value,name,uid) values ('other value','two',102);
809
delete from t1 where uid=102;
810
replace into t1 (value,name,uid) values ('other value','two',102);
811
replace into t1 (value,name,uid) values ('other value','two',102);
815
3 three three value 103
816
6 two other value 102
818
create database mysqltest;
819
create table mysqltest.t1 (a int not null) engine= innodb;
820
insert into mysqltest.t1 values(1);
821
create TEMPORARY table mysqltest.t2 (a int not null) engine= myisam;
822
insert into mysqltest.t2 values(1);
823
create temporary table mysqltest.t3 (a int not null) engine= MEMORY;
824
insert into mysqltest.t3 values(1);
826
drop database mysqltest;
827
show tables from mysqltest;
828
ERROR 42000: Unknown database 'mysqltest'
830
create table t1 (a int not null) engine= innodb;
831
insert into t1 values(1),(2);
838
insert into t1 values(1),(2);
845
create table t1 (a int not null) engine= innodb;
846
insert into t1 values(1),(2);
848
insert into t1 values(1),(2);
854
insert into t1 values(1),(2);
859
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
860
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
861
explain select * from t1 order by a;
862
id select_type table type possible_keys key key_len ref rows Extra
863
1 SIMPLE t1 index NULL PRIMARY 4 NULL #
864
explain select * from t1 order by b;
865
id select_type table type possible_keys key key_len ref rows Extra
866
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
867
explain select * from t1 order by c;
868
id select_type table type possible_keys key key_len ref rows Extra
869
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
870
explain select a from t1 order by a;
871
id select_type table type possible_keys key key_len ref rows Extra
872
1 SIMPLE t1 index NULL PRIMARY 4 NULL # Using index
873
explain select b from t1 order by b;
874
id select_type table type possible_keys key key_len ref rows Extra
875
1 SIMPLE t1 index NULL b 4 NULL # Using index
876
explain select a,b from t1 order by b;
877
id select_type table type possible_keys key key_len ref rows Extra
878
1 SIMPLE t1 index NULL b 4 NULL # Using index
879
explain select a,b from t1;
880
id select_type table type possible_keys key key_len ref rows Extra
881
1 SIMPLE t1 index NULL PRIMARY 4 NULL #
882
explain select a,b,c from t1;
883
id select_type table type possible_keys key key_len ref rows Extra
884
1 SIMPLE t1 ALL NULL NULL NULL NULL #
886
create table t1 (t int not null default 1, key (t)) engine=innodb;
888
Field Type Null Default Default_is_NULL On_Update
891
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;
893
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
894
SELECT @@tx_isolation,@@global.tx_isolation;
895
@@tx_isolation @@global.tx_isolation
896
SERIALIZABLE REPEATABLE-READ
897
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
898
select id, code, name from t1 order by id;
905
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
906
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
907
select id, code, name from t1 order by id;
916
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
917
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
918
select id, code, name from t1 order by id;
929
create table t1 (a int, b int) engine=innodb;
930
insert into t1 values(20,null);
931
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
933
b ifnull(t2.b,"this is null")
935
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
936
t2.b=t3.a order by 1;
937
b ifnull(t2.b,"this is null")
939
insert into t1 values(10,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")
946
create TEMPORARY table t1 (a varchar(10) not null) engine=myisam;
947
create table t2 (b varchar(10) not null unique) engine=innodb;
948
select t1.a from t1,t2 where t1.a=t2.b;
951
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
952
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
953
insert into t1 values (10, 20);
954
insert into t2 values (10, 20);
957
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
958
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
959
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
960
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
962
INSERT INTO t1 VALUES("this-key", "will disappear");
963
INSERT INTO t2 VALUES("this-key", "will also disappear");
964
DELETE FROM t3 WHERE id1="my-test-1";
967
this-key will disappear
970
this-key will also disappear
981
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
987
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
988
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
989
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
1002
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
1003
create table t2 (a int not null auto_increment primary key, b int);
1004
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
1005
insert into t2 (a) select b from t1;
1006
insert into t1 (b) select b from t2;
1007
insert into t2 (a) select b from t1;
1008
insert into t1 (a) select b from t2;
1009
insert into t2 (a) select b from t1;
1010
insert into t1 (a) select b from t2;
1011
insert into t2 (a) select b from t1;
1012
insert into t1 (a) select b from t2;
1013
insert into t2 (a) select b from t1;
1014
insert into t1 (a) select b from t2;
1015
select count(*) from t1;
1018
explain select * from t1 where c between 1 and 2500;
1019
id select_type table type possible_keys key key_len ref rows Extra
1020
1 SIMPLE t1 range c c 5 NULL # Using where
1022
explain select * from t1 where c between 1 and 2500;
1023
id select_type table type possible_keys key key_len ref rows Extra
1024
1 SIMPLE t1 ALL c NULL NULL NULL # Using where
1026
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
1027
insert into t1 (id) values (null),(null),(null),(null),(null);
1028
update t1 set fk=69 where fk is null order by id limit 1;
1037
create table t1 (a int not null, b int not null, key (a));
1038
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);
1040
update t1 set b=(@tmp:=@tmp+1) order by a;
1041
update t1 set b=99 where a=1 order by b asc limit 1;
1042
update t1 set b=100 where a=1 order by b desc limit 2;
1043
update t1 set a=a+10+b where a=1 order by b;
1044
select * from t1 order by a,b;
1060
create table t1 (a integer auto_increment primary key) engine=innodb;
1061
insert into t1 (a) values (NULL),(NULL);
1063
insert into t1 (a) values (NULL),(NULL);
1069
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
1070
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;
1076
foreign key(pid) references t1(id) on delete cascade) engine=innodb;
1077
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
1078
(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
1079
delete from t1 where id=0;
1080
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)
1081
delete from t1 where id=15;
1082
delete from t1 where id=0;
1084
CREATE TABLE t1 (col1 int) ENGINE=InnoDB;
1085
CREATE TABLE t2 (col1 int, stamp TIMESTAMP,INDEX stamp_idx (stamp)) ENGINE=InnoDB;
1086
insert into t1 values (1),(2),(3);
1087
insert into t2 values (1, 20020204110000),(2, 20020204110001),(4,20020204110002 ),(5,20020204110003);
1088
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
1089
'20020204120000' GROUP BY col1;
1098
`id` int NOT NULL auto_increment,
1099
`id_object` int default '0',
1100
`id_version` int NOT NULL default '1',
1101
`label` varchar(100) NOT NULL default '',
1104
KEY `id_object` (`id_object`),
1105
KEY `id_version` (`id_version`)
1107
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);
1109
`id` int NOT NULL auto_increment,
1110
`id_version` int NOT NULL default '1',
1112
KEY `id_version` (`id_version`)
1114
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
1115
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
1116
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
1117
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
1124
3525 Fournisseur Test
1126
create TEMPORARY table t1 (a int, b varchar(200), c text not null) engine=myisam;
1127
create table t2 (a int, b varchar(200), c text not null) engine=innodb;
1128
create table t3 (a int, b varchar(200), c text not null) engine=innodb;
1129
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
1130
insert t2 select * from t1;
1131
insert t3 select * from t1;
1132
drop table t1,t2,t3;
1133
create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
1134
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
1135
select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
1147
create table t1 (a int) engine=innodb;
1148
create table t2 like t1;
1150
create table t1 (id int not null, id2 int not null, unique (id,id2)) engine=innodb;
1151
create table t2 (id int not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
1152
show create table t1;
1154
t1 CREATE TABLE `t1` (
1157
UNIQUE KEY `id` (`id`,`id2`)
1158
) ENGINE=InnoDB COLLATE = utf8_general_ci
1159
show create table t2;
1161
t2 CREATE TABLE `t2` (
1163
KEY `t1_id_fk` (`id`),
1164
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1165
) ENGINE=InnoDB COLLATE = utf8_general_ci
1166
create index id on t2 (id);
1167
show create table t2;
1169
t2 CREATE TABLE `t2` (
1172
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1173
) ENGINE=InnoDB COLLATE = utf8_general_ci
1174
create index id2 on t2 (id);
1175
show create table t2;
1177
t2 CREATE TABLE `t2` (
1181
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1182
) ENGINE=InnoDB COLLATE = utf8_general_ci
1183
drop index id2 on t2;
1184
drop index id on t2;
1185
Got one of the listed errors
1186
show create table t2;
1188
t2 CREATE TABLE `t2` (
1191
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1192
) ENGINE=InnoDB COLLATE = utf8_general_ci
1194
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;
1195
show create table t2;
1197
t2 CREATE TABLE `t2` (
1200
KEY `t1_id_fk` (`id`,`id2`),
1201
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1202
) ENGINE=InnoDB COLLATE = utf8_general_ci
1203
create unique index id on t2 (id,id2);
1204
show create table t2;
1206
t2 CREATE TABLE `t2` (
1209
UNIQUE KEY `id` (`id`,`id2`),
1210
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1211
) ENGINE=InnoDB COLLATE = utf8_general_ci
1213
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;
1214
show create table t2;
1216
t2 CREATE TABLE `t2` (
1219
UNIQUE KEY `id` (`id`,`id2`),
1220
KEY `t1_id_fk` (`id2`,`id`),
1221
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1222
) ENGINE=InnoDB COLLATE = utf8_general_ci
1224
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;
1225
show create table t2;
1227
t2 CREATE TABLE `t2` (
1230
UNIQUE KEY `id` (`id`,`id2`),
1231
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1232
) ENGINE=InnoDB COLLATE = utf8_general_ci
1234
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;
1235
show create table t2;
1237
t2 CREATE TABLE `t2` (
1240
UNIQUE KEY `id` (`id`,`id2`),
1241
KEY `t1_id_fk` (`id2`,`id`),
1242
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1243
) ENGINE=InnoDB COLLATE = utf8_general_ci
1245
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;
1246
show create table t2;
1248
t2 CREATE TABLE `t2` (
1249
`id` INT NOT NULL AUTO_INCREMENT,
1252
KEY `id` (`id`,`id2`),
1253
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1254
) ENGINE=InnoDB COLLATE = utf8_general_ci
1256
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;
1257
show create table t2;
1259
t2 CREATE TABLE `t2` (
1260
`id` INT NOT NULL AUTO_INCREMENT,
1262
KEY `t1_id_fk` (`id`),
1263
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1264
) ENGINE=InnoDB COLLATE = utf8_general_ci
1265
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1266
show create table t2;
1268
t2 CREATE TABLE `t2` (
1269
`id` INT NOT NULL AUTO_INCREMENT,
1271
KEY `id_test` (`id`),
1272
KEY `id_test2` (`id`,`id2`),
1273
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1274
) ENGINE=InnoDB COLLATE = utf8_general_ci
1276
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
1277
ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match
1278
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
1279
show create table t2;
1281
t2 CREATE TABLE `t2` (
1282
`a` INT NOT NULL AUTO_INCREMENT,
1283
`b` INT DEFAULT NULL,
1285
UNIQUE KEY `b_2` (`b`),
1287
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1288
) ENGINE=InnoDB COLLATE = utf8_general_ci
1290
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;
1291
show create table t2;
1293
t2 CREATE TABLE `t2` (
1294
`a` INT NOT NULL AUTO_INCREMENT,
1295
`b` INT DEFAULT NULL,
1297
UNIQUE KEY `b` (`b`),
1298
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
1299
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1300
) ENGINE=InnoDB COLLATE = utf8_general_ci
1302
create table t1 (c char(10), index (c,c)) engine=innodb;
1303
ERROR 42S21: Duplicate column name 'c'
1304
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
1305
ERROR 42S21: Duplicate column name 'c1'
1306
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
1307
ERROR 42S21: Duplicate column name 'c1'
1308
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
1309
ERROR 42S21: Duplicate column name 'c1'
1310
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
1311
alter table t1 add key (c1,c1);
1312
ERROR 42S21: Duplicate column name 'c1'
1313
alter table t1 add key (c2,c1,c1);
1314
ERROR 42S21: Duplicate column name 'c1'
1315
alter table t1 add key (c1,c2,c1);
1316
ERROR 42S21: Duplicate column name 'c1'
1317
alter table t1 add key (c1,c1,c2);
1318
ERROR 42S21: Duplicate column name 'c1'
1320
create table t1(a int, b int) engine=innodb;
1321
insert into t1 values ('1111', '3333');
1322
select distinct concat(a, b) from t1;
1326
CREATE TABLE t1 (a_id int NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=InnoDB;
1327
INSERT INTO t1 VALUES (1),(2),(3);
1328
CREATE TABLE t2 (b_id int NOT NULL default '0',b_a int NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
1329
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB;
1330
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
1331
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;
1338
create temporary table t1 (a int) engine=innodb;
1339
insert into t1 values (4711);
1341
insert into t1 values (42);
1346
create table t1 (a int) engine=innodb;
1347
insert into t1 values (4711);
1349
insert into t1 values (42);
1354
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;
1355
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
1356
select * from t1 order by a,b,c,d;
1361
explain select * from t1 order by a,b,c,d;
1362
id select_type table type possible_keys key key_len ref rows Extra
1363
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
1365
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1366
insert into t1 values ('8', '6'), ('4', '7');
1367
select min(a) from t1;
1370
select min(b) from t1 where a='8';
1374
create table t1 (x bigint not null primary key) engine=innodb;
1375
insert into t1(x) values (0x0ffffffffffffff0),(0x0ffffffffffffff1);
1380
select count(*) from t1 where x>0;
1383
select count(*) from t1 where x=0;
1386
select count(*) from t1 where x<0;
1389
select count(*) from t1 where x < -16;
1392
select count(*) from t1 where x = -16;
1395
explain select count(*) from t1 where x > -16;
1396
id select_type table type possible_keys key key_len ref rows Extra
1397
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL 1 Using where; Using index
1398
select count(*) from t1 where x > -16;
1401
select * from t1 where x > -16;
1405
select count(*) from t1 where x = 1152921504606846961;
1409
show status like "Innodb_buffer_pool_pages_total";
1411
show status like "Innodb_page_size";
1413
show status like "Innodb_rows_deleted";
1415
show status like "Innodb_rows_inserted";
1417
show status like "Innodb_rows_updated";
1419
show status like "Innodb_row_lock_waits";
1421
show status like "Innodb_row_lock_current_waits";
1423
show status like "Innodb_row_lock_time";
1425
show status like "Innodb_row_lock_time_max";
1427
show status like "Innodb_row_lock_time_avg";
1429
show variables like "innodb_sync_spin_loops";
1431
innodb_sync_spin_loops 30
1432
set global innodb_sync_spin_loops=1000;
1433
show variables like "innodb_sync_spin_loops";
1435
innodb_sync_spin_loops 1000
1436
set global innodb_sync_spin_loops=0;
1437
show variables like "innodb_sync_spin_loops";
1439
innodb_sync_spin_loops 0
1440
set global innodb_sync_spin_loops=20;
1441
show variables like "innodb_sync_spin_loops";
1443
innodb_sync_spin_loops 20
1444
show variables like "innodb_thread_concurrency";
1446
innodb_thread_concurrency 0
1447
set global innodb_thread_concurrency=1001;
1449
Error 1292 Truncated incorrect thread_concurrency value: '1001'
1450
show variables like "innodb_thread_concurrency";
1452
innodb_thread_concurrency 1000
1453
set global innodb_thread_concurrency=0;
1454
show variables like "innodb_thread_concurrency";
1456
innodb_thread_concurrency 0
1457
set global innodb_thread_concurrency=16;
1458
show variables like "innodb_thread_concurrency";
1460
innodb_thread_concurrency 16
1461
show variables like "innodb_concurrency_tickets";
1463
innodb_concurrency_tickets 500
1464
set global innodb_concurrency_tickets=1000;
1465
show variables like "innodb_concurrency_tickets";
1467
innodb_concurrency_tickets 1000
1468
set global innodb_concurrency_tickets=0;
1470
Error 1292 Truncated incorrect concurrency_tickets value: '0'
1471
show variables like "innodb_concurrency_tickets";
1473
innodb_concurrency_tickets 1
1474
set global innodb_concurrency_tickets=500;
1475
show variables like "innodb_concurrency_tickets";
1477
innodb_concurrency_tickets 500
1478
show variables like "innodb_thread_sleep_delay";
1480
innodb_thread_sleep_delay 10000
1481
set global innodb_thread_sleep_delay=100000;
1482
show variables like "innodb_thread_sleep_delay";
1484
innodb_thread_sleep_delay 100000
1485
set global innodb_thread_sleep_delay=0;
1486
show variables like "innodb_thread_sleep_delay";
1488
innodb_thread_sleep_delay 0
1489
set global innodb_thread_sleep_delay=10000;
1490
show variables like "innodb_thread_sleep_delay";
1492
innodb_thread_sleep_delay 10000
1493
set storage_engine=INNODB;
1494
drop table if exists t1,t2,t3;
1495
--- Testing varchar ---
1496
--- Testing varchar ---
1497
create table t1 (v varchar(10), c char(10), t text);
1498
insert into t1 values('+ ', '+ ', '+ ');
1499
set @a=repeat(' ',20);
1500
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1501
ERROR 22001: Data too long for column 'v' at row 1
1502
set @a=repeat(' ',10);
1503
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1504
ERROR 22001: Data too long for column 'v' at row 1
1505
set @a=repeat(' ',9);
1506
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1507
select concat('*',v,'*',c,'*',t,'*') from t1;
1508
concat('*',v,'*',c,'*',t,'*')
1511
show create table t1;
1513
t1 CREATE TABLE `t1` (
1514
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1515
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1516
`t` TEXT COLLATE utf8_general_ci
1517
) ENGINE=InnoDB COLLATE = utf8_general_ci
1518
create table t2 like t1;
1519
show create table t2;
1521
t2 CREATE TABLE `t2` (
1522
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1523
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1524
`t` TEXT COLLATE utf8_general_ci
1525
) ENGINE=InnoDB COLLATE = utf8_general_ci
1526
create table t3 select * from t1;
1527
show create table t3;
1529
t3 CREATE TABLE `t3` (
1530
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1531
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1532
`t` TEXT COLLATE utf8_general_ci
1533
) ENGINE=InnoDB COLLATE = utf8_general_ci
1534
alter table t1 modify c varchar(10);
1535
show create table t1;
1537
t1 CREATE TABLE `t1` (
1538
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1539
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1540
`t` TEXT COLLATE utf8_general_ci
1541
) ENGINE=InnoDB COLLATE = utf8_general_ci
1542
alter table t1 modify v char(10);
1543
show create table t1;
1545
t1 CREATE TABLE `t1` (
1546
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1547
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1548
`t` TEXT COLLATE utf8_general_ci
1549
) ENGINE=InnoDB COLLATE = utf8_general_ci
1550
alter table t1 modify t varchar(10);
1551
show create table t1;
1553
t1 CREATE TABLE `t1` (
1554
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1555
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1556
`t` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
1557
) ENGINE=InnoDB COLLATE = utf8_general_ci
1558
select concat('*',v,'*',c,'*',t,'*') from t1;
1559
concat('*',v,'*',c,'*',t,'*')
1562
drop table t1,t2,t3;
1563
create table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
1564
show create table t1;
1566
t1 CREATE TABLE `t1` (
1567
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1568
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1569
`t` TEXT COLLATE utf8_general_ci,
1573
) ENGINE=InnoDB COLLATE = utf8_general_ci
1574
select count(*) from t1;
1577
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
1578
select count(*) from t1 where v='a';
1581
select count(*) from t1 where c='a';
1584
select count(*) from t1 where t='a';
1587
select count(*) from t1 where v='a ';
1590
select count(*) from t1 where c='a ';
1593
select count(*) from t1 where t='a ';
1596
select count(*) from t1 where v between 'a' and 'a ';
1599
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1602
select count(*) from t1 where v like 'a%';
1605
select count(*) from t1 where c like 'a%';
1608
select count(*) from t1 where t like 'a%';
1611
select count(*) from t1 where v like 'a %';
1614
explain select count(*) from t1 where v='a ';
1615
id select_type table type possible_keys key key_len ref rows Extra
1616
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1617
explain select count(*) from t1 where c='a ';
1618
id select_type table type possible_keys key key_len ref rows Extra
1619
1 SIMPLE t1 ref c c 43 const # Using where; Using index
1620
explain select count(*) from t1 where t='a ';
1621
id select_type table type possible_keys key key_len ref rows Extra
1622
1 SIMPLE t1 ref t t 43 const # Using where
1623
explain select count(*) from t1 where v like 'a%';
1624
id select_type table type possible_keys key key_len ref rows Extra
1625
1 SIMPLE t1 range v v 43 NULL # Using where; Using index
1626
explain select count(*) from t1 where v between 'a' and 'a ';
1627
id select_type table type possible_keys key key_len ref rows Extra
1628
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1629
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1630
id select_type table type possible_keys key key_len ref rows Extra
1631
1 SIMPLE t1 ref v v 43 const # Using where; Using index
1632
alter table t1 add unique(v);
1633
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
1634
alter table t1 add key(v);
1635
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
1647
explain select * from t1 where v='a';
1648
id select_type table type possible_keys key key_len ref rows Extra
1649
1 SIMPLE t1 ref v,v_2 # 43 const # Using where
1650
select v,count(*) from t1 group by v limit 10;
1662
select v,count(t) from t1 group by v limit 10;
1674
select v,count(c) from t1 group by v limit 10;
1686
select sql_big_result v,count(t) from t1 group by v limit 10;
1698
select sql_big_result v,count(c) from t1 group by v limit 10;
1710
select c,count(*) from t1 group by c limit 10;
1722
select c,count(t) from t1 group by c limit 10;
1734
select sql_big_result c,count(t) from t1 group by c limit 10;
1746
select t,count(*) from t1 group by t limit 10;
1758
select t,count(t) from t1 group by t limit 10;
1770
select sql_big_result t,count(t) from t1 group by t limit 10;
1782
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
1784
Warning 1071 Specified key was too long; max key length is 1023 bytes
1785
show create table t1;
1787
t1 CREATE TABLE `t1` (
1788
`v` VARCHAR(300) COLLATE utf8_general_ci DEFAULT NULL,
1789
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1790
`t` TEXT COLLATE utf8_general_ci,
1794
) ENGINE=InnoDB COLLATE = utf8_general_ci
1795
select count(*) from t1 where v='a';
1798
select count(*) from t1 where v='a ';
1801
select count(*) from t1 where v between 'a' and 'a ';
1804
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1807
select count(*) from t1 where v like 'a%';
1810
select count(*) from t1 where v like 'a %';
1813
explain select count(*) from t1 where v='a ';
1814
id select_type table type possible_keys key key_len ref rows Extra
1815
1 SIMPLE t1 ref v v 1023 const # Using where
1816
explain select count(*) from t1 where v like 'a%';
1817
id select_type table type possible_keys key key_len ref rows Extra
1818
1 SIMPLE t1 range v v 1023 NULL # Using where
1819
explain select count(*) from t1 where v between 'a' and 'a ';
1820
id select_type table type possible_keys key key_len ref rows Extra
1821
1 SIMPLE t1 ref v v 1023 const # Using where
1822
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1823
id select_type table type possible_keys key key_len ref rows Extra
1824
1 SIMPLE t1 ref v v 1023 const # Using where
1825
explain select * from t1 where v='a';
1826
id select_type table type possible_keys key key_len ref rows Extra
1827
1 SIMPLE t1 ref v v 1023 const # Using where
1828
select v,count(*) from t1 group by v limit 10;
1840
select v,count(t) from t1 group by v limit 10;
1852
select sql_big_result v,count(t) from t1 group by v limit 10;
1864
alter table t1 drop key v, add key v (v(30));
1865
show create table t1;
1867
t1 CREATE TABLE `t1` (
1868
`v` VARCHAR(300) COLLATE utf8_general_ci DEFAULT NULL,
1869
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1870
`t` TEXT COLLATE utf8_general_ci,
1874
) ENGINE=InnoDB COLLATE = utf8_general_ci
1875
select count(*) from t1 where v='a';
1878
select count(*) from t1 where v='a ';
1881
select count(*) from t1 where v between 'a' and 'a ';
1884
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1887
select count(*) from t1 where v like 'a%';
1890
select count(*) from t1 where v like 'a %';
1893
explain select count(*) from t1 where v='a ';
1894
id select_type table type possible_keys key key_len ref rows Extra
1895
1 SIMPLE t1 ref v v 123 const # Using where
1896
explain select count(*) from t1 where v like 'a%';
1897
id select_type table type possible_keys key key_len ref rows Extra
1898
1 SIMPLE t1 range v v 123 NULL # Using where
1899
explain select count(*) from t1 where v between 'a' and 'a ';
1900
id select_type table type possible_keys key key_len ref rows Extra
1901
1 SIMPLE t1 ref v v 123 const # Using where
1902
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1903
id select_type table type possible_keys key key_len ref rows Extra
1904
1 SIMPLE t1 ref v v 123 const # Using where
1905
explain select * from t1 where v='a';
1906
id select_type table type possible_keys key key_len ref rows Extra
1907
1 SIMPLE t1 ref v v 123 const # Using where
1908
select v,count(*) from t1 group by v limit 10;
1920
select v,count(t) from t1 group by v limit 10;
1932
select sql_big_result v,count(t) from t1 group by v limit 10;
1944
alter table t1 modify v varchar(600), drop key v, add key v (v);
1946
Warning 1071 Specified key was too long; max key length is 1023 bytes
1947
show create table t1;
1949
t1 CREATE TABLE `t1` (
1950
`v` VARCHAR(600) COLLATE utf8_general_ci DEFAULT NULL,
1951
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1952
`t` TEXT COLLATE utf8_general_ci,
1956
) ENGINE=InnoDB COLLATE = utf8_general_ci
1957
select v,count(*) from t1 group by v limit 10;
1969
select v,count(t) from t1 group by v limit 10;
1981
select sql_big_result v,count(t) from t1 group by v limit 10;
1994
create table t1 (a char(10), unique (a));
1995
insert into t1 values ('a ');
1996
insert into t1 values ('a ');
1997
ERROR 23000: Duplicate entry 'a ' for key 'a'
1998
alter table t1 modify a varchar(10);
1999
insert into t1 values ('a '),('a '),('a '),('a ');
2000
ERROR 23000: Duplicate entry 'a ' for key 'a'
2001
insert into t1 values ('a ');
2002
ERROR 23000: Duplicate entry 'a ' for key 'a'
2003
insert into t1 values ('a ');
2004
ERROR 22001: Data too long for column 'a' at row 1
2005
insert into t1 values ('a ');
2006
ERROR 23000: Duplicate entry 'a ' for key 'a'
2007
update t1 set a='a ' where a like 'a%';
2008
select concat(a,'.') from t1;
2011
update t1 set a='abc ' where a like 'a ';
2012
select concat(a,'.') from t1;
2015
update t1 set a='a ' where a like 'a %';
2016
select concat(a,'.') from t1;
2019
update t1 set a='a ' where a like 'a ';
2020
select concat(a,'.') from t1;
2024
create table t1 (v varchar(10), c char(10), t text, key(v(5)), key(c(5)), key(t(5)));
2025
show create table t1;
2027
t1 CREATE TABLE `t1` (
2028
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2029
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2030
`t` TEXT COLLATE utf8_general_ci,
2034
) ENGINE=InnoDB COLLATE = utf8_general_ci
2036
create table t1 (v char(10));
2037
show create table t1;
2039
t1 CREATE TABLE `t1` (
2040
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
2041
) ENGINE=InnoDB COLLATE = utf8_general_ci
2043
create table t1 (v varchar(10), c char(10));
2044
show create table t1;
2046
t1 CREATE TABLE `t1` (
2047
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2048
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
2049
) ENGINE=InnoDB COLLATE = utf8_general_ci
2050
insert into t1 values('a','a'),('a ','a ');
2051
select concat('*',v,'*',c,'*') from t1;
2052
concat('*',v,'*',c,'*')
2056
create table t1(a int, b varchar(12), key ba(b, a));
2057
insert into t1 values (1, 'A'), (20, NULL);
2058
explain select * from t1 where a=20 and b is null;
2059
id select_type table type possible_keys key key_len ref rows Extra
2060
1 SIMPLE t1 ref ba ba 56 const,const 1 Using where; Using index
2061
select * from t1 where a=20 and b is null;
2065
create table t1 (v varchar(16383), key(v));
2067
Warning 1071 Specified key was too long; max key length is 1023 bytes
2069
create table t1 (v varchar(16383));
2070
show create table t1;
2072
t1 CREATE TABLE `t1` (
2073
`v` VARCHAR(16383) COLLATE utf8_general_ci DEFAULT NULL
2074
) ENGINE=InnoDB COLLATE = utf8_general_ci
2076
create table t1 (v varchar(16383));
2077
show create table t1;
2079
t1 CREATE TABLE `t1` (
2080
`v` VARCHAR(16383) COLLATE utf8_general_ci DEFAULT NULL
2081
) ENGINE=InnoDB COLLATE = utf8_general_ci
2083
set storage_engine=InnoDB;
2084
create table t1 (v varchar(16383)) engine=innodb;
2086
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
2087
insert into t1 values ('8', '6'), ('4', '7');
2088
select min(a) from t1;
2091
select min(b) from t1 where a='8';
2095
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
2096
insert into t1 (b) values (1);
2097
replace into t1 (b) values (2), (1), (3);
2104
insert into t1 (b) values (1);
2105
replace into t1 (b) values (2);
2106
replace into t1 (b) values (1);
2107
replace into t1 (b) values (3);
2114
create table t1 (rowid int not null auto_increment, val int not null,primary
2115
key (rowid), unique(val)) engine=innodb;
2116
replace into t1 (val) values ('1'),('2');
2117
replace into t1 (val) values ('1'),('2');
2118
insert into t1 (val) values ('1'),('2');
2119
ERROR 23000: Duplicate entry '1' for key 'val'
2125
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
2126
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
2127
SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300;
2130
SELECT GRADE FROM t1 WHERE GRADE= 151;
2135
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
2138
id INTEGER NOT NULL,
2139
FOREIGN KEY (id) REFERENCES t1 (id)
2141
INSERT INTO t1 (id) VALUES (NULL);
2146
INSERT INTO t1 (id) VALUES (NULL);
2152
INSERT INTO t1 (id) VALUES (NULL);
2161
CREATE TEMPORARY TABLE t2
2163
id INT NOT NULL PRIMARY KEY,
2165
FOREIGN KEY (b) REFERENCES test.t1(id)
2167
Got one of the listed errors
2169
create table t1 (col1 varchar(2000), index (col1(767)))
2172
Warning 1071 Specified key was too long; max key length is 1023 bytes
2173
create table t2 (col1 char(255), index (col1))
2175
create table t4 (col1 varchar(767), index (col1))
2178
Warning 1071 Specified key was too long; max key length is 1023 bytes
2179
create table t5 (col1 varchar(190) primary key)
2181
create table t6 (col1 varbinary(254) primary key)
2183
create table t7 (col1 text, index(col1(767)))
2186
Warning 1071 Specified key was too long; max key length is 1023 bytes
2187
create table t8 (col1 blob, index(col1(767)))
2189
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
2192
Warning 1071 Specified key was too long; max key length is 1023 bytes
2193
Warning 1071 Specified key was too long; max key length is 1023 bytes
2194
show create table t9;
2196
t9 CREATE TABLE `t9` (
2197
`col1` VARCHAR(512) COLLATE utf8_general_ci DEFAULT NULL,
2198
`col2` VARCHAR(512) COLLATE utf8_general_ci DEFAULT NULL,
2199
KEY `col1` (`col1`(255),`col2`(255))
2200
) ENGINE=InnoDB COLLATE = utf8_general_ci
2201
drop table t1, t2, t4, t5, t6, t7, t8, t9;
2202
create table t1 (col1 varchar(768), index(col1))
2205
Warning 1071 Specified key was too long; max key length is 1023 bytes
2206
create table t2 (col1 varbinary(768), index(col1))
2208
create table t3 (col1 text, index(col1(768)))
2211
Warning 1071 Specified key was too long; max key length is 1023 bytes
2212
create table t4 (col1 blob, index(col1(768)))
2214
show create table t1;
2216
t1 CREATE TABLE `t1` (
2217
`col1` VARCHAR(768) COLLATE utf8_general_ci DEFAULT NULL,
2218
KEY `col1` (`col1`(255))
2219
) ENGINE=InnoDB COLLATE = utf8_general_ci
2220
drop table t1, t2, t3, t4;
2221
create table t1 (col1 varchar(768) primary key)
2223
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2224
create table t2 (col1 varbinary(1024) primary key)
2226
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2227
create table t3 (col1 text, primary key(col1(768)))
2229
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2230
create table t4 (col1 blob, primary key(col1(1024)))
2232
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2240
CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
2242
INSERT INTO t2 VALUES(2);
2243
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2244
INSERT INTO t1 VALUES(1);
2245
INSERT INTO t2 VALUES(1);
2246
DELETE FROM t1 WHERE id = 1;
2247
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2249
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
2250
SET FOREIGN_KEY_CHECKS=0;
2252
SET FOREIGN_KEY_CHECKS=1;
2253
INSERT INTO t2 VALUES(3);
2254
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2256
set foreign_key_checks=0;
2257
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
2258
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
2259
ERROR HY000: Can't create table 'test.t1' (errno: 150)
2260
set foreign_key_checks=1;
2262
set foreign_key_checks=0;
2263
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
2264
create table t1(a varchar(10) primary key) engine = innodb;
2265
alter table t1 modify column a int;
2266
Got one of the listed errors
2267
set foreign_key_checks=1;
2269
create table t1(a int primary key) row_format=redundant engine=innodb;
2270
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
2271
create table t3(a int primary key) row_format=compact engine=innodb;
2272
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
2273
insert into t1 values(1);
2274
insert into t3 values(1);
2275
insert into t2 values(2);
2276
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`))
2277
insert into t4 values(2);
2278
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`))
2279
insert into t2 values(1);
2280
insert into t4 values(1);
2282
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`))
2284
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`))
2286
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`))
2288
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`))
2290
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`))
2292
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`))
2297
drop table t4,t3,t2,t1;
2298
create table t1 (a varchar(255),
2302
key (a(200),b(200),c(200),d(200))) engine=innodb;
2304
create table t1 (a varchar(255),
2309
key (a,b,c,d,e)) engine=innodb;
2310
ERROR 42000: Specified key was too long; max key length is 3500 bytes
2311
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
2312
create table t3 (s1 varchar(2) ,primary key (s1)) engine=innodb;
2313
create table t4 (s1 char(2) ,primary key (s1)) engine=innodb;
2314
insert into t1 values (0x41),(0x4120),(0x4100);
2315
insert into t3 values (0x41),(0x4120),(0x4100);
2316
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2317
insert into t3 values (0x41),(0x4100);
2318
insert into t4 values (0x41),(0x4120),(0x4100);
2319
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2320
insert into t4 values (0x41),(0x4100);
2321
select hex(s1) from t1;
2326
select hex(s1) from t3;
2330
select hex(s1) from t4;
2334
drop table t1,t3,t4;
2335
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
2336
create table t2 (s1 varbinary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
2337
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
2338
insert into t2 values(0x42);
2339
insert into t2 values(0x41);
2340
select hex(s1) from t2;
2344
update t1 set s1=0x123456 where a=2;
2345
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)
2346
select hex(s1) from t2;
2350
update t1 set s1=0x12 where a=1;
2351
update t1 set s1=0x12345678 where a=1;
2352
ERROR 22001: Data too long for column 's1' at row 1
2353
update t1 set s1=0x123457 where a=1;
2354
update t1 set s1=0x1220 where a=1;
2355
select hex(s1) from t2;
2359
update t1 set s1=0x1200 where a=1;
2360
select hex(s1) from t2;
2364
update t1 set s1=0x4200 where a=1;
2365
select hex(s1) from t2;
2369
delete from t1 where a=1;
2370
update t2 set s1=0x4120;
2372
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)
2373
delete from t1 where a!=3;
2374
select a,hex(s1) from t1;
2377
select hex(s1) from t2;
2382
create table t1 (a int primary key,s1 varchar(2) not null unique) engine=innodb;
2383
create table t2 (s1 char(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
2384
insert into t1 values(1,0x4100),(2,0x41);
2385
insert into t2 values(0x41);
2386
select hex(s1) from t2;
2389
update t1 set s1=0x1234 where a=1;
2390
select hex(s1) from t2;
2393
update t1 set s1=0x12 where a=2;
2394
select hex(s1) from t2;
2397
delete from t1 where a=1;
2398
delete from t1 where a=2;
2399
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)
2400
select a,hex(s1) from t1;
2403
select hex(s1) from t2;
2407
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
2408
CREATE TABLE t2(a INT) ENGINE=InnoDB;
2409
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
2410
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
2411
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
2412
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
2413
SHOW CREATE TABLE t2;
2415
t2 CREATE TABLE `t2` (
2416
`a` INT DEFAULT NULL,
2417
KEY `t2_ibfk_0` (`a`)
2418
) ENGINE=InnoDB COLLATE = utf8_general_ci
2421
field1 varchar(8) NOT NULL DEFAULT '',
2422
field2 varchar(8) NOT NULL DEFAULT '',
2423
PRIMARY KEY (field1, field2)
2426
field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
2427
FOREIGN KEY (field1) REFERENCES t1 (field1)
2428
ON DELETE CASCADE ON UPDATE CASCADE
2430
INSERT INTO t1 VALUES ('old', 'somevalu');
2431
INSERT INTO t1 VALUES ('other', 'anyvalue');
2432
INSERT INTO t2 VALUES ('old');
2433
INSERT INTO t2 VALUES ('other');
2434
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
2435
ERROR 23000: Upholding foreign key constraints for table 't1', entry 'other-somevalu', key 1 would lead to a duplicate entry
2448
alter table t1 add constraint c2_fk foreign key (c2)
2449
references t2(c1) on delete cascade;
2450
show create table t1;
2452
t1 CREATE TABLE `t1` (
2453
`c1` BIGINT NOT NULL,
2454
`c2` BIGINT NOT NULL,
2456
UNIQUE KEY `c2` (`c2`),
2457
CONSTRAINT `c2_fk` FOREIGN KEY (`c2`) REFERENCES `t2` (`c1`) ON DELETE CASCADE
2458
) ENGINE=InnoDB COLLATE = utf8_general_ci
2459
alter table t1 drop foreign key c2_fk;
2460
show create table t1;
2462
t1 CREATE TABLE `t1` (
2463
`c1` BIGINT NOT NULL,
2464
`c2` BIGINT NOT NULL,
2466
UNIQUE KEY `c2` (`c2`)
2467
) ENGINE=InnoDB COLLATE = utf8_general_ci
2469
create table t1(a date) engine=innodb;
2470
create table t2(a date, key(a)) engine=innodb;
2471
insert into t1 values('2005-10-01');
2472
insert into t2 values('2005-10-01');
2473
select * from t1, t2
2474
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
2476
2005-10-01 2005-10-01
2478
create table t1 (id int not null, f_id int not null, f int not null,
2479
primary key(f_id, id)) engine=innodb;
2480
create table t2 (id int not null,s_id int not null,s varchar(200),
2481
primary key(id)) engine=innodb;
2482
INSERT INTO t1 VALUES (8, 1, 3);
2483
INSERT INTO t1 VALUES (1, 2, 1);
2484
INSERT INTO t2 VALUES (1, 0, '');
2485
INSERT INTO t2 VALUES (8, 1, '');
2487
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
2488
where mm.id is null lock in share mode;
2491
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2492
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
2495
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2496
update t1 set b = 5 where b = 1;
2498
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2499
select * from t1 where a = 7 and b = 3 for update;
2505
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2506
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
2509
select * from t1 lock in share mode;
2517
update t1 set b = 5 where b = 1;
2519
select * from t1 where a = 2 and b = 2 for update;
2520
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2524
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2525
insert into t1 values (1,2),(5,3),(4,2);
2526
create table t2(d int not null, e int, primary key(d)) engine=innodb;
2527
insert into t2 values (8,6),(12,1),(3,1);
2530
select * from t2 for update;
2536
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2537
insert into t1 select * from t2;
2538
update t1 set b = (select e from t2 where a = d);
2539
create table t3(d int not null, e int, primary key(d)) engine=innodb
2543
drop table t1, t2, t3;
2544
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2545
insert into t1 values (1,2),(5,3),(4,2);
2546
create table t2(a int not null, b int, primary key(a)) engine=innodb;
2547
insert into t2 values (8,6),(12,1),(3,1);
2548
create table t3(d int not null, b int, primary key(d)) engine=innodb;
2549
insert into t3 values (8,6),(12,1),(3,1);
2550
create table t5(a int not null, b int, primary key(a)) engine=innodb;
2551
insert into t5 values (1,2),(5,3),(4,2);
2552
create table t6(d int not null, e int, primary key(d)) engine=innodb;
2553
insert into t6 values (8,6),(12,1),(3,1);
2554
create table t8(a int not null, b int, primary key(a)) engine=innodb;
2555
insert into t8 values (1,2),(5,3),(4,2);
2556
create table t9(d int not null, e int, primary key(d)) engine=innodb;
2557
insert into t9 values (8,6),(12,1),(3,1);
2560
select * from t2 for update;
2566
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2567
insert into t1 select * from t2;
2569
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2570
update t3 set b = (select b from t2 where a = d);
2572
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2573
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
2575
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2576
insert into t5 (select * from t2 lock in share mode);
2578
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2579
update t6 set e = (select b from t2 where a = d lock in share mode);
2581
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2582
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
2584
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2585
insert into t8 (select * from t2 for update);
2587
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2588
update t9 set e = (select b from t2 where a = d for update);
2590
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2591
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
2592
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2593
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2594
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2595
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2596
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2597
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2598
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2599
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2600
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2602
drop table t1, t2, t3, t5, t6, t8, t9;
2603
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
2604
ERROR HY000: Can't create table 'test.t1' (errno: -1)
2611
b VARCHAR(128) NOT NULL,
2614
KEY idx_t2_b_c (b,c(200)),
2615
CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a)
2618
INSERT INTO t1 VALUES (1);
2619
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
2620
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
2621
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
2622
INSERT INTO t2 VALUES (1, 'customer_over', '1');
2623
SELECT * FROM t2 WHERE b = 'customer_over';
2626
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
2629
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
2632
/* Bang: Empty result set, above was expected: */
2633
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2636
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2640
CREATE TABLE t1 ( a int ) ENGINE=innodb;
2642
INSERT INTO t1 VALUES (1);
2643
ALTER TABLE t1 ENGINE=innodb;
2645
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
2646
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
2647
CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
2648
ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
2649
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
2650
DELETE CASCADE ON UPDATE CASCADE;
2651
SHOW CREATE TABLE t2;
2653
t2 CREATE TABLE `t2` (
2658
CONSTRAINT `t2_t1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
2659
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`f`) REFERENCES `t1` (`f`) ON UPDATE CASCADE ON DELETE CASCADE
2660
) ENGINE=InnoDB COLLATE = utf8_general_ci
2662
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
2663
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
2664
INSERT INTO t1 VALUES (1);
2665
INSERT INTO t2 VALUES (1);
2666
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
2667
ALTER TABLE t2 MODIFY a INT NOT NULL;
2668
ERROR HY000: Error on rename of '#sql-temporary' to 'test.t2' (errno: 150)
2671
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
2673
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
2675
INSERT INTO t1 VALUES ('DDD');
2680
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
2682
INSERT INTO t1 VALUES (NULL),(347),(NULL);
2688
SHOW CREATE TABLE t1;
2690
t1 CREATE TABLE `t1` (
2691
`id` INT NOT NULL AUTO_INCREMENT,
2693
) ENGINE=InnoDB COLLATE = utf8_general_ci AUTO_INCREMENT=42
2694
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
2695
INSERT INTO t2 VALUES(42),(347),(348);
2696
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
2697
SHOW CREATE TABLE t1;
2699
t1 CREATE TABLE `t1` (
2700
`id` INT NOT NULL AUTO_INCREMENT,
2702
CONSTRAINT `t1_t2` FOREIGN KEY (`id`) REFERENCES `t2` (`id`)
2703
) ENGINE=InnoDB COLLATE = utf8_general_ci
2705
DROP TABLE IF EXISTS t1;
2707
Note 1051 Unknown table 't1'
2709
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
2711
INSERT INTO t1 VALUES(-10);
2715
INSERT INTO t1 VALUES(NULL);
2721
SET GLOBAL innodb_lock_wait_timeout=@orig_lock_wait_timeout ;