~jaypipes/drizzle/new-test-runner

« back to all changes in this revision

Viewing changes to storage/innobase/mysql-test/innodb.result

  • Committer: Jay Pipes
  • Date: 2008-12-11 17:52:34 UTC
  • mfrom: (482.16.152 testable)
  • Revision ID: jpipes@serialcoder-20081211175234-uqsfvmgxejvmellq
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
drop table if exists t1,t2,t3,t4;
 
2
drop database if exists mysqltest;
 
3
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
 
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;
 
6
id      code    name
 
7
1       1       Tim
 
8
2       1       Monty
 
9
3       2       David
 
10
4       2       Erik
 
11
5       3       Sasha
 
12
6       3       Jeremy
 
13
7       4       Matt
 
14
update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
 
15
select id, code, name from t1 order by id;
 
16
id      code    name
 
17
2       1       Monty
 
18
3       2       David
 
19
4       2       Erik
 
20
5       3       Sasha
 
21
6       3       Jeremy
 
22
7       4       Matt
 
23
8       1       Sinisa
 
24
update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
 
25
select id, code, name from t1 order by id;
 
26
id      code    name
 
27
3       2       David
 
28
4       2       Erik
 
29
5       3       Sasha
 
30
6       3       Jeremy
 
31
7       4       Matt
 
32
8       1       Sinisa
 
33
12      1       Ralph
 
34
drop table t1;
 
35
CREATE TABLE t1 (
 
36
id int(11) NOT NULL auto_increment,
 
37
parent_id int(11) DEFAULT '0' NOT NULL,
 
38
level tinyint(4) DEFAULT '0' NOT NULL,
 
39
PRIMARY KEY (id),
 
40
KEY parent_id (parent_id),
 
41
KEY level (level)
 
42
) engine=innodb;
 
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;
 
46
id      parent_id       level
 
47
8       102     2
 
48
9       102     2
 
49
15      102     2
 
50
update t1 set id=id+1000;
 
51
update t1 set id=1024 where id=1009;
 
52
Got one of the listed errors
 
53
select * from t1;
 
54
id      parent_id       level
 
55
1001    100     0
 
56
1002    101     1
 
57
1003    101     1
 
58
1004    101     1
 
59
1005    101     1
 
60
1006    101     1
 
61
1007    101     1
 
62
1008    102     2
 
63
1009    102     2
 
64
1015    102     2
 
65
1016    103     2
 
66
1017    103     2
 
67
1018    103     2
 
68
1019    103     2
 
69
1020    103     2
 
70
1021    104     2
 
71
1022    104     2
 
72
1024    104     2
 
73
1025    105     2
 
74
1026    105     2
 
75
1027    105     2
 
76
1028    105     2
 
77
1029    105     2
 
78
1030    105     2
 
79
1031    106     2
 
80
1032    106     2
 
81
1033    106     2
 
82
1034    106     2
 
83
1035    106     2
 
84
1036    107     2
 
85
1037    107     2
 
86
1038    107     2
 
87
1040    107     2
 
88
1157    100     0
 
89
1179    105     2
 
90
1183    104     2
 
91
1193    105     2
 
92
1202    107     2
 
93
1203    107     2
 
94
update ignore t1 set id=id+1;
 
95
select * from t1;
 
96
id      parent_id       level
 
97
1001    100     0
 
98
1002    101     1
 
99
1003    101     1
 
100
1004    101     1
 
101
1005    101     1
 
102
1006    101     1
 
103
1007    101     1
 
104
1008    102     2
 
105
1010    102     2
 
106
1015    102     2
 
107
1016    103     2
 
108
1017    103     2
 
109
1018    103     2
 
110
1019    103     2
 
111
1020    103     2
 
112
1021    104     2
 
113
1023    104     2
 
114
1024    104     2
 
115
1025    105     2
 
116
1026    105     2
 
117
1027    105     2
 
118
1028    105     2
 
119
1029    105     2
 
120
1030    105     2
 
121
1031    106     2
 
122
1032    106     2
 
123
1033    106     2
 
124
1034    106     2
 
125
1035    106     2
 
126
1036    107     2
 
127
1037    107     2
 
128
1039    107     2
 
129
1041    107     2
 
130
1158    100     0
 
131
1180    105     2
 
132
1184    104     2
 
133
1194    105     2
 
134
1202    107     2
 
135
1204    107     2
 
136
update ignore t1 set id=1023 where id=1010;
 
137
select * from t1 where parent_id=102;
 
138
id      parent_id       level
 
139
1008    102     2
 
140
1010    102     2
 
141
1015    102     2
 
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   1       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   1       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   1       const   #       
 
151
select level,id from t1 where level=1;
 
152
level   id
 
153
1       1002
 
154
1       1003
 
155
1       1004
 
156
1       1005
 
157
1       1006
 
158
1       1007
 
159
select level,id,parent_id from t1 where level=1;
 
160
level   id      parent_id
 
161
1       1002    101
 
162
1       1003    101
 
163
1       1004    101
 
164
1       1005    101
 
165
1       1006    101
 
166
1       1007    101
 
167
optimize table t1;
 
168
Table   Op      Msg_type        Msg_text
 
169
test.t1 optimize        note    Table does not support optimize, doing recreate + analyze instead
 
170
test.t1 optimize        status  OK
 
171
show keys from t1;
 
172
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment
 
173
t1      0       PRIMARY 1       id      A       #       NULL    NULL            BTREE   
 
174
t1      1       parent_id       1       parent_id       A       #       NULL    NULL            BTREE   
 
175
t1      1       level   1       level   A       #       NULL    NULL            BTREE   
 
176
drop table t1;
 
177
CREATE TABLE t1 (
 
178
gesuchnr int(11) DEFAULT '0' NOT NULL,
 
179
benutzer_id int(11) DEFAULT '0' NOT NULL,
 
180
PRIMARY KEY (gesuchnr,benutzer_id)
 
181
) engine=innodb;
 
182
replace into t1 (gesuchnr,benutzer_id) values (2,1);
 
183
replace into t1 (gesuchnr,benutzer_id) values (1,1);
 
184
replace into t1 (gesuchnr,benutzer_id) values (1,1);
 
185
select * from t1;
 
186
gesuchnr        benutzer_id
 
187
1       1
 
188
2       1
 
189
drop table t1;
 
190
create table t1 (a int) engine=innodb;
 
191
insert into t1 values (1), (2);
 
192
optimize table t1;
 
193
Table   Op      Msg_type        Msg_text
 
194
test.t1 optimize        note    Table does not support optimize, doing recreate + analyze instead
 
195
test.t1 optimize        status  OK
 
196
delete from t1 where a = 1;
 
197
select * from t1;
 
198
a
 
199
2
 
200
check table t1;
 
201
Table   Op      Msg_type        Msg_text
 
202
test.t1 check   status  OK
 
203
drop table t1;
 
204
create table t1 (a int,b varchar(20)) engine=innodb;
 
205
insert into t1 values (1,""), (2,"testing");
 
206
delete from t1 where a = 1;
 
207
select * from t1;
 
208
a       b
 
209
2       testing
 
210
create index skr on t1 (a);
 
211
insert into t1 values (3,""), (4,"testing");
 
212
analyze table t1;
 
213
Table   Op      Msg_type        Msg_text
 
214
test.t1 analyze status  OK
 
215
show keys from t1;
 
216
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment
 
217
t1      1       skr     1       a       A       #       NULL    NULL    YES     BTREE   
 
218
drop table t1;
 
219
create table t1 (a int,b varchar(20),key(a)) engine=innodb;
 
220
insert into t1 values (1,""), (2,"testing");
 
221
select * from t1 where a = 1;
 
222
a       b
 
223
1       
 
224
drop table t1;
 
225
create table t1 (n int not null primary key) engine=innodb;
 
226
set autocommit=0;
 
227
insert into t1 values (4);
 
228
rollback;
 
229
select n, "after rollback" from t1;
 
230
n       after rollback
 
231
insert into t1 values (4);
 
232
commit;
 
233
select n, "after commit" from t1;
 
234
n       after commit
 
235
4       after commit
 
236
commit;
 
237
insert into t1 values (5);
 
238
insert into t1 values (4);
 
239
ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
 
240
commit;
 
241
select n, "after commit" from t1;
 
242
n       after commit
 
243
4       after commit
 
244
5       after commit
 
245
set autocommit=1;
 
246
insert into t1 values (6);
 
247
insert into t1 values (4);
 
248
ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
 
249
select n from t1;
 
250
n
 
251
4
 
252
5
 
253
6
 
254
set autocommit=0;
 
255
begin;
 
256
savepoint `my_savepoint`;
 
257
insert into t1 values (7);
 
258
savepoint `savept2`;
 
259
insert into t1 values (3);
 
260
select n from t1;
 
261
n
 
262
3
 
263
4
 
264
5
 
265
6
 
266
7
 
267
savepoint savept3;
 
268
rollback to savepoint savept2;
 
269
rollback to savepoint savept3;
 
270
ERROR 42000: SAVEPOINT savept3 does not exist
 
271
rollback to savepoint savept2;
 
272
release savepoint `my_savepoint`;
 
273
select n from t1;
 
274
n
 
275
4
 
276
5
 
277
6
 
278
7
 
279
rollback to savepoint `my_savepoint`;
 
280
ERROR 42000: SAVEPOINT my_savepoint does not exist
 
281
rollback to savepoint savept2;
 
282
ERROR 42000: SAVEPOINT savept2 does not exist
 
283
insert into t1 values (8);
 
284
savepoint sv;
 
285
commit;
 
286
savepoint sv;
 
287
set autocommit=1;
 
288
rollback;
 
289
drop table t1;
 
290
create table t1 (n int not null primary key) engine=innodb;
 
291
start transaction;
 
292
insert into t1 values (4);
 
293
flush tables with read lock;
 
294
commit;
 
295
unlock tables;
 
296
commit;
 
297
select * from t1;
 
298
n
 
299
4
 
300
drop table t1;
 
301
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
 
302
begin;
 
303
insert into t1 values(1,'hamdouni');
 
304
select id as afterbegin_id,nom as afterbegin_nom from t1;
 
305
afterbegin_id   afterbegin_nom
 
306
1       hamdouni
 
307
rollback;
 
308
select id as afterrollback_id,nom as afterrollback_nom from t1;
 
309
afterrollback_id        afterrollback_nom
 
310
set autocommit=0;
 
311
insert into t1 values(2,'mysql');
 
312
select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
 
313
afterautocommit0_id     afterautocommit0_nom
 
314
2       mysql
 
315
rollback;
 
316
select id as afterrollback_id,nom as afterrollback_nom from t1;
 
317
afterrollback_id        afterrollback_nom
 
318
set autocommit=1;
 
319
drop table t1;
 
320
CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
 
321
insert into t1 values ('pippo', 12);
 
322
insert into t1 values ('pippo', 12);
 
323
ERROR 23000: Duplicate entry 'pippo' for key 'PRIMARY'
 
324
delete from t1;
 
325
delete from t1 where id = 'pippo';
 
326
select * from t1;
 
327
id      val
 
328
insert into t1 values ('pippo', 12);
 
329
set autocommit=0;
 
330
delete from t1;
 
331
rollback;
 
332
select * from t1;
 
333
id      val
 
334
pippo   12
 
335
delete from t1;
 
336
commit;
 
337
select * from t1;
 
338
id      val
 
339
drop table t1;
 
340
create table t1 (a integer) engine=innodb;
 
341
start transaction;
 
342
rename table t1 to t2;
 
343
create table t1 (b integer) engine=innodb;
 
344
insert into t1 values (1);
 
345
rollback;
 
346
drop table t1;
 
347
rename table t2 to t1;
 
348
drop table t1;
 
349
set autocommit=1;
 
350
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
 
351
INSERT INTO t1 VALUES (1, 'Jochen');
 
352
select * from t1;
 
353
ID      NAME
 
354
1       Jochen
 
355
drop table t1;
 
356
CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
 
357
set autocommit=0;
 
358
INSERT INTO t1  SET _userid='marc@anyware.co.uk';
 
359
COMMIT;
 
360
SELECT * FROM t1;
 
361
_userid
 
362
marc@anyware.co.uk
 
363
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
 
364
_userid
 
365
marc@anyware.co.uk
 
366
drop table t1;
 
367
set autocommit=1;
 
368
CREATE TABLE t1 (
 
369
user_id int(10) DEFAULT '0' NOT NULL,
 
370
name varchar(100),
 
371
phone varchar(100),
 
372
ref_email varchar(100) DEFAULT '' NOT NULL,
 
373
detail varchar(200),
 
374
PRIMARY KEY (user_id,ref_email)
 
375
)engine=innodb;
 
376
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');
 
377
select * from t1 where user_id=10292;
 
378
user_id name    phone   ref_email       detail
 
379
10292   sanjeev 29153373        sansh777@hotmail.com    xxx
 
380
10292   shirish 2333604 shirish@yahoo.com       ddsds
 
381
10292   sonali  323232  sonali@bolly.com        filmstar
 
382
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
 
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
select * from t1 where user_id>=10292;
 
389
user_id name    phone   ref_email       detail
 
390
10292   sanjeev 29153373        sansh777@hotmail.com    xxx
 
391
10292   shirish 2333604 shirish@yahoo.com       ddsds
 
392
10292   sonali  323232  sonali@bolly.com        filmstar
 
393
10293   shirish 2333604 shirish@yahoo.com       ddsds
 
394
select * from t1 where user_id>10292;
 
395
user_id name    phone   ref_email       detail
 
396
10293   shirish 2333604 shirish@yahoo.com       ddsds
 
397
select * from t1 where user_id<10292;
 
398
user_id name    phone   ref_email       detail
 
399
10291   sanjeev 29153373        sansh777@hotmail.com    xxx
 
400
drop table t1;
 
401
CREATE TABLE t1 (a int not null, b int not null,c int not null,
 
402
key(a),primary key(a,b), unique(c),key(a),unique(b));
 
403
show index from t1;
 
404
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment
 
405
t1      0       PRIMARY 1       a       A       #       NULL    NULL            BTREE   
 
406
t1      0       PRIMARY 2       b       A       #       NULL    NULL            BTREE   
 
407
t1      0       c       1       c       A       #       NULL    NULL            BTREE   
 
408
t1      0       b       1       b       A       #       NULL    NULL            BTREE   
 
409
t1      1       a       1       a       A       #       NULL    NULL            BTREE   
 
410
t1      1       a_2     1       a       A       #       NULL    NULL            BTREE   
 
411
drop table t1;
 
412
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
 
413
alter table t1 engine=innodb;
 
414
insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
 
415
select * from t1;
 
416
col1    col2
 
417
1       1
 
418
2       3
 
419
3       4
 
420
4       4
 
421
5       2
 
422
update t1 set col2='7' where col1='4';
 
423
select * from t1;
 
424
col1    col2
 
425
1       1
 
426
2       3
 
427
3       4
 
428
4       7
 
429
5       2
 
430
alter table t1 add co3 int not null;
 
431
select * from t1;
 
432
col1    col2    co3
 
433
1       1       0
 
434
2       3       0
 
435
3       4       0
 
436
4       7       0
 
437
5       2       0
 
438
update t1 set col2='9' where col1='2';
 
439
select * from t1;
 
440
col1    col2    co3
 
441
1       1       0
 
442
2       9       0
 
443
3       4       0
 
444
4       7       0
 
445
5       2       0
 
446
drop table t1;
 
447
create table t1 (a int not null , b int, primary key (a)) engine = innodb;
 
448
create table t2 (a int not null , b int, primary key (a)) engine = myisam;
 
449
insert into t1 VALUES (1,3) , (2,3), (3,3);
 
450
select * from t1;
 
451
a       b
 
452
1       3
 
453
2       3
 
454
3       3
 
455
insert into t2 select * from t1;
 
456
select * from t2;
 
457
a       b
 
458
1       3
 
459
2       3
 
460
3       3
 
461
delete from t1 where b = 3;
 
462
select * from t1;
 
463
a       b
 
464
insert into t1 select * from t2;
 
465
select * from t1;
 
466
a       b
 
467
1       3
 
468
2       3
 
469
3       3
 
470
select * from t2;
 
471
a       b
 
472
1       3
 
473
2       3
 
474
3       3
 
475
drop table t1,t2;
 
476
CREATE TABLE t1 (
 
477
user_name varchar(12),
 
478
password text,
 
479
subscribed char(1),
 
480
user_id int(11) DEFAULT '0' NOT NULL,
 
481
quota bigint(20),
 
482
weight double,
 
483
access_date date,
 
484
access_time time,
 
485
approved datetime,
 
486
dummy_primary_key int(11) NOT NULL auto_increment,
 
487
PRIMARY KEY (dummy_primary_key)
 
488
) ENGINE=innodb;
 
489
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
 
490
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
 
491
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','23:06:59','2000-09-07 23:06:59',3);
 
492
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','23:06:59','2000-09-07 23:06:59',4);
 
493
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
 
494
select  user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
 
495
user_name       password        subscribed      user_id quota   weight  access_date     access_time     approved        dummy_primary_key
 
496
user_0  somepassword    N       0       0       0       2000-09-07      23:06:59        2000-09-07 23:06:59     1
 
497
user_1  somepassword    Y       1       1       1       2000-09-07      23:06:59        2000-09-07 23:06:59     2
 
498
user_2  somepassword    N       2       2       1.4142135623731 2000-09-07      23:06:59        2000-09-07 23:06:59     3
 
499
user_3  somepassword    Y       3       3       1.7320508075689 2000-09-07      23:06:59        2000-09-07 23:06:59     4
 
500
user_4  somepassword    N       4       4       2       2000-09-07      23:06:59        2000-09-07 23:06:59     5
 
501
drop table t1;
 
502
CREATE TABLE t1 (
 
503
id int(11) NOT NULL auto_increment,
 
504
parent_id int(11) DEFAULT '0' NOT NULL,
 
505
level tinyint(4) DEFAULT '0' NOT NULL,
 
506
KEY (id),
 
507
KEY parent_id (parent_id),
 
508
KEY level (level)
 
509
) engine=innodb;
 
510
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);
 
511
INSERT INTO t1 values (179,5,2);
 
512
update t1 set parent_id=parent_id+100;
 
513
select * from t1 where parent_id=102;
 
514
id      parent_id       level
 
515
8       102     2
 
516
9       102     2
 
517
15      102     2
 
518
update t1 set id=id+1000;
 
519
update t1 set id=1024 where id=1009;
 
520
select * from t1;
 
521
id      parent_id       level
 
522
1001    100     0
 
523
1003    101     1
 
524
1004    101     1
 
525
1008    102     2
 
526
1024    102     2
 
527
1017    103     2
 
528
1022    104     2
 
529
1024    104     2
 
530
1028    105     2
 
531
1029    105     2
 
532
1030    105     2
 
533
1031    106     2
 
534
1032    106     2
 
535
1033    106     2
 
536
1203    107     2
 
537
1202    107     2
 
538
1020    103     2
 
539
1157    100     0
 
540
1193    105     2
 
541
1040    107     2
 
542
1002    101     1
 
543
1015    102     2
 
544
1006    101     1
 
545
1034    106     2
 
546
1035    106     2
 
547
1016    103     2
 
548
1007    101     1
 
549
1036    107     2
 
550
1018    103     2
 
551
1026    105     2
 
552
1027    105     2
 
553
1183    104     2
 
554
1038    107     2
 
555
1025    105     2
 
556
1037    107     2
 
557
1021    104     2
 
558
1019    103     2
 
559
1005    101     1
 
560
1179    105     2
 
561
update ignore t1 set id=id+1;
 
562
select * from t1;
 
563
id      parent_id       level
 
564
1002    100     0
 
565
1004    101     1
 
566
1005    101     1
 
567
1009    102     2
 
568
1025    102     2
 
569
1018    103     2
 
570
1023    104     2
 
571
1025    104     2
 
572
1029    105     2
 
573
1030    105     2
 
574
1031    105     2
 
575
1032    106     2
 
576
1033    106     2
 
577
1034    106     2
 
578
1204    107     2
 
579
1203    107     2
 
580
1021    103     2
 
581
1158    100     0
 
582
1194    105     2
 
583
1041    107     2
 
584
1003    101     1
 
585
1016    102     2
 
586
1007    101     1
 
587
1035    106     2
 
588
1036    106     2
 
589
1017    103     2
 
590
1008    101     1
 
591
1037    107     2
 
592
1019    103     2
 
593
1027    105     2
 
594
1028    105     2
 
595
1184    104     2
 
596
1039    107     2
 
597
1026    105     2
 
598
1038    107     2
 
599
1022    104     2
 
600
1020    103     2
 
601
1006    101     1
 
602
1180    105     2
 
603
update ignore t1 set id=1023 where id=1010;
 
604
select * from t1 where parent_id=102;
 
605
id      parent_id       level
 
606
1009    102     2
 
607
1025    102     2
 
608
1016    102     2
 
609
explain select level from t1 where level=1;
 
610
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
611
1       SIMPLE  t1      ref     level   level   1       const   #       Using index
 
612
select level,id from t1 where level=1;
 
613
level   id
 
614
1       1004
 
615
1       1005
 
616
1       1003
 
617
1       1007
 
618
1       1008
 
619
1       1006
 
620
select level,id,parent_id from t1 where level=1;
 
621
level   id      parent_id
 
622
1       1004    101
 
623
1       1005    101
 
624
1       1003    101
 
625
1       1007    101
 
626
1       1008    101
 
627
1       1006    101
 
628
select level,id from t1 where level=1 order by id;
 
629
level   id
 
630
1       1003
 
631
1       1004
 
632
1       1005
 
633
1       1006
 
634
1       1007
 
635
1       1008
 
636
delete from t1 where level=1;
 
637
select * from t1;
 
638
id      parent_id       level
 
639
1002    100     0
 
640
1009    102     2
 
641
1025    102     2
 
642
1018    103     2
 
643
1023    104     2
 
644
1025    104     2
 
645
1029    105     2
 
646
1030    105     2
 
647
1031    105     2
 
648
1032    106     2
 
649
1033    106     2
 
650
1034    106     2
 
651
1204    107     2
 
652
1203    107     2
 
653
1021    103     2
 
654
1158    100     0
 
655
1194    105     2
 
656
1041    107     2
 
657
1016    102     2
 
658
1035    106     2
 
659
1036    106     2
 
660
1017    103     2
 
661
1037    107     2
 
662
1019    103     2
 
663
1027    105     2
 
664
1028    105     2
 
665
1184    104     2
 
666
1039    107     2
 
667
1026    105     2
 
668
1038    107     2
 
669
1022    104     2
 
670
1020    103     2
 
671
1180    105     2
 
672
drop table t1;
 
673
CREATE TABLE t1 (
 
674
sca_code char(6) NOT NULL,
 
675
cat_code char(6) NOT NULL,
 
676
sca_desc varchar(50),
 
677
lan_code char(2) NOT NULL,
 
678
sca_pic varchar(100),
 
679
sca_sdesc varchar(50),
 
680
sca_sch_desc varchar(16),
 
681
PRIMARY KEY (sca_code, cat_code, lan_code),
 
682
INDEX sca_pic (sca_pic)
 
683
) engine = innodb ;
 
684
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');
 
685
select count(*) from t1 where sca_code = 'PD';
 
686
count(*)
 
687
1
 
688
select count(*) from t1 where sca_code <= 'PD';
 
689
count(*)
 
690
1
 
691
select count(*) from t1 where sca_pic is null;
 
692
count(*)
 
693
2
 
694
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
 
695
select count(*) from t1 where sca_code='PD' and sca_pic is null;
 
696
count(*)
 
697
1
 
698
select count(*) from t1 where cat_code='E';
 
699
count(*)
 
700
0
 
701
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
 
702
select count(*) from t1 where sca_code='PD' and sca_pic is null;
 
703
count(*)
 
704
1
 
705
select count(*) from t1 where sca_pic >= 'n';
 
706
count(*)
 
707
1
 
708
select sca_pic from t1 where sca_pic is null;
 
709
sca_pic
 
710
NULL
 
711
NULL
 
712
update t1 set sca_pic="test" where sca_pic is null;
 
713
delete from t1 where sca_code='pd';
 
714
drop table t1;
 
715
set @a:=now();
 
716
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
 
717
insert into t1 (a) values(1),(2),(3);
 
718
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
 
719
a
 
720
1
 
721
2
 
722
3
 
723
select a from t1 natural join t1 as t2 where b >= @a order by a;
 
724
a
 
725
1
 
726
2
 
727
3
 
728
update t1 set a=5 where a=1;
 
729
select a from t1;
 
730
a
 
731
2
 
732
3
 
733
5
 
734
drop table t1;
 
735
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
 
736
insert into t1 values("hello",1),("world",2);
 
737
select * from t1 order by b desc;
 
738
a       b
 
739
world   2
 
740
hello   1
 
741
optimize table t1;
 
742
Table   Op      Msg_type        Msg_text
 
743
test.t1 optimize        note    Table does not support optimize, doing recreate + analyze instead
 
744
test.t1 optimize        status  OK
 
745
show keys from t1;
 
746
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment
 
747
t1      0       PRIMARY 1       a       A       #       NULL    NULL            BTREE   
 
748
drop table t1;
 
749
create table t1 (i int, j int ) ENGINE=innodb;
 
750
insert into t1 values (1,2);
 
751
select * from t1 where i=1 and j=2;
 
752
i       j
 
753
1       2
 
754
create index ax1 on t1 (i,j);
 
755
select * from t1 where i=1 and j=2;
 
756
i       j
 
757
1       2
 
758
drop table t1;
 
759
CREATE TABLE t1 (
 
760
a int3 unsigned NOT NULL,
 
761
b int1 unsigned NOT NULL,
 
762
UNIQUE (a, b)
 
763
) ENGINE = innodb;
 
764
INSERT INTO t1 VALUES (1, 1);
 
765
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
 
766
MIN(B)  MAX(b)
 
767
1       1
 
768
drop table t1;
 
769
CREATE TABLE t1 (a int unsigned NOT NULL) engine=innodb;
 
770
INSERT INTO t1 VALUES (1);
 
771
SELECT * FROM t1;
 
772
a
 
773
1
 
774
DROP TABLE t1;
 
775
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;
 
776
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);
 
777
explain select * from t1 where a > 0 and a < 50;
 
778
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
779
1       SIMPLE  t1      range   PRIMARY PRIMARY 4       NULL    #       Using where
 
780
drop table t1;
 
781
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
 
782
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
 
783
LOCK TABLES t1 WRITE;
 
784
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
 
785
ERROR 23000: Duplicate entry '1-1' for key 'PRIMARY'
 
786
select id from t1;
 
787
id
 
788
0
 
789
1
 
790
2
 
791
select id from t1;
 
792
id
 
793
0
 
794
1
 
795
2
 
796
UNLOCK TABLES;
 
797
DROP TABLE t1;
 
798
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
 
799
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
 
800
LOCK TABLES t1 WRITE;
 
801
begin;
 
802
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
 
803
ERROR 23000: Duplicate entry '1-1' for key 'PRIMARY'
 
804
select id from t1;
 
805
id
 
806
0
 
807
1
 
808
2
 
809
insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
 
810
commit;
 
811
select id,id3 from t1;
 
812
id      id3
 
813
0       0
 
814
1       1
 
815
2       2
 
816
100     2
 
817
UNLOCK TABLES;
 
818
DROP TABLE t1;
 
819
create table t1 (a char(20), unique (a(5))) engine=innodb;
 
820
drop table t1;
 
821
create table t1 (a char(20), index (a(5))) engine=innodb;
 
822
show create table t1;
 
823
Table   Create Table
 
824
t1      CREATE TABLE `t1` (
 
825
  `a` char(20) DEFAULT NULL,
 
826
  KEY `a` (`a`(5))
 
827
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
828
drop table t1;
 
829
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
 
830
insert into t1 values (NULL),(NULL),(NULL);
 
831
delete from t1 where a=3;
 
832
insert into t1 values (NULL);
 
833
select * from t1;
 
834
a
 
835
1
 
836
2
 
837
4
 
838
alter table t1 add b int;
 
839
select * from t1;
 
840
a       b
 
841
1       NULL
 
842
2       NULL
 
843
4       NULL
 
844
drop table t1;
 
845
create table t1
 
846
(
 
847
id int auto_increment primary key,
 
848
name varchar(32) not null,
 
849
value text not null,
 
850
uid int not null,
 
851
unique key(name,uid)
 
852
) engine=innodb;
 
853
insert into t1 values (1,'one','one value',101),
 
854
(2,'two','two value',102),(3,'three','three value',103);
 
855
set insert_id=5;
 
856
replace into t1 (value,name,uid) values ('other value','two',102);
 
857
delete from t1 where uid=102;
 
858
set insert_id=5;
 
859
replace into t1 (value,name,uid) values ('other value','two',102);
 
860
set insert_id=6;
 
861
replace into t1 (value,name,uid) values ('other value','two',102);
 
862
select * from t1;
 
863
id      name    value   uid
 
864
1       one     one value       101
 
865
3       three   three value     103
 
866
6       two     other value     102
 
867
drop table t1;
 
868
create database mysqltest;
 
869
create table mysqltest.t1 (a int not null) engine= innodb;
 
870
insert into mysqltest.t1 values(1);
 
871
create table mysqltest.t2 (a int not null) engine= myisam;
 
872
insert into mysqltest.t2 values(1);
 
873
create table mysqltest.t3 (a int not null) engine= heap;
 
874
insert into mysqltest.t3 values(1);
 
875
commit;
 
876
drop database mysqltest;
 
877
show tables from mysqltest;
 
878
ERROR 42000: Unknown database 'mysqltest'
 
879
set autocommit=0;
 
880
create table t1 (a int not null) engine= innodb;
 
881
insert into t1 values(1),(2);
 
882
truncate table t1;
 
883
commit;
 
884
truncate table t1;
 
885
truncate table t1;
 
886
select * from t1;
 
887
a
 
888
insert into t1 values(1),(2);
 
889
delete from t1;
 
890
select * from t1;
 
891
a
 
892
commit;
 
893
drop table t1;
 
894
set autocommit=1;
 
895
create table t1 (a int not null) engine= innodb;
 
896
insert into t1 values(1),(2);
 
897
truncate table t1;
 
898
insert into t1 values(1),(2);
 
899
select * from t1;
 
900
a
 
901
1
 
902
2
 
903
truncate table t1;
 
904
insert into t1 values(1),(2);
 
905
delete from t1;
 
906
select * from t1;
 
907
a
 
908
drop table t1;
 
909
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
 
910
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
 
911
explain select * from t1 order by a;
 
912
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
913
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    #       
 
914
explain select * from t1 order by b;
 
915
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
916
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    #       Using filesort
 
917
explain select * from t1 order by c;
 
918
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
919
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    #       Using filesort
 
920
explain select a from t1 order by a;
 
921
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
922
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    #       Using index
 
923
explain select b from t1 order by b;
 
924
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
925
1       SIMPLE  t1      index   NULL    b       4       NULL    #       Using index
 
926
explain select a,b from t1 order by b;
 
927
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
928
1       SIMPLE  t1      index   NULL    b       4       NULL    #       Using index
 
929
explain select a,b from t1;
 
930
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
931
1       SIMPLE  t1      index   NULL    b       4       NULL    #       Using index
 
932
explain select a,b,c from t1;
 
933
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
934
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    #       
 
935
drop table t1;
 
936
create table t1 (t int not null default 1, key (t)) engine=innodb;
 
937
desc t1;
 
938
Field   Type    Null    Key     Default Extra
 
939
t       int(11) NO      MUL     1       
 
940
drop table t1;
 
941
CREATE TABLE t1 (
 
942
number bigint(20) NOT NULL default '0',
 
943
cname char(15) NOT NULL default '',
 
944
carrier_id smallint(6) NOT NULL default '0',
 
945
privacy tinyint(4) NOT NULL default '0',
 
946
last_mod_date timestamp NOT NULL,
 
947
last_mod_id smallint(6) NOT NULL default '0',
 
948
last_app_date timestamp NOT NULL,
 
949
last_app_id smallint(6) default '-1',
 
950
version smallint(6) NOT NULL default '0',
 
951
assigned_scps int(11) default '0',
 
952
status tinyint(4) default '0'
 
953
) ENGINE=InnoDB;
 
954
INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
 
955
INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
 
956
INSERT INTO t1 VALUES (650,'San Francisco',0,0,20011227111336,342,00000000000000,-1,1,24,1);
 
957
INSERT INTO t1 VALUES (302467,'Sue\'s Subshop',90,3,20020109113241,500,20020102115111,501,7,24,0);
 
958
INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
 
959
INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
 
960
CREATE TABLE t2 (
 
961
number bigint(20) NOT NULL default '0',
 
962
cname char(15) NOT NULL default '',
 
963
carrier_id smallint(6) NOT NULL default '0',
 
964
privacy tinyint(4) NOT NULL default '0',
 
965
last_mod_date timestamp NOT NULL,
 
966
last_mod_id smallint(6) NOT NULL default '0',
 
967
last_app_date timestamp NOT NULL,
 
968
last_app_id smallint(6) default '-1',
 
969
version smallint(6) NOT NULL default '0',
 
970
assigned_scps int(11) default '0',
 
971
status tinyint(4) default '0'
 
972
) ENGINE=InnoDB;
 
973
INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
 
974
INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
 
975
INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,00000000000000,-1,1,24,1);
 
976
INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
 
977
select * from t1;
 
978
number  cname   carrier_id      privacy last_mod_date   last_mod_id     last_app_date   last_app_id     version assigned_scps   status
 
979
4077711111      SeanWheeler     90      2       2002-01-11 11:28:46     500     0000-00-00 00:00:00     -1      2       3       1
 
980
9197722223      berry   90      3       2002-01-11 11:28:09     500     2002-01-02 11:45:32     501     4       10      0
 
981
650     San Francisco   0       0       2001-12-27 11:13:36     342     0000-00-00 00:00:00     -1      1       24      1
 
982
302467  Sue's Subshop   90      3       2002-01-09 11:32:41     500     2002-01-02 11:51:11     501     7       24      0
 
983
6014911113      SudzCarwash     520     1       2002-01-02 11:52:34     500     2002-01-02 11:52:59     501     33      32768   0
 
984
333     tubs    99      2       2002-01-09 11:34:40     501     2002-01-09 11:34:40     500     3       10      0
 
985
select * from t2;
 
986
number  cname   carrier_id      privacy last_mod_date   last_mod_id     last_app_date   last_app_id     version assigned_scps   status
 
987
4077711111      SeanWheeler     0       2       2002-01-11 11:28:53     500     0000-00-00 00:00:00     -1      2       3       1
 
988
9197722223      berry   90      3       2002-01-11 11:28:18     500     2002-01-02 11:45:32     501     4       10      0
 
989
650     San Francisco   90      0       2002-01-09 11:31:58     342     0000-00-00 00:00:00     -1      1       24      1
 
990
333     tubs    99      2       2002-01-09 11:34:53     501     2002-01-09 11:34:53     500     3       10      0
 
991
delete t1, t2 from t1 left join t2 on t1.number=t2.number where (t1.carrier_id=90 and t1.number=t2.number) or (t2.carrier_id=90 and t1.number=t2.number) or  (t1.carrier_id=90 and t2.number is null);
 
992
select * from t1;
 
993
number  cname   carrier_id      privacy last_mod_date   last_mod_id     last_app_date   last_app_id     version assigned_scps   status
 
994
6014911113      SudzCarwash     520     1       2002-01-02 11:52:34     500     2002-01-02 11:52:59     501     33      32768   0
 
995
333     tubs    99      2       2002-01-09 11:34:40     501     2002-01-09 11:34:40     500     3       10      0
 
996
select * from t2;
 
997
number  cname   carrier_id      privacy last_mod_date   last_mod_id     last_app_date   last_app_id     version assigned_scps   status
 
998
333     tubs    99      2       2002-01-09 11:34:53     501     2002-01-09 11:34:53     500     3       10      0
 
999
select * from t2;
 
1000
number  cname   carrier_id      privacy last_mod_date   last_mod_id     last_app_date   last_app_id     version assigned_scps   status
 
1001
333     tubs    99      2       2002-01-09 11:34:53     501     2002-01-09 11:34:53     500     3       10      0
 
1002
drop table t1,t2;
 
1003
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
 
1004
BEGIN;
 
1005
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
 
1006
SELECT @@tx_isolation,@@global.tx_isolation;
 
1007
@@tx_isolation  @@global.tx_isolation
 
1008
SERIALIZABLE    REPEATABLE-READ
 
1009
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
 
1010
select id, code, name from t1 order by id;
 
1011
id      code    name
 
1012
1       1       Tim
 
1013
2       1       Monty
 
1014
3       2       David
 
1015
COMMIT;
 
1016
BEGIN;
 
1017
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
 
1018
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
 
1019
select id, code, name from t1 order by id;
 
1020
id      code    name
 
1021
1       1       Tim
 
1022
2       1       Monty
 
1023
3       2       David
 
1024
4       2       Erik
 
1025
5       3       Sasha
 
1026
COMMIT;
 
1027
SET binlog_format='MIXED';
 
1028
BEGIN;
 
1029
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
 
1030
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
 
1031
select id, code, name from t1 order by id;
 
1032
id      code    name
 
1033
1       1       Tim
 
1034
2       1       Monty
 
1035
3       2       David
 
1036
4       2       Erik
 
1037
5       3       Sasha
 
1038
6       3       Jeremy
 
1039
7       4       Matt
 
1040
COMMIT;
 
1041
DROP TABLE t1;
 
1042
create table t1 (n int(10), d int(10)) engine=innodb;
 
1043
create table t2 (n int(10), d int(10)) engine=innodb;
 
1044
insert into t1 values(1,1),(1,2);
 
1045
insert into t2 values(1,10),(2,20);
 
1046
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
 
1047
select * from t1;
 
1048
n       d
 
1049
1       10
 
1050
1       10
 
1051
select * from t2;
 
1052
n       d
 
1053
1       30
 
1054
2       20
 
1055
drop table t1,t2;
 
1056
drop table if exists t1, t2;
 
1057
CREATE TABLE t1 (a int, PRIMARY KEY (a));
 
1058
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
 
1059
create trigger trg_del_t2 after  delete on t2 for each row
 
1060
insert into t1 values (1);
 
1061
insert into t1 values (1);
 
1062
insert into t2 values (1),(2);
 
1063
delete t2 from t2;
 
1064
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
1065
select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
 
1066
count(*)
 
1067
2
 
1068
drop table t1, t2;
 
1069
drop table if exists t1, t2;
 
1070
CREATE TABLE t1 (a int, PRIMARY KEY (a));
 
1071
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
 
1072
create trigger trg_del_t2 after  delete on t2 for each row
 
1073
insert into t1 values (1);
 
1074
insert into t1 values (1);
 
1075
insert into t2 values (1),(2);
 
1076
delete t2 from t2;
 
1077
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
1078
select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
 
1079
count(*)
 
1080
2
 
1081
drop table t1, t2;
 
1082
create table t1 (a int, b int) engine=innodb;
 
1083
insert into t1 values(20,null);
 
1084
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
 
1085
t2.b=t3.a;
 
1086
b       ifnull(t2.b,"this is null")
 
1087
NULL    this is null
 
1088
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
 
1089
t2.b=t3.a order by 1;
 
1090
b       ifnull(t2.b,"this is null")
 
1091
NULL    this is null
 
1092
insert into t1 values(10,null);
 
1093
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
 
1094
t2.b=t3.a order by 1;
 
1095
b       ifnull(t2.b,"this is null")
 
1096
NULL    this is null
 
1097
NULL    this is null
 
1098
drop table t1;
 
1099
create table t1 (a varchar(10) not null) engine=myisam;
 
1100
create table t2 (b varchar(10) not null unique) engine=innodb;
 
1101
select t1.a from t1,t2 where t1.a=t2.b;
 
1102
a
 
1103
drop table t1,t2;
 
1104
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
 
1105
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
 
1106
insert into t1 values (10, 20);
 
1107
insert into t2 values (10, 20);
 
1108
update t1, t2 set t1.b = 150, t2.b = t1.b where t2.a = t1.a and t1.a = 10;
 
1109
drop table t1,t2;
 
1110
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
 
1111
CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (t1_id) REFERENCES t1(id)  ON DELETE CASCADE ) ENGINE=INNODB;
 
1112
insert into t1 set id=1;
 
1113
insert into t2 set id=1, t1_id=1;
 
1114
delete t1,t2 from t1,t2 where t1.id=t2.t1_id;
 
1115
select * from t1;
 
1116
id
 
1117
select * from t2;
 
1118
id      t1_id
 
1119
drop table t2,t1;
 
1120
CREATE TABLE t1(id INT NOT NULL,  PRIMARY KEY (id)) ENGINE=INNODB;
 
1121
CREATE TABLE t2(id  INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id)  ) ENGINE=INNODB;
 
1122
INSERT INTO t1 VALUES(1);
 
1123
INSERT INTO t2 VALUES(1, 1);
 
1124
SELECT * from t1;
 
1125
id
 
1126
1
 
1127
UPDATE t1,t2 SET t1.id=t1.id+1, t2.t1_id=t1.id+1;
 
1128
SELECT * from t1;
 
1129
id
 
1130
2
 
1131
UPDATE t1,t2 SET t1.id=t1.id+1 where t1.id!=t2.id;
 
1132
SELECT * from t1;
 
1133
id
 
1134
3
 
1135
DROP TABLE t1,t2;
 
1136
set autocommit=0;
 
1137
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
 
1138
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
 
1139
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
 
1140
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
 
1141
COMMIT;
 
1142
INSERT INTO t1 VALUES("this-key", "will disappear");
 
1143
INSERT INTO t2 VALUES("this-key", "will also disappear");
 
1144
DELETE FROM t3 WHERE id1="my-test-1";
 
1145
SELECT * FROM t1;
 
1146
id      value
 
1147
this-key        will disappear
 
1148
SELECT * FROM t2;
 
1149
id      value
 
1150
this-key        will also disappear
 
1151
SELECT * FROM t3;
 
1152
id1     id2
 
1153
ROLLBACK;
 
1154
SELECT * FROM t1;
 
1155
id      value
 
1156
SELECT * FROM t2;
 
1157
id      value
 
1158
SELECT * FROM t3;
 
1159
id1     id2
 
1160
my-test-1       my-test-2
 
1161
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
 
1162
id1     id2
 
1163
my-test-1       my-test-2
 
1164
COMMIT;
 
1165
set autocommit=1;
 
1166
DROP TABLE t1,t2,t3;
 
1167
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
 
1168
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
 
1169
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
 
1170
SELECT * from t1;
 
1171
a       b
 
1172
1       1
 
1173
102     2
 
1174
103     3
 
1175
4       4
 
1176
5       5
 
1177
6       6
 
1178
7       7
 
1179
8       8
 
1180
9       9
 
1181
drop table t1;
 
1182
CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) engine=innodb;
 
1183
CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) engine=innodb;
 
1184
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12);
 
1185
INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
 
1186
update t1,t2 set t1.a=t1.a+100;
 
1187
select * from t1;
 
1188
a       b
 
1189
101     1
 
1190
102     2
 
1191
103     3
 
1192
104     4
 
1193
105     5
 
1194
106     6
 
1195
107     7
 
1196
108     8
 
1197
109     9
 
1198
110     10
 
1199
111     11
 
1200
112     12
 
1201
update t1,t2 set t1.a=t1.a+100 where t1.a=101;
 
1202
select * from t1;
 
1203
a       b
 
1204
201     1
 
1205
102     2
 
1206
103     3
 
1207
104     4
 
1208
105     5
 
1209
106     6
 
1210
107     7
 
1211
108     8
 
1212
109     9
 
1213
110     10
 
1214
111     11
 
1215
112     12
 
1216
update t1,t2 set t1.b=t1.b+10 where t1.b=2;
 
1217
select * from t1;
 
1218
a       b
 
1219
201     1
 
1220
103     3
 
1221
104     4
 
1222
105     5
 
1223
106     6
 
1224
107     7
 
1225
108     8
 
1226
109     9
 
1227
110     10
 
1228
111     11
 
1229
102     12
 
1230
112     12
 
1231
update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t1.a=t2.a+100;
 
1232
select * from t1;
 
1233
a       b
 
1234
201     1
 
1235
103     5
 
1236
104     6
 
1237
106     6
 
1238
105     7
 
1239
107     7
 
1240
108     8
 
1241
109     9
 
1242
110     10
 
1243
111     11
 
1244
102     12
 
1245
112     12
 
1246
select * from t2;
 
1247
a       b
 
1248
1       1
 
1249
2       2
 
1250
6       6
 
1251
7       7
 
1252
8       8
 
1253
9       9
 
1254
3       13
 
1255
4       14
 
1256
5       15
 
1257
drop table t1,t2;
 
1258
CREATE TABLE t2 (   NEXT_T         BIGINT NOT NULL PRIMARY KEY) ENGINE=MyISAM;
 
1259
CREATE TABLE t1 (  B_ID           INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB;
 
1260
SET AUTOCOMMIT=0;
 
1261
INSERT INTO t1 ( B_ID ) VALUES ( 1 );
 
1262
INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );
 
1263
ROLLBACK;
 
1264
Warnings:
 
1265
Warning 1196    Some non-transactional changed tables couldn't be rolled back
 
1266
SELECT * FROM t1;
 
1267
B_ID
 
1268
drop table  t1,t2;
 
1269
create table t1  ( pk         int primary key,    parent     int not null,    child      int not null,       index (parent)  ) engine = innodb;
 
1270
insert into t1 values   (1,0,4),  (2,1,3),  (3,2,1),  (4,1,2);
 
1271
select distinct  parent,child   from t1   order by parent;
 
1272
parent  child
 
1273
0       4
 
1274
1       2
 
1275
1       3
 
1276
2       1
 
1277
drop table t1;
 
1278
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
 
1279
create table t2 (a int not null auto_increment primary key, b int);
 
1280
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
 
1281
insert into t2 (a) select b from t1;
 
1282
insert into t1 (b) select b from t2;
 
1283
insert into t2 (a) select b from t1;
 
1284
insert into t1 (a) select b from t2;
 
1285
insert into t2 (a) select b from t1;
 
1286
insert into t1 (a) select b from t2;
 
1287
insert into t2 (a) select b from t1;
 
1288
insert into t1 (a) select b from t2;
 
1289
insert into t2 (a) select b from t1;
 
1290
insert into t1 (a) select b from t2;
 
1291
select count(*) from t1;
 
1292
count(*)
 
1293
623
 
1294
explain select * from t1 where c between 1 and 2500;
 
1295
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1296
1       SIMPLE  t1      range   c       c       5       NULL    #       Using where
 
1297
update t1 set c=a;
 
1298
explain select * from t1 where c between 1 and 2500;
 
1299
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1300
1       SIMPLE  t1      ALL     c       NULL    NULL    NULL    #       Using where
 
1301
drop table t1,t2;
 
1302
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
 
1303
insert into t1 (id) values (null),(null),(null),(null),(null);
 
1304
update t1 set fk=69 where fk is null order by id limit 1;
 
1305
SELECT * from t1;
 
1306
id      fk
 
1307
2       NULL
 
1308
3       NULL
 
1309
4       NULL
 
1310
5       NULL
 
1311
1       69
 
1312
drop table t1;
 
1313
create table t1 (a int not null, b int not null, key (a));
 
1314
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);
 
1315
SET @tmp=0;
 
1316
update t1 set b=(@tmp:=@tmp+1) order by a;
 
1317
update t1 set b=99 where a=1 order by b asc limit 1;
 
1318
update t1 set b=100 where a=1 order by b desc limit 2;
 
1319
update t1 set a=a+10+b where a=1 order by b;
 
1320
select * from t1 order by a,b;
 
1321
a       b
 
1322
2       4
 
1323
2       5
 
1324
2       6
 
1325
3       7
 
1326
3       8
 
1327
3       9
 
1328
3       10
 
1329
3       11
 
1330
3       12
 
1331
13      2
 
1332
111     100
 
1333
111     100
 
1334
drop table t1;
 
1335
create table t1 ( c char(8) not null ) engine=innodb;
 
1336
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
 
1337
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
 
1338
alter table t1 add b char(8) not null;
 
1339
alter table t1 add a char(8) not null;
 
1340
alter table t1 add primary key (a,b,c);
 
1341
update t1 set a=c, b=c;
 
1342
create table t2 (c char(8) not null, b char(8) not null, a char(8) not null, primary key(a,b,c)) engine=innodb;
 
1343
insert into t2 select * from t1;
 
1344
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
 
1345
drop table t1,t2;
 
1346
SET AUTOCOMMIT=1;
 
1347
create table t1 (a integer auto_increment primary key) engine=innodb;
 
1348
insert into t1 (a) values (NULL),(NULL);
 
1349
truncate table t1;
 
1350
insert into t1 (a) values (NULL),(NULL);
 
1351
SELECT * from t1;
 
1352
a
 
1353
1
 
1354
2
 
1355
drop table t1;
 
1356
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
 
1357
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;
 
1358
drop table t2,t1;
 
1359
create table `t1` (`id` int( 11 ) not null  ,primary key ( `id` )) engine = innodb;
 
1360
insert into `t1`values ( 1 ) ;
 
1361
create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = innodb;
 
1362
insert into `t2`values ( 1 ) ;
 
1363
create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb;
 
1364
insert into `t3`values ( 1 ) ;
 
1365
delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
 
1366
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))
 
1367
update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7  where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
 
1368
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))
 
1369
update t3 set  t3.id=7  where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
 
1370
ERROR 42S22: Unknown column 't1.id' in 'where clause'
 
1371
drop table t3,t2,t1;
 
1372
create table t1(
 
1373
id int primary key,
 
1374
pid int,
 
1375
index(pid),
 
1376
foreign key(pid) references t1(id) on delete cascade) engine=innodb;
 
1377
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
 
1378
(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
 
1379
delete from t1 where id=0;
 
1380
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)
 
1381
delete from t1 where id=15;
 
1382
delete from t1 where id=0;
 
1383
drop table t1;
 
1384
CREATE TABLE t1 (col1 int(1))ENGINE=InnoDB;
 
1385
CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx
 
1386
(stamp))ENGINE=InnoDB;
 
1387
insert into t1 values (1),(2),(3);
 
1388
insert into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);
 
1389
Warnings:
 
1390
Warning 1265    Data truncated for column 'stamp' at row 3
 
1391
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
 
1392
'20020204120000' GROUP BY col1;
 
1393
col1
 
1394
1
 
1395
2
 
1396
3
 
1397
4
 
1398
drop table t1,t2;
 
1399
CREATE TABLE t1 (
 
1400
`id` int(10) unsigned NOT NULL auto_increment,
 
1401
`id_object` int(10) unsigned default '0',
 
1402
`id_version` int(10) unsigned NOT NULL default '1',
 
1403
`label` varchar(100) NOT NULL default '',
 
1404
`description` text,
 
1405
PRIMARY KEY  (`id`),
 
1406
KEY `id_object` (`id_object`),
 
1407
KEY `id_version` (`id_version`)
 
1408
) ENGINE=InnoDB;
 
1409
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);
 
1410
CREATE TABLE t2 (
 
1411
`id` int(10) unsigned NOT NULL auto_increment,
 
1412
`id_version` int(10) unsigned NOT NULL default '1',
 
1413
PRIMARY KEY  (`id`),
 
1414
KEY `id_version` (`id_version`)
 
1415
) ENGINE=InnoDB;
 
1416
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
 
1417
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
 
1418
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl 
 
1419
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
 
1420
id      label
 
1421
3382    Test
 
1422
102     Le Pekin (Test)
 
1423
1794    Test de resto
 
1424
1822    Test 3
 
1425
3524    Societe Test
 
1426
3525    Fournisseur Test
 
1427
drop table t1,t2;
 
1428
create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=myisam;
 
1429
create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=innodb;
 
1430
create table t3 (a int, b varchar(200), c text not null) checksum=1 engine=innodb;
 
1431
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
 
1432
insert t2 select * from t1;
 
1433
insert t3 select * from t1;
 
1434
checksum table t1, t2, t3, t4 quick;
 
1435
Table   Checksum
 
1436
test.t1 2948697075
 
1437
test.t2 NULL
 
1438
test.t3 NULL
 
1439
test.t4 NULL
 
1440
Warnings:
 
1441
Error   1146    Table 'test.t4' doesn't exist
 
1442
checksum table t1, t2, t3, t4;
 
1443
Table   Checksum
 
1444
test.t1 2948697075
 
1445
test.t2 2948697075
 
1446
test.t3 2948697075
 
1447
test.t4 NULL
 
1448
Warnings:
 
1449
Error   1146    Table 'test.t4' doesn't exist
 
1450
checksum table t1, t2, t3, t4 extended;
 
1451
Table   Checksum
 
1452
test.t1 2948697075
 
1453
test.t2 2948697075
 
1454
test.t3 2948697075
 
1455
test.t4 NULL
 
1456
Warnings:
 
1457
Error   1146    Table 'test.t4' doesn't exist
 
1458
drop table t1,t2,t3;
 
1459
create table t1 (id int,  name char(10) not null,  name2 char(10) not null) engine=innodb;
 
1460
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
 
1461
select trim(name2) from t1  union all  select trim(name) from t1 union all select trim(id) from t1;
 
1462
trim(name2)
 
1463
fff
 
1464
sss
 
1465
ttt
 
1466
first
 
1467
second
 
1468
third
 
1469
1
 
1470
2
 
1471
3
 
1472
drop table t1;
 
1473
create table t1 (a int) engine=innodb;
 
1474
create table t2 like t1;
 
1475
drop table t1,t2;
 
1476
create table t1 (id int(11) not null, id2 int(11) not null, unique (id,id2)) engine=innodb;
 
1477
create table t2 (id int(11) not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
 
1478
show create table t1;
 
1479
Table   Create Table
 
1480
t1      CREATE TABLE `t1` (
 
1481
  `id` int(11) NOT NULL,
 
1482
  `id2` int(11) NOT NULL,
 
1483
  UNIQUE KEY `id` (`id`,`id2`)
 
1484
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1485
show create table t2;
 
1486
Table   Create Table
 
1487
t2      CREATE TABLE `t2` (
 
1488
  `id` int(11) NOT NULL,
 
1489
  KEY `t1_id_fk` (`id`),
 
1490
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
 
1491
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1492
create index id on t2 (id);
 
1493
show create table t2;
 
1494
Table   Create Table
 
1495
t2      CREATE TABLE `t2` (
 
1496
  `id` int(11) NOT NULL,
 
1497
  KEY `id` (`id`),
 
1498
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
 
1499
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1500
create index id2 on t2 (id);
 
1501
show create table t2;
 
1502
Table   Create Table
 
1503
t2      CREATE TABLE `t2` (
 
1504
  `id` int(11) NOT NULL,
 
1505
  KEY `id` (`id`),
 
1506
  KEY `id2` (`id`),
 
1507
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
 
1508
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1509
drop index id2 on t2;
 
1510
drop index id on t2;
 
1511
ERROR HY000: Cannot drop index 'id': needed in a foreign key constraint
 
1512
show create table t2;
 
1513
Table   Create Table
 
1514
t2      CREATE TABLE `t2` (
 
1515
  `id` int(11) NOT NULL,
 
1516
  KEY `id` (`id`),
 
1517
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
 
1518
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1519
drop table t2;
 
1520
create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;
 
1521
show create table t2;
 
1522
Table   Create Table
 
1523
t2      CREATE TABLE `t2` (
 
1524
  `id` int(11) NOT NULL,
 
1525
  `id2` int(11) NOT NULL,
 
1526
  KEY `t1_id_fk` (`id`,`id2`),
 
1527
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
 
1528
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1529
create unique index id on t2 (id,id2);
 
1530
show create table t2;
 
1531
Table   Create Table
 
1532
t2      CREATE TABLE `t2` (
 
1533
  `id` int(11) NOT NULL,
 
1534
  `id2` int(11) NOT NULL,
 
1535
  UNIQUE KEY `id` (`id`,`id2`),
 
1536
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
 
1537
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1538
drop table t2;
 
1539
create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
 
1540
show create table t2;
 
1541
Table   Create Table
 
1542
t2      CREATE TABLE `t2` (
 
1543
  `id` int(11) NOT NULL,
 
1544
  `id2` int(11) NOT NULL,
 
1545
  UNIQUE KEY `id` (`id`,`id2`),
 
1546
  KEY `t1_id_fk` (`id2`,`id`),
 
1547
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
 
1548
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1549
drop table t2;
 
1550
create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;
 
1551
show create table t2;
 
1552
Table   Create Table
 
1553
t2      CREATE TABLE `t2` (
 
1554
  `id` int(11) NOT NULL,
 
1555
  `id2` int(11) NOT NULL,
 
1556
  UNIQUE KEY `id` (`id`,`id2`),
 
1557
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
 
1558
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1559
drop table t2;
 
1560
create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
 
1561
show create table t2;
 
1562
Table   Create Table
 
1563
t2      CREATE TABLE `t2` (
 
1564
  `id` int(11) NOT NULL,
 
1565
  `id2` int(11) NOT NULL,
 
1566
  UNIQUE KEY `id` (`id`,`id2`),
 
1567
  KEY `t1_id_fk` (`id2`,`id`),
 
1568
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
 
1569
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1570
drop table t2;
 
1571
create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
 
1572
show create table t2;
 
1573
Table   Create Table
 
1574
t2      CREATE TABLE `t2` (
 
1575
  `id` int(11) NOT NULL AUTO_INCREMENT,
 
1576
  `id2` int(11) NOT NULL,
 
1577
  PRIMARY KEY (`id`),
 
1578
  KEY `id` (`id`,`id2`),
 
1579
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
 
1580
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1581
drop table t2;
 
1582
create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
 
1583
show create table t2;
 
1584
Table   Create Table
 
1585
t2      CREATE TABLE `t2` (
 
1586
  `id` int(11) NOT NULL AUTO_INCREMENT,
 
1587
  `id2` int(11) NOT NULL,
 
1588
  KEY `t1_id_fk` (`id`),
 
1589
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
 
1590
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1591
alter table t2 add index id_test (id), add index id_test2 (id,id2);
 
1592
show create table t2;
 
1593
Table   Create Table
 
1594
t2      CREATE TABLE `t2` (
 
1595
  `id` int(11) NOT NULL AUTO_INCREMENT,
 
1596
  `id2` int(11) NOT NULL,
 
1597
  KEY `id_test` (`id`),
 
1598
  KEY `id_test2` (`id`,`id2`),
 
1599
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
 
1600
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1601
drop table t2;
 
1602
create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
 
1603
ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match
 
1604
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
 
1605
show create table t2;
 
1606
Table   Create Table
 
1607
t2      CREATE TABLE `t2` (
 
1608
  `a` int(11) NOT NULL AUTO_INCREMENT,
 
1609
  `b` int(11) DEFAULT NULL,
 
1610
  PRIMARY KEY (`a`),
 
1611
  UNIQUE KEY `b_2` (`b`),
 
1612
  KEY `b` (`b`),
 
1613
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
 
1614
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1615
drop table t2;
 
1616
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;
 
1617
show create table t2;
 
1618
Table   Create Table
 
1619
t2      CREATE TABLE `t2` (
 
1620
  `a` int(11) NOT NULL AUTO_INCREMENT,
 
1621
  `b` int(11) DEFAULT NULL,
 
1622
  PRIMARY KEY (`a`),
 
1623
  UNIQUE KEY `b` (`b`),
 
1624
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
 
1625
  CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
 
1626
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1627
drop table t2, t1;
 
1628
create table t1 (c char(10), index (c,c)) engine=innodb;
 
1629
ERROR 42S21: Duplicate column name 'c'
 
1630
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
 
1631
ERROR 42S21: Duplicate column name 'c1'
 
1632
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
 
1633
ERROR 42S21: Duplicate column name 'c1'
 
1634
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
 
1635
ERROR 42S21: Duplicate column name 'c1'
 
1636
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
 
1637
alter table t1 add key (c1,c1);
 
1638
ERROR 42S21: Duplicate column name 'c1'
 
1639
alter table t1 add key (c2,c1,c1);
 
1640
ERROR 42S21: Duplicate column name 'c1'
 
1641
alter table t1 add key (c1,c2,c1);
 
1642
ERROR 42S21: Duplicate column name 'c1'
 
1643
alter table t1 add key (c1,c1,c2);
 
1644
ERROR 42S21: Duplicate column name 'c1'
 
1645
drop table t1;
 
1646
create table t1(a int(1) , b int(1)) engine=innodb;
 
1647
insert into t1 values ('1111', '3333');
 
1648
select distinct concat(a, b) from t1;
 
1649
concat(a, b)
 
1650
11113333
 
1651
drop table t1;
 
1652
CREATE TABLE t1 ( a char(10) ) ENGINE=InnoDB;
 
1653
SELECT a FROM t1 WHERE MATCH (a) AGAINST ('test' IN BOOLEAN MODE);
 
1654
ERROR HY000: The used table type doesn't support FULLTEXT indexes
 
1655
DROP TABLE t1;
 
1656
CREATE TABLE t1 (a_id tinyint(4) NOT NULL default '0', PRIMARY KEY  (a_id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
1657
INSERT INTO t1 VALUES (1),(2),(3);
 
1658
CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL default '0', PRIMARY KEY  (b_id), KEY  (b_a), 
 
1659
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
1660
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
 
1661
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;
 
1662
a_id    b_list
 
1663
1       1,2,3
 
1664
2       4,5
 
1665
3       NULL
 
1666
DROP TABLE t2;
 
1667
DROP TABLE t1;
 
1668
create temporary table t1 (a int) engine=innodb;
 
1669
insert into t1 values (4711);
 
1670
truncate t1;
 
1671
insert into t1 values (42);
 
1672
select * from t1;
 
1673
a
 
1674
42
 
1675
drop table t1;
 
1676
create table t1 (a int) engine=innodb;
 
1677
insert into t1 values (4711);
 
1678
truncate t1;
 
1679
insert into t1 values (42);
 
1680
select * from t1;
 
1681
a
 
1682
42
 
1683
drop table t1;
 
1684
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;
 
1685
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
 
1686
select * from t1 order by a,b,c,d;
 
1687
a       b       c       d       e
 
1688
1       1       a       1       1
 
1689
2       2       b       2       2
 
1690
3       3       ab      3       3
 
1691
explain select * from t1 order by a,b,c,d;
 
1692
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1693
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using filesort
 
1694
drop table t1;
 
1695
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
 
1696
insert into t1 values ('8', '6'), ('4', '7');
 
1697
select min(a) from t1;
 
1698
min(a)
 
1699
4
 
1700
select min(b) from t1 where a='8';
 
1701
min(b)
 
1702
6
 
1703
drop table t1;
 
1704
create table t1 (x bigint unsigned not null primary key) engine=innodb;
 
1705
insert into t1(x) values (0xfffffffffffffff0),(0xfffffffffffffff1);
 
1706
select * from t1;
 
1707
x
 
1708
18446744073709551600
 
1709
18446744073709551601
 
1710
select count(*) from t1 where x>0;
 
1711
count(*)
 
1712
2
 
1713
select count(*) from t1 where x=0;
 
1714
count(*)
 
1715
0
 
1716
select count(*) from t1 where x<0;
 
1717
count(*)
 
1718
0
 
1719
select count(*) from t1 where x < -16;
 
1720
count(*)
 
1721
0
 
1722
select count(*) from t1 where x = -16;
 
1723
count(*)
 
1724
0
 
1725
explain select count(*) from t1 where x > -16;
 
1726
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1727
1       SIMPLE  t1      index   PRIMARY PRIMARY 8       NULL    2       Using where; Using index
 
1728
select count(*) from t1 where x > -16;
 
1729
count(*)
 
1730
2
 
1731
select * from t1 where x > -16;
 
1732
x
 
1733
18446744073709551600
 
1734
18446744073709551601
 
1735
select count(*) from t1 where x = 18446744073709551601;
 
1736
count(*)
 
1737
1
 
1738
drop table t1;
 
1739
show status like "Innodb_buffer_pool_pages_total";
 
1740
Variable_name   Value
 
1741
Innodb_buffer_pool_pages_total  511
 
1742
show status like "Innodb_page_size";
 
1743
Variable_name   Value
 
1744
Innodb_page_size        16384
 
1745
show status like "Innodb_rows_deleted";
 
1746
Variable_name   Value
 
1747
Innodb_rows_deleted     71
 
1748
show status like "Innodb_rows_inserted";
 
1749
Variable_name   Value
 
1750
Innodb_rows_inserted    1084
 
1751
show status like "Innodb_rows_updated";
 
1752
Variable_name   Value
 
1753
Innodb_rows_updated     885
 
1754
show status like "Innodb_row_lock_waits";
 
1755
Variable_name   Value
 
1756
Innodb_row_lock_waits   0
 
1757
show status like "Innodb_row_lock_current_waits";
 
1758
Variable_name   Value
 
1759
Innodb_row_lock_current_waits   0
 
1760
show status like "Innodb_row_lock_time";
 
1761
Variable_name   Value
 
1762
Innodb_row_lock_time    0
 
1763
show status like "Innodb_row_lock_time_max";
 
1764
Variable_name   Value
 
1765
Innodb_row_lock_time_max        0
 
1766
show status like "Innodb_row_lock_time_avg";
 
1767
Variable_name   Value
 
1768
Innodb_row_lock_time_avg        0
 
1769
show variables like "innodb_sync_spin_loops";
 
1770
Variable_name   Value
 
1771
innodb_sync_spin_loops  20
 
1772
set global innodb_sync_spin_loops=1000;
 
1773
show variables like "innodb_sync_spin_loops";
 
1774
Variable_name   Value
 
1775
innodb_sync_spin_loops  1000
 
1776
set global innodb_sync_spin_loops=0;
 
1777
show variables like "innodb_sync_spin_loops";
 
1778
Variable_name   Value
 
1779
innodb_sync_spin_loops  0
 
1780
set global innodb_sync_spin_loops=20;
 
1781
show variables like "innodb_sync_spin_loops";
 
1782
Variable_name   Value
 
1783
innodb_sync_spin_loops  20
 
1784
show variables like "innodb_thread_concurrency";
 
1785
Variable_name   Value
 
1786
innodb_thread_concurrency       8
 
1787
set global innodb_thread_concurrency=1001;
 
1788
Warnings:
 
1789
Warning 1292    Truncated incorrect thread_concurrency value: '1001'
 
1790
show variables like "innodb_thread_concurrency";
 
1791
Variable_name   Value
 
1792
innodb_thread_concurrency       1000
 
1793
set global innodb_thread_concurrency=0;
 
1794
show variables like "innodb_thread_concurrency";
 
1795
Variable_name   Value
 
1796
innodb_thread_concurrency       0
 
1797
set global innodb_thread_concurrency=16;
 
1798
show variables like "innodb_thread_concurrency";
 
1799
Variable_name   Value
 
1800
innodb_thread_concurrency       16
 
1801
show variables like "innodb_concurrency_tickets";
 
1802
Variable_name   Value
 
1803
innodb_concurrency_tickets      500
 
1804
set global innodb_concurrency_tickets=1000;
 
1805
show variables like "innodb_concurrency_tickets";
 
1806
Variable_name   Value
 
1807
innodb_concurrency_tickets      1000
 
1808
set global innodb_concurrency_tickets=0;
 
1809
Warnings:
 
1810
Warning 1292    Truncated incorrect concurrency_tickets value: '0'
 
1811
show variables like "innodb_concurrency_tickets";
 
1812
Variable_name   Value
 
1813
innodb_concurrency_tickets      1
 
1814
set global innodb_concurrency_tickets=500;
 
1815
show variables like "innodb_concurrency_tickets";
 
1816
Variable_name   Value
 
1817
innodb_concurrency_tickets      500
 
1818
show variables like "innodb_thread_sleep_delay";
 
1819
Variable_name   Value
 
1820
innodb_thread_sleep_delay       10000
 
1821
set global innodb_thread_sleep_delay=100000;
 
1822
show variables like "innodb_thread_sleep_delay";
 
1823
Variable_name   Value
 
1824
innodb_thread_sleep_delay       100000
 
1825
set global innodb_thread_sleep_delay=0;
 
1826
show variables like "innodb_thread_sleep_delay";
 
1827
Variable_name   Value
 
1828
innodb_thread_sleep_delay       0
 
1829
set global innodb_thread_sleep_delay=10000;
 
1830
show variables like "innodb_thread_sleep_delay";
 
1831
Variable_name   Value
 
1832
innodb_thread_sleep_delay       10000
 
1833
set storage_engine=INNODB;
 
1834
drop table if exists t1,t2,t3;
 
1835
--- Testing varchar ---
 
1836
--- Testing varchar ---
 
1837
create table t1 (v varchar(10), c char(10), t text);
 
1838
insert into t1 values('+ ', '+ ', '+ ');
 
1839
set @a=repeat(' ',20);
 
1840
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
 
1841
Warnings:
 
1842
Note    1265    Data truncated for column 'v' at row 1
 
1843
select concat('*',v,'*',c,'*',t,'*') from t1;
 
1844
concat('*',v,'*',c,'*',t,'*')
 
1845
*+ *+*+ *
 
1846
*+         *+*+                    *
 
1847
show create table t1;
 
1848
Table   Create Table
 
1849
t1      CREATE TABLE `t1` (
 
1850
  `v` varchar(10) DEFAULT NULL,
 
1851
  `c` char(10) DEFAULT NULL,
 
1852
  `t` text
 
1853
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1854
create table t2 like t1;
 
1855
show create table t2;
 
1856
Table   Create Table
 
1857
t2      CREATE TABLE `t2` (
 
1858
  `v` varchar(10) DEFAULT NULL,
 
1859
  `c` char(10) DEFAULT NULL,
 
1860
  `t` text
 
1861
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1862
create table t3 select * from t1;
 
1863
show create table t3;
 
1864
Table   Create Table
 
1865
t3      CREATE TABLE `t3` (
 
1866
  `v` varchar(10) DEFAULT NULL,
 
1867
  `c` char(10) DEFAULT NULL,
 
1868
  `t` text
 
1869
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1870
alter table t1 modify c varchar(10);
 
1871
show create table t1;
 
1872
Table   Create Table
 
1873
t1      CREATE TABLE `t1` (
 
1874
  `v` varchar(10) DEFAULT NULL,
 
1875
  `c` varchar(10) DEFAULT NULL,
 
1876
  `t` text
 
1877
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1878
alter table t1 modify v char(10);
 
1879
show create table t1;
 
1880
Table   Create Table
 
1881
t1      CREATE TABLE `t1` (
 
1882
  `v` char(10) DEFAULT NULL,
 
1883
  `c` varchar(10) DEFAULT NULL,
 
1884
  `t` text
 
1885
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1886
alter table t1 modify t varchar(10);
 
1887
Warnings:
 
1888
Note    1265    Data truncated for column 't' at row 2
 
1889
show create table t1;
 
1890
Table   Create Table
 
1891
t1      CREATE TABLE `t1` (
 
1892
  `v` char(10) DEFAULT NULL,
 
1893
  `c` varchar(10) DEFAULT NULL,
 
1894
  `t` varchar(10) DEFAULT NULL
 
1895
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1896
select concat('*',v,'*',c,'*',t,'*') from t1;
 
1897
concat('*',v,'*',c,'*',t,'*')
 
1898
*+*+*+ *
 
1899
*+*+*+         *
 
1900
drop table t1,t2,t3;
 
1901
create table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
 
1902
show create table t1;
 
1903
Table   Create Table
 
1904
t1      CREATE TABLE `t1` (
 
1905
  `v` varchar(10) DEFAULT NULL,
 
1906
  `c` char(10) DEFAULT NULL,
 
1907
  `t` text,
 
1908
  KEY `v` (`v`),
 
1909
  KEY `c` (`c`),
 
1910
  KEY `t` (`t`(10))
 
1911
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1912
select count(*) from t1;
 
1913
count(*)
 
1914
270
 
1915
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
 
1916
select count(*) from t1 where v='a';
 
1917
count(*)
 
1918
10
 
1919
select count(*) from t1 where c='a';
 
1920
count(*)
 
1921
10
 
1922
select count(*) from t1 where t='a';
 
1923
count(*)
 
1924
10
 
1925
select count(*) from t1 where v='a  ';
 
1926
count(*)
 
1927
10
 
1928
select count(*) from t1 where c='a  ';
 
1929
count(*)
 
1930
10
 
1931
select count(*) from t1 where t='a  ';
 
1932
count(*)
 
1933
10
 
1934
select count(*) from t1 where v between 'a' and 'a ';
 
1935
count(*)
 
1936
10
 
1937
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
 
1938
count(*)
 
1939
10
 
1940
select count(*) from t1 where v like 'a%';
 
1941
count(*)
 
1942
11
 
1943
select count(*) from t1 where c like 'a%';
 
1944
count(*)
 
1945
11
 
1946
select count(*) from t1 where t like 'a%';
 
1947
count(*)
 
1948
11
 
1949
select count(*) from t1 where v like 'a %';
 
1950
count(*)
 
1951
9
 
1952
explain select count(*) from t1 where v='a  ';
 
1953
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1954
1       SIMPLE  t1      ref     v       v       13      const   #       Using where; Using index
 
1955
explain select count(*) from t1 where c='a  ';
 
1956
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1957
1       SIMPLE  t1      ref     c       c       11      const   #       Using where; Using index
 
1958
explain select count(*) from t1 where t='a  ';
 
1959
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1960
1       SIMPLE  t1      ref     t       t       13      const   #       Using where
 
1961
explain select count(*) from t1 where v like 'a%';
 
1962
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1963
1       SIMPLE  t1      range   v       v       13      NULL    #       Using where; Using index
 
1964
explain select count(*) from t1 where v between 'a' and 'a ';
 
1965
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1966
1       SIMPLE  t1      ref     v       v       13      const   #       Using where; Using index
 
1967
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
 
1968
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1969
1       SIMPLE  t1      ref     v       v       13      const   #       Using where; Using index
 
1970
alter table t1 add unique(v);
 
1971
ERROR 23000: Duplicate entry 'v' for key 'v_2'
 
1972
alter table t1 add key(v);
 
1973
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
 
1974
qq
 
1975
*a*a*a*
 
1976
*a *a*a *
 
1977
*a  *a*a  *
 
1978
*a   *a*a   *
 
1979
*a    *a*a    *
 
1980
*a     *a*a     *
 
1981
*a      *a*a      *
 
1982
*a       *a*a       *
 
1983
*a        *a*a        *
 
1984
*a         *a*a         *
 
1985
explain select * from t1 where v='a';
 
1986
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1987
1       SIMPLE  t1      ref     v,v_2   #       13      const   #       Using where
 
1988
select v,count(*) from t1 group by v limit 10;
 
1989
v       count(*)
 
1990
a      1
 
1991
a       10
 
1992
b       10
 
1993
c       10
 
1994
d       10
 
1995
e       10
 
1996
f       10
 
1997
g       10
 
1998
h       10
 
1999
i       10
 
2000
select v,count(t) from t1 group by v limit 10;
 
2001
v       count(t)
 
2002
a      1
 
2003
a       10
 
2004
b       10
 
2005
c       10
 
2006
d       10
 
2007
e       10
 
2008
f       10
 
2009
g       10
 
2010
h       10
 
2011
i       10
 
2012
select v,count(c) from t1 group by v limit 10;
 
2013
v       count(c)
 
2014
a      1
 
2015
a       10
 
2016
b       10
 
2017
c       10
 
2018
d       10
 
2019
e       10
 
2020
f       10
 
2021
g       10
 
2022
h       10
 
2023
i       10
 
2024
select sql_big_result v,count(t) from t1 group by v limit 10;
 
2025
v       count(t)
 
2026
a      1
 
2027
a       10
 
2028
b       10
 
2029
c       10
 
2030
d       10
 
2031
e       10
 
2032
f       10
 
2033
g       10
 
2034
h       10
 
2035
i       10
 
2036
select sql_big_result v,count(c) from t1 group by v limit 10;
 
2037
v       count(c)
 
2038
a      1
 
2039
a       10
 
2040
b       10
 
2041
c       10
 
2042
d       10
 
2043
e       10
 
2044
f       10
 
2045
g       10
 
2046
h       10
 
2047
i       10
 
2048
select c,count(*) from t1 group by c limit 10;
 
2049
c       count(*)
 
2050
a      1
 
2051
a       10
 
2052
b       10
 
2053
c       10
 
2054
d       10
 
2055
e       10
 
2056
f       10
 
2057
g       10
 
2058
h       10
 
2059
i       10
 
2060
select c,count(t) from t1 group by c limit 10;
 
2061
c       count(t)
 
2062
a      1
 
2063
a       10
 
2064
b       10
 
2065
c       10
 
2066
d       10
 
2067
e       10
 
2068
f       10
 
2069
g       10
 
2070
h       10
 
2071
i       10
 
2072
select sql_big_result c,count(t) from t1 group by c limit 10;
 
2073
c       count(t)
 
2074
a      1
 
2075
a       10
 
2076
b       10
 
2077
c       10
 
2078
d       10
 
2079
e       10
 
2080
f       10
 
2081
g       10
 
2082
h       10
 
2083
i       10
 
2084
select t,count(*) from t1 group by t limit 10;
 
2085
t       count(*)
 
2086
a      1
 
2087
a       10
 
2088
b       10
 
2089
c       10
 
2090
d       10
 
2091
e       10
 
2092
f       10
 
2093
g       10
 
2094
h       10
 
2095
i       10
 
2096
select t,count(t) from t1 group by t limit 10;
 
2097
t       count(t)
 
2098
a      1
 
2099
a       10
 
2100
b       10
 
2101
c       10
 
2102
d       10
 
2103
e       10
 
2104
f       10
 
2105
g       10
 
2106
h       10
 
2107
i       10
 
2108
select sql_big_result t,count(t) from t1 group by t limit 10;
 
2109
t       count(t)
 
2110
a      1
 
2111
a       10
 
2112
b       10
 
2113
c       10
 
2114
d       10
 
2115
e       10
 
2116
f       10
 
2117
g       10
 
2118
h       10
 
2119
i       10
 
2120
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
 
2121
show create table t1;
 
2122
Table   Create Table
 
2123
t1      CREATE TABLE `t1` (
 
2124
  `v` varchar(300) DEFAULT NULL,
 
2125
  `c` char(10) DEFAULT NULL,
 
2126
  `t` text,
 
2127
  KEY `c` (`c`),
 
2128
  KEY `t` (`t`(10)),
 
2129
  KEY `v` (`v`)
 
2130
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2131
select count(*) from t1 where v='a';
 
2132
count(*)
 
2133
10
 
2134
select count(*) from t1 where v='a  ';
 
2135
count(*)
 
2136
10
 
2137
select count(*) from t1 where v between 'a' and 'a ';
 
2138
count(*)
 
2139
10
 
2140
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
 
2141
count(*)
 
2142
10
 
2143
select count(*) from t1 where v like 'a%';
 
2144
count(*)
 
2145
11
 
2146
select count(*) from t1 where v like 'a %';
 
2147
count(*)
 
2148
9
 
2149
explain select count(*) from t1 where v='a  ';
 
2150
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2151
1       SIMPLE  t1      ref     v       v       303     const   #       Using where; Using index
 
2152
explain select count(*) from t1 where v like 'a%';
 
2153
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2154
1       SIMPLE  t1      range   v       v       303     NULL    #       Using where; Using index
 
2155
explain select count(*) from t1 where v between 'a' and 'a ';
 
2156
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2157
1       SIMPLE  t1      ref     v       v       303     const   #       Using where; Using index
 
2158
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
 
2159
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2160
1       SIMPLE  t1      ref     v       v       303     const   #       Using where; Using index
 
2161
explain select * from t1 where v='a';
 
2162
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2163
1       SIMPLE  t1      ref     v       v       303     const   #       Using where
 
2164
select v,count(*) from t1 group by v limit 10;
 
2165
v       count(*)
 
2166
a      1
 
2167
a       10
 
2168
b       10
 
2169
c       10
 
2170
d       10
 
2171
e       10
 
2172
f       10
 
2173
g       10
 
2174
h       10
 
2175
i       10
 
2176
select v,count(t) from t1 group by v limit 10;
 
2177
v       count(t)
 
2178
a      1
 
2179
a       10
 
2180
b       10
 
2181
c       10
 
2182
d       10
 
2183
e       10
 
2184
f       10
 
2185
g       10
 
2186
h       10
 
2187
i       10
 
2188
select sql_big_result v,count(t) from t1 group by v limit 10;
 
2189
v       count(t)
 
2190
a      1
 
2191
a       10
 
2192
b       10
 
2193
c       10
 
2194
d       10
 
2195
e       10
 
2196
f       10
 
2197
g       10
 
2198
h       10
 
2199
i       10
 
2200
alter table t1 drop key v, add key v (v(30));
 
2201
show create table t1;
 
2202
Table   Create Table
 
2203
t1      CREATE TABLE `t1` (
 
2204
  `v` varchar(300) DEFAULT NULL,
 
2205
  `c` char(10) DEFAULT NULL,
 
2206
  `t` text,
 
2207
  KEY `c` (`c`),
 
2208
  KEY `t` (`t`(10)),
 
2209
  KEY `v` (`v`(30))
 
2210
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2211
select count(*) from t1 where v='a';
 
2212
count(*)
 
2213
10
 
2214
select count(*) from t1 where v='a  ';
 
2215
count(*)
 
2216
10
 
2217
select count(*) from t1 where v between 'a' and 'a ';
 
2218
count(*)
 
2219
10
 
2220
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
 
2221
count(*)
 
2222
10
 
2223
select count(*) from t1 where v like 'a%';
 
2224
count(*)
 
2225
11
 
2226
select count(*) from t1 where v like 'a %';
 
2227
count(*)
 
2228
9
 
2229
explain select count(*) from t1 where v='a  ';
 
2230
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2231
1       SIMPLE  t1      ref     v       v       33      const   #       Using where
 
2232
explain select count(*) from t1 where v like 'a%';
 
2233
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2234
1       SIMPLE  t1      range   v       v       33      NULL    #       Using where
 
2235
explain select count(*) from t1 where v between 'a' and 'a ';
 
2236
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2237
1       SIMPLE  t1      ref     v       v       33      const   #       Using where
 
2238
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
 
2239
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2240
1       SIMPLE  t1      ref     v       v       33      const   #       Using where
 
2241
explain select * from t1 where v='a';
 
2242
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2243
1       SIMPLE  t1      ref     v       v       33      const   #       Using where
 
2244
select v,count(*) from t1 group by v limit 10;
 
2245
v       count(*)
 
2246
a      1
 
2247
a       10
 
2248
b       10
 
2249
c       10
 
2250
d       10
 
2251
e       10
 
2252
f       10
 
2253
g       10
 
2254
h       10
 
2255
i       10
 
2256
select v,count(t) from t1 group by v limit 10;
 
2257
v       count(t)
 
2258
a      1
 
2259
a       10
 
2260
b       10
 
2261
c       10
 
2262
d       10
 
2263
e       10
 
2264
f       10
 
2265
g       10
 
2266
h       10
 
2267
i       10
 
2268
select sql_big_result v,count(t) from t1 group by v limit 10;
 
2269
v       count(t)
 
2270
a      1
 
2271
a       10
 
2272
b       10
 
2273
c       10
 
2274
d       10
 
2275
e       10
 
2276
f       10
 
2277
g       10
 
2278
h       10
 
2279
i       10
 
2280
alter table t1 modify v varchar(600), drop key v, add key v (v);
 
2281
show create table t1;
 
2282
Table   Create Table
 
2283
t1      CREATE TABLE `t1` (
 
2284
  `v` varchar(600) DEFAULT NULL,
 
2285
  `c` char(10) DEFAULT NULL,
 
2286
  `t` text,
 
2287
  KEY `c` (`c`),
 
2288
  KEY `t` (`t`(10)),
 
2289
  KEY `v` (`v`)
 
2290
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2291
select v,count(*) from t1 group by v limit 10;
 
2292
v       count(*)
 
2293
a      1
 
2294
a       10
 
2295
b       10
 
2296
c       10
 
2297
d       10
 
2298
e       10
 
2299
f       10
 
2300
g       10
 
2301
h       10
 
2302
i       10
 
2303
select v,count(t) from t1 group by v limit 10;
 
2304
v       count(t)
 
2305
a      1
 
2306
a       10
 
2307
b       10
 
2308
c       10
 
2309
d       10
 
2310
e       10
 
2311
f       10
 
2312
g       10
 
2313
h       10
 
2314
i       10
 
2315
select sql_big_result v,count(t) from t1 group by v limit 10;
 
2316
v       count(t)
 
2317
a      1
 
2318
a       10
 
2319
b       10
 
2320
c       10
 
2321
d       10
 
2322
e       10
 
2323
f       10
 
2324
g       10
 
2325
h       10
 
2326
i       10
 
2327
drop table t1;
 
2328
create table t1 (a char(10), unique (a));
 
2329
insert into t1 values ('a   ');
 
2330
insert into t1 values ('a ');
 
2331
ERROR 23000: Duplicate entry 'a' for key 'a'
 
2332
alter table t1 modify a varchar(10);
 
2333
insert into t1 values ('a '),('a  '),('a   '),('a         ');
 
2334
ERROR 23000: Duplicate entry 'a ' for key 'a'
 
2335
insert into t1 values ('a     ');
 
2336
ERROR 23000: Duplicate entry 'a     ' for key 'a'
 
2337
insert into t1 values ('a          ');
 
2338
ERROR 23000: Duplicate entry 'a         ' for key 'a'
 
2339
insert into t1 values ('a ');
 
2340
ERROR 23000: Duplicate entry 'a ' for key 'a'
 
2341
update t1 set a='a  ' where a like 'a%';
 
2342
select concat(a,'.') from t1;
 
2343
concat(a,'.')
 
2344
a  .
 
2345
update t1 set a='abc    ' where a like 'a ';
 
2346
select concat(a,'.') from t1;
 
2347
concat(a,'.')
 
2348
a  .
 
2349
update t1 set a='a      ' where a like 'a %';
 
2350
select concat(a,'.') from t1;
 
2351
concat(a,'.')
 
2352
a      .
 
2353
update t1 set a='a  ' where a like 'a      ';
 
2354
select concat(a,'.') from t1;
 
2355
concat(a,'.')
 
2356
a  .
 
2357
drop table t1;
 
2358
create table t1 (v varchar(10), c char(10), t text, key(v(5)), key(c(5)), key(t(5)));
 
2359
show create table t1;
 
2360
Table   Create Table
 
2361
t1      CREATE TABLE `t1` (
 
2362
  `v` varchar(10) DEFAULT NULL,
 
2363
  `c` char(10) DEFAULT NULL,
 
2364
  `t` text,
 
2365
  KEY `v` (`v`(5)),
 
2366
  KEY `c` (`c`(5)),
 
2367
  KEY `t` (`t`(5))
 
2368
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2369
drop table t1;
 
2370
create table t1 (v char(10) character set utf8);
 
2371
show create table t1;
 
2372
Table   Create Table
 
2373
t1      CREATE TABLE `t1` (
 
2374
  `v` char(10) CHARACTER SET utf8 DEFAULT NULL
 
2375
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2376
drop table t1;
 
2377
create table t1 (v varchar(10), c char(10)) row_format=fixed;
 
2378
Warnings:
 
2379
Warning 1478    InnoDB: assuming ROW_FORMAT=COMPACT.
 
2380
show create table t1;
 
2381
Table   Create Table
 
2382
t1      CREATE TABLE `t1` (
 
2383
  `v` varchar(10) DEFAULT NULL,
 
2384
  `c` char(10) DEFAULT NULL
 
2385
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED
 
2386
insert into t1 values('a','a'),('a ','a ');
 
2387
select concat('*',v,'*',c,'*') from t1;
 
2388
concat('*',v,'*',c,'*')
 
2389
*a*a*
 
2390
*a *a*
 
2391
drop table t1;
 
2392
create table t1 (v varchar(65530), key(v(10)));
 
2393
insert into t1 values(repeat('a',65530));
 
2394
select length(v) from t1 where v=repeat('a',65530);
 
2395
length(v)
 
2396
65530
 
2397
drop table t1;
 
2398
create table t1(a int, b varchar(12), key ba(b, a));
 
2399
insert into t1 values (1, 'A'), (20, NULL);
 
2400
explain select * from t1 where a=20 and b is null;
 
2401
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2402
1       SIMPLE  t1      ref     ba      ba      20      const,const     1       Using where; Using index
 
2403
select * from t1 where a=20 and b is null;
 
2404
a       b
 
2405
20      NULL
 
2406
drop table t1;
 
2407
create table t1 (v varchar(65530), key(v));
 
2408
Warnings:
 
2409
Warning 1071    Specified key was too long; max key length is 767 bytes
 
2410
drop table t1;
 
2411
create table t1 (v varchar(65536));
 
2412
Warnings:
 
2413
Note    1246    Converting column 'v' from VARCHAR to TEXT
 
2414
show create table t1;
 
2415
Table   Create Table
 
2416
t1      CREATE TABLE `t1` (
 
2417
  `v` mediumtext
 
2418
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2419
drop table t1;
 
2420
create table t1 (v varchar(65530) character set utf8);
 
2421
Warnings:
 
2422
Note    1246    Converting column 'v' from VARCHAR to TEXT
 
2423
show create table t1;
 
2424
Table   Create Table
 
2425
t1      CREATE TABLE `t1` (
 
2426
  `v` mediumtext CHARACTER SET utf8
 
2427
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2428
drop table t1;
 
2429
set storage_engine=MyISAM;
 
2430
create table t1 (v varchar(16384)) engine=innodb;
 
2431
drop table t1;
 
2432
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
 
2433
insert into t1 values ('8', '6'), ('4', '7');
 
2434
select min(a) from t1;
 
2435
min(a)
 
2436
4
 
2437
select min(b) from t1 where a='8';
 
2438
min(b)
 
2439
6
 
2440
drop table t1;
 
2441
CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
 
2442
insert into t1 (b) values (1);
 
2443
replace into t1 (b) values (2), (1), (3);
 
2444
select * from t1;
 
2445
a       b
 
2446
3       1
 
2447
2       2
 
2448
4       3
 
2449
truncate table t1;
 
2450
insert into t1 (b) values (1);
 
2451
replace into t1 (b) values (2);
 
2452
replace into t1 (b) values (1);
 
2453
replace into t1 (b) values (3);
 
2454
select * from t1;
 
2455
a       b
 
2456
3       1
 
2457
2       2
 
2458
4       3
 
2459
drop table t1;
 
2460
create table t1 (rowid int not null auto_increment, val int not null,primary
 
2461
key (rowid), unique(val)) engine=innodb;
 
2462
replace into t1 (val) values ('1'),('2');
 
2463
replace into t1 (val) values ('1'),('2');
 
2464
insert into t1 (val) values ('1'),('2');
 
2465
ERROR 23000: Duplicate entry '1' for key 'val'
 
2466
select * from t1;
 
2467
rowid   val
 
2468
3       1
 
2469
4       2
 
2470
drop table t1;
 
2471
create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
 
2472
insert into t1 (val) values (1);
 
2473
update t1 set a=2 where a=1;
 
2474
insert into t1 (val) values (1);
 
2475
ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
 
2476
select * from t1;
 
2477
a       val
 
2478
2       1
 
2479
drop table t1;
 
2480
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
 
2481
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
 
2482
SELECT GRADE  FROM t1 WHERE GRADE > 160 AND GRADE < 300;
 
2483
GRADE
 
2484
252
 
2485
SELECT GRADE  FROM t1 WHERE GRADE= 151;
 
2486
GRADE
 
2487
151
 
2488
DROP TABLE t1;
 
2489
create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb;
 
2490
create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb;
 
2491
insert into t2 values ('aa','cc');
 
2492
insert into t1 values ('aa','bb'),('aa','cc');
 
2493
delete t1 from t1,t2 where f1=f3 and f4='cc';
 
2494
select * from t1;
 
2495
f1      f2
 
2496
drop table t1,t2;
 
2497
CREATE TABLE t1 (
 
2498
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
 
2499
) ENGINE=InnoDB;
 
2500
CREATE TABLE t2 (
 
2501
id INTEGER NOT NULL,
 
2502
FOREIGN KEY (id) REFERENCES t1 (id)
 
2503
) ENGINE=InnoDB;
 
2504
INSERT INTO t1 (id) VALUES (NULL);
 
2505
SELECT * FROM t1;
 
2506
id
 
2507
1
 
2508
TRUNCATE t1;
 
2509
INSERT INTO t1 (id) VALUES (NULL);
 
2510
SELECT * FROM t1;
 
2511
id
 
2512
1
 
2513
DELETE FROM t1;
 
2514
TRUNCATE t1;
 
2515
INSERT INTO t1 (id) VALUES (NULL);
 
2516
SELECT * FROM t1;
 
2517
id
 
2518
1
 
2519
DROP TABLE t2, t1;
 
2520
CREATE TABLE t1
 
2521
(
 
2522
id INT PRIMARY KEY
 
2523
) ENGINE=InnoDB;
 
2524
CREATE TEMPORARY TABLE t2
 
2525
(
 
2526
id INT NOT NULL PRIMARY KEY,
 
2527
b INT,
 
2528
FOREIGN KEY (b) REFERENCES test.t1(id)
 
2529
) ENGINE=InnoDB;
 
2530
Got one of the listed errors
 
2531
DROP TABLE t1;
 
2532
create table t1 (col1 varchar(2000), index (col1(767)))
 
2533
character set = latin1 engine = innodb;
 
2534
create table t2 (col1 char(255), index (col1))
 
2535
character set = latin1 engine = innodb;
 
2536
create table t3 (col1 binary(255), index (col1))
 
2537
character set = latin1 engine = innodb;
 
2538
create table t4 (col1 varchar(767), index (col1))
 
2539
character set = latin1 engine = innodb;
 
2540
create table t5 (col1 varchar(767) primary key)
 
2541
character set = latin1 engine = innodb;
 
2542
create table t6 (col1 varbinary(767) primary key)
 
2543
character set = latin1 engine = innodb;
 
2544
create table t7 (col1 text, index(col1(767)))
 
2545
character set = latin1 engine = innodb;
 
2546
create table t8 (col1 blob, index(col1(767)))
 
2547
character set = latin1 engine = innodb;
 
2548
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
 
2549
character set = latin1 engine = innodb;
 
2550
show create table t9;
 
2551
Table   Create Table
 
2552
t9      CREATE TABLE `t9` (
 
2553
  `col1` varchar(512) DEFAULT NULL,
 
2554
  `col2` varchar(512) DEFAULT NULL,
 
2555
  KEY `col1` (`col1`,`col2`)
 
2556
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2557
drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
 
2558
create table t1 (col1 varchar(768), index(col1))
 
2559
character set = latin1 engine = innodb;
 
2560
Warnings:
 
2561
Warning 1071    Specified key was too long; max key length is 767 bytes
 
2562
create table t2 (col1 varbinary(768), index(col1))
 
2563
character set = latin1 engine = innodb;
 
2564
Warnings:
 
2565
Warning 1071    Specified key was too long; max key length is 767 bytes
 
2566
create table t3 (col1 text, index(col1(768)))
 
2567
character set = latin1 engine = innodb;
 
2568
Warnings:
 
2569
Warning 1071    Specified key was too long; max key length is 767 bytes
 
2570
create table t4 (col1 blob, index(col1(768)))
 
2571
character set = latin1 engine = innodb;
 
2572
Warnings:
 
2573
Warning 1071    Specified key was too long; max key length is 767 bytes
 
2574
show create table t1;
 
2575
Table   Create Table
 
2576
t1      CREATE TABLE `t1` (
 
2577
  `col1` varchar(768) DEFAULT NULL,
 
2578
  KEY `col1` (`col1`(767))
 
2579
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2580
drop table t1, t2, t3, t4;
 
2581
create table t1 (col1 varchar(768) primary key)
 
2582
character set = latin1 engine = innodb;
 
2583
ERROR 42000: Specified key was too long; max key length is 767 bytes
 
2584
create table t2 (col1 varbinary(768) primary key)
 
2585
character set = latin1 engine = innodb;
 
2586
ERROR 42000: Specified key was too long; max key length is 767 bytes
 
2587
create table t3 (col1 text, primary key(col1(768)))
 
2588
character set = latin1 engine = innodb;
 
2589
ERROR 42000: Specified key was too long; max key length is 767 bytes
 
2590
create table t4 (col1 blob, primary key(col1(768)))
 
2591
character set = latin1 engine = innodb;
 
2592
ERROR 42000: Specified key was too long; max key length is 767 bytes
 
2593
CREATE TABLE t1
 
2594
(
 
2595
id INT PRIMARY KEY
 
2596
) ENGINE=InnoDB;
 
2597
CREATE TABLE t2
 
2598
(
 
2599
v INT,
 
2600
CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
 
2601
) ENGINE=InnoDB;
 
2602
INSERT INTO t2 VALUES(2);
 
2603
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
 
2604
INSERT INTO t1 VALUES(1);
 
2605
INSERT INTO t2 VALUES(1);
 
2606
DELETE FROM t1 WHERE id = 1;
 
2607
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
 
2608
DROP TABLE t1;
 
2609
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
 
2610
SET FOREIGN_KEY_CHECKS=0;
 
2611
DROP TABLE t1;
 
2612
SET FOREIGN_KEY_CHECKS=1;
 
2613
INSERT INTO t2 VALUES(3);
 
2614
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
 
2615
DROP TABLE t2;
 
2616
create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
 
2617
insert into t1 values (1),(2);
 
2618
set autocommit=0;
 
2619
checksum table t1;
 
2620
Table   Checksum
 
2621
test.t1 1531596814
 
2622
insert into t1 values(3);
 
2623
checksum table t1;
 
2624
Table   Checksum
 
2625
test.t1 1531596814
 
2626
commit;
 
2627
checksum table t1;
 
2628
Table   Checksum
 
2629
test.t1 2050879373
 
2630
commit;
 
2631
drop table t1;
 
2632
create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
 
2633
insert into t1 values (1),(2);
 
2634
set autocommit=1;
 
2635
checksum table t1;
 
2636
Table   Checksum
 
2637
test.t1 1531596814
 
2638
set autocommit=1;
 
2639
insert into t1 values(3);
 
2640
checksum table t1;
 
2641
Table   Checksum
 
2642
test.t1 2050879373
 
2643
drop table t1;
 
2644
set foreign_key_checks=0;
 
2645
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
 
2646
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
 
2647
ERROR HY000: Can't create table 'test.t1' (errno: 150)
 
2648
set foreign_key_checks=1;
 
2649
drop table t2;
 
2650
set foreign_key_checks=0;
 
2651
create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
 
2652
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=utf8;
 
2653
ERROR HY000: Can't create table 'test.t2' (errno: 150)
 
2654
set foreign_key_checks=1;
 
2655
drop table t1;
 
2656
set foreign_key_checks=0;
 
2657
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
 
2658
create table t1(a varchar(10) primary key) engine = innodb;
 
2659
alter table t1 modify column a int;
 
2660
Got one of the listed errors
 
2661
set foreign_key_checks=1;
 
2662
drop table t2,t1;
 
2663
set foreign_key_checks=0;
 
2664
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
 
2665
create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
 
2666
alter table t1 convert to character set utf8;
 
2667
set foreign_key_checks=1;
 
2668
drop table t2,t1;
 
2669
set foreign_key_checks=0;
 
2670
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
 
2671
create table t3(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=utf8;
 
2672
rename table t3 to t1;
 
2673
ERROR HY000: Error on rename of './test/t3' to './test/t1' (errno: 150)
 
2674
set foreign_key_checks=1;
 
2675
drop table t2,t3;
 
2676
create table t1(a int primary key) row_format=redundant engine=innodb;
 
2677
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
 
2678
create table t3(a int primary key) row_format=compact engine=innodb;
 
2679
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
 
2680
insert into t1 values(1);
 
2681
insert into t3 values(1);
 
2682
insert into t2 values(2);
 
2683
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`))
 
2684
insert into t4 values(2);
 
2685
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`))
 
2686
insert into t2 values(1);
 
2687
insert into t4 values(1);
 
2688
update t1 set a=2;
 
2689
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`))
 
2690
update t2 set a=2;
 
2691
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`))
 
2692
update t3 set a=2;
 
2693
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`))
 
2694
update t4 set a=2;
 
2695
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`))
 
2696
truncate t1;
 
2697
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`))
 
2698
truncate t3;
 
2699
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`))
 
2700
truncate t2;
 
2701
truncate t4;
 
2702
truncate t1;
 
2703
truncate t3;
 
2704
drop table t4,t3,t2,t1;
 
2705
create table t1 (a varchar(255) character set utf8,
 
2706
b varchar(255) character set utf8,
 
2707
c varchar(255) character set utf8,
 
2708
d varchar(255) character set utf8,
 
2709
key (a,b,c,d)) engine=innodb;
 
2710
drop table t1;
 
2711
create table t1 (a varchar(255) character set utf8,
 
2712
b varchar(255) character set utf8,
 
2713
c varchar(255) character set utf8,
 
2714
d varchar(255) character set utf8,
 
2715
e varchar(255) character set utf8,
 
2716
key (a,b,c,d,e)) engine=innodb;
 
2717
ERROR 42000: Specified key was too long; max key length is 3072 bytes
 
2718
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
 
2719
create table t2 (s1 binary(2),primary key (s1)) engine=innodb;
 
2720
create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb;
 
2721
create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb;
 
2722
insert into t1 values (0x41),(0x4120),(0x4100);
 
2723
insert into t2 values (0x41),(0x4120),(0x4100);
 
2724
ERROR 23000: Duplicate entry 'A' for key 'PRIMARY'
 
2725
insert into t2 values (0x41),(0x4120);
 
2726
insert into t3 values (0x41),(0x4120),(0x4100);
 
2727
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
 
2728
insert into t3 values (0x41),(0x4100);
 
2729
insert into t4 values (0x41),(0x4120),(0x4100);
 
2730
ERROR 23000: Duplicate entry 'A' for key 'PRIMARY'
 
2731
insert into t4 values (0x41),(0x4100);
 
2732
select hex(s1) from t1;
 
2733
hex(s1)
 
2734
41
 
2735
4100
 
2736
4120
 
2737
select hex(s1) from t2;
 
2738
hex(s1)
 
2739
4100
 
2740
4120
 
2741
select hex(s1) from t3;
 
2742
hex(s1)
 
2743
4100
 
2744
41
 
2745
select hex(s1) from t4;
 
2746
hex(s1)
 
2747
4100
 
2748
41
 
2749
drop table t1,t2,t3,t4;
 
2750
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
 
2751
create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
 
2752
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
 
2753
insert into t2 values(0x42);
 
2754
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
 
2755
insert into t2 values(0x41);
 
2756
select hex(s1) from t2;
 
2757
hex(s1)
 
2758
4100
 
2759
update t1 set s1=0x123456 where a=2;
 
2760
select hex(s1) from t2;
 
2761
hex(s1)
 
2762
4100
 
2763
update t1 set s1=0x12 where a=1;
 
2764
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)
 
2765
update t1 set s1=0x12345678 where a=1;
 
2766
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)
 
2767
update t1 set s1=0x123457 where a=1;
 
2768
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)
 
2769
update t1 set s1=0x1220 where a=1;
 
2770
select hex(s1) from t2;
 
2771
hex(s1)
 
2772
1220
 
2773
update t1 set s1=0x1200 where a=1;
 
2774
select hex(s1) from t2;
 
2775
hex(s1)
 
2776
1200
 
2777
update t1 set s1=0x4200 where a=1;
 
2778
select hex(s1) from t2;
 
2779
hex(s1)
 
2780
4200
 
2781
delete from t1 where a=1;
 
2782
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)
 
2783
delete from t1 where a=2;
 
2784
update t2 set s1=0x4120;
 
2785
delete from t1;
 
2786
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)
 
2787
delete from t1 where a!=3;
 
2788
select a,hex(s1) from t1;
 
2789
a       hex(s1)
 
2790
3       4120
 
2791
select hex(s1) from t2;
 
2792
hex(s1)
 
2793
4120
 
2794
drop table t2,t1;
 
2795
create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=innodb;
 
2796
create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
 
2797
insert into t1 values(1,0x4100),(2,0x41);
 
2798
insert into t2 values(0x41);
 
2799
select hex(s1) from t2;
 
2800
hex(s1)
 
2801
41
 
2802
update t1 set s1=0x1234 where a=1;
 
2803
select hex(s1) from t2;
 
2804
hex(s1)
 
2805
41
 
2806
update t1 set s1=0x12 where a=2;
 
2807
select hex(s1) from t2;
 
2808
hex(s1)
 
2809
12
 
2810
delete from t1 where a=1;
 
2811
delete from t1 where a=2;
 
2812
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)
 
2813
select a,hex(s1) from t1;
 
2814
a       hex(s1)
 
2815
2       12
 
2816
select hex(s1) from t2;
 
2817
hex(s1)
 
2818
12
 
2819
drop table t2,t1;
 
2820
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
 
2821
CREATE TABLE t2(a INT) ENGINE=InnoDB;
 
2822
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
 
2823
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
 
2824
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
 
2825
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
 
2826
SHOW CREATE TABLE t2;
 
2827
Table   Create Table
 
2828
t2      CREATE TABLE `t2` (
 
2829
  `a` int(11) DEFAULT NULL,
 
2830
  KEY `t2_ibfk_0` (`a`)
 
2831
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2832
DROP TABLE t2,t1;
 
2833
create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
 
2834
insert into t1(a) values (1),(2),(3);
 
2835
commit;
 
2836
set autocommit = 0;
 
2837
update t1 set b = 5 where a = 2;
 
2838
create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
 
2839
set autocommit = 0;
 
2840
insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
 
2841
(11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
 
2842
(12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
 
2843
(13),(23),(33),(43),(53),(63),(73),(83),(93),(103),
 
2844
(14),(24),(34),(44),(54),(64),(74),(84),(94),(104);
 
2845
commit;
 
2846
commit;
 
2847
drop trigger t1t;
 
2848
drop table t1;
 
2849
create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
 
2850
create table t2(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
 
2851
create table t3(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
 
2852
create table t4(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
 
2853
create table t5(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
 
2854
insert into t1(a) values (1),(2),(3);
 
2855
insert into t2(a) values (1),(2),(3);
 
2856
insert into t3(a) values (1),(2),(3);
 
2857
insert into t4(a) values (1),(2),(3);
 
2858
insert into t3(a) values (5),(7),(8);
 
2859
insert into t4(a) values (5),(7),(8);
 
2860
insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
 
2861
create trigger t1t before insert on t1 for each row begin 
 
2862
INSERT INTO t2 SET a = NEW.a;
 
2863
end |
 
2864
create trigger t2t before insert on t2 for each row begin
 
2865
DELETE FROM t3 WHERE a = NEW.a;
 
2866
end |
 
2867
create trigger t3t before delete on t3 for each row begin  
 
2868
UPDATE t4 SET b = b + 1 WHERE a = OLD.a;
 
2869
end |
 
2870
create trigger t4t before update on t4 for each row begin
 
2871
UPDATE t5 SET b = b + 1 where a = NEW.a;
 
2872
end |
 
2873
commit;
 
2874
set autocommit = 0;
 
2875
update t1 set b = b + 5 where a = 1;
 
2876
update t2 set b = b + 5 where a = 1;
 
2877
update t3 set b = b + 5 where a = 1;
 
2878
update t4 set b = b + 5 where a = 1;
 
2879
insert into t5(a) values(20);
 
2880
set autocommit = 0;
 
2881
insert into t1(a) values(7);
 
2882
insert into t2(a) values(8);
 
2883
delete from t2 where a = 3;
 
2884
update t4 set b = b + 1 where a = 3;
 
2885
commit;
 
2886
drop trigger t1t;
 
2887
drop trigger t2t;
 
2888
drop trigger t3t;
 
2889
drop trigger t4t;
 
2890
drop table t1, t2, t3, t4, t5;
 
2891
CREATE TABLE t1 (
 
2892
field1 varchar(8) NOT NULL DEFAULT '',
 
2893
field2 varchar(8) NOT NULL DEFAULT '',
 
2894
PRIMARY KEY  (field1, field2)
 
2895
) ENGINE=InnoDB;
 
2896
CREATE TABLE t2 (
 
2897
field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
 
2898
FOREIGN KEY (field1) REFERENCES t1 (field1)
 
2899
ON DELETE CASCADE ON UPDATE CASCADE
 
2900
) ENGINE=InnoDB;
 
2901
INSERT INTO t1 VALUES ('old', 'somevalu');
 
2902
INSERT INTO t1 VALUES ('other', 'anyvalue');
 
2903
INSERT INTO t2 VALUES ('old');
 
2904
INSERT INTO t2 VALUES ('other');
 
2905
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
 
2906
ERROR 23000: Upholding foreign key constraints for table 't1', entry 'other-somevalu', key 1 would lead to a duplicate entry
 
2907
DROP TABLE t2;
 
2908
DROP TABLE t1;
 
2909
create table t1 (
 
2910
c1 bigint not null,
 
2911
c2 bigint not null,
 
2912
primary key (c1),
 
2913
unique  key (c2)
 
2914
) engine=innodb;
 
2915
create table t2 (
 
2916
c1 bigint not null,
 
2917
primary key (c1)
 
2918
) engine=innodb;
 
2919
alter table t1 add constraint c2_fk foreign key (c2)
 
2920
references t2(c1) on delete cascade;
 
2921
show create table t1;
 
2922
Table   Create Table
 
2923
t1      CREATE TABLE `t1` (
 
2924
  `c1` bigint(20) NOT NULL,
 
2925
  `c2` bigint(20) NOT NULL,
 
2926
  PRIMARY KEY (`c1`),
 
2927
  UNIQUE KEY `c2` (`c2`),
 
2928
  CONSTRAINT `c2_fk` FOREIGN KEY (`c2`) REFERENCES `t2` (`c1`) ON DELETE CASCADE
 
2929
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2930
alter table t1 drop foreign key c2_fk;
 
2931
show create table t1;
 
2932
Table   Create Table
 
2933
t1      CREATE TABLE `t1` (
 
2934
  `c1` bigint(20) NOT NULL,
 
2935
  `c2` bigint(20) NOT NULL,
 
2936
  PRIMARY KEY (`c1`),
 
2937
  UNIQUE KEY `c2` (`c2`)
 
2938
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
2939
drop table t1, t2;
 
2940
create table t1(a date) engine=innodb;
 
2941
create table t2(a date, key(a)) engine=innodb;
 
2942
insert into t1 values('2005-10-01');
 
2943
insert into t2 values('2005-10-01');
 
2944
select * from t1, t2
 
2945
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
 
2946
a       a
 
2947
2005-10-01      2005-10-01
 
2948
drop table t1, t2;
 
2949
create table t1 (id int not null, f_id int not null, f int not null,
 
2950
primary key(f_id, id)) engine=innodb;
 
2951
create table t2 (id int not null,s_id int not null,s varchar(200),
 
2952
primary key(id)) engine=innodb;
 
2953
INSERT INTO t1 VALUES (8, 1, 3);
 
2954
INSERT INTO t1 VALUES (1, 2, 1);
 
2955
INSERT INTO t2 VALUES (1, 0, '');
 
2956
INSERT INTO t2 VALUES (8, 1, '');
 
2957
commit;
 
2958
DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
 
2959
WHERE mm.id IS NULL;
 
2960
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
 
2961
where mm.id is null lock in share mode;
 
2962
id      f_id    f
 
2963
drop table t1,t2;
 
2964
create table t1(a int not null, b int, primary key(a)) engine=innodb;
 
2965
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
 
2966
commit;
 
2967
SET binlog_format='MIXED';
 
2968
set autocommit = 0;
 
2969
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
2970
update t1 set b = 5 where b = 1;
 
2971
SET binlog_format='MIXED';
 
2972
set autocommit = 0;
 
2973
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
2974
select * from t1 where a = 7 and b = 3 for update;
 
2975
a       b
 
2976
7       3
 
2977
commit;
 
2978
commit;
 
2979
drop table t1;
 
2980
create table t1(a int not null, b int, primary key(a)) engine=innodb;
 
2981
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
 
2982
commit;
 
2983
set autocommit = 0;
 
2984
select * from t1 lock in share mode;
 
2985
a       b
 
2986
1       1
 
2987
2       2
 
2988
3       1
 
2989
4       2
 
2990
5       1
 
2991
6       2
 
2992
update t1 set b = 5 where b = 1;
 
2993
set autocommit = 0;
 
2994
select * from t1 where a = 2 and b = 2 for update;
 
2995
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
2996
commit;
 
2997
commit;
 
2998
drop table t1;
 
2999
create table t1(a int not null, b int, primary key(a)) engine=innodb;
 
3000
insert into t1 values (1,2),(5,3),(4,2);
 
3001
create table t2(d int not null, e int, primary key(d)) engine=innodb;
 
3002
insert into t2 values (8,6),(12,1),(3,1);
 
3003
commit;
 
3004
set autocommit = 0;
 
3005
select * from t2 for update;
 
3006
d       e
 
3007
3       1
 
3008
8       6
 
3009
12      1
 
3010
SET binlog_format='MIXED';
 
3011
set autocommit = 0;
 
3012
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
3013
insert into t1 select * from t2;
 
3014
update t1 set b = (select e from t2 where a = d);
 
3015
create table t3(d int not null, e int, primary key(d)) engine=innodb
 
3016
select * from t2;
 
3017
commit;
 
3018
commit;
 
3019
drop table t1, t2, t3;
 
3020
create table t1(a int not null, b int, primary key(a)) engine=innodb;
 
3021
insert into t1 values (1,2),(5,3),(4,2);
 
3022
create table t2(a int not null, b int, primary key(a)) engine=innodb;
 
3023
insert into t2 values (8,6),(12,1),(3,1);
 
3024
create table t3(d int not null, b int, primary key(d)) engine=innodb;
 
3025
insert into t3 values (8,6),(12,1),(3,1);
 
3026
create table t5(a int not null, b int, primary key(a)) engine=innodb;
 
3027
insert into t5 values (1,2),(5,3),(4,2);
 
3028
create table t6(d int not null, e int, primary key(d)) engine=innodb;
 
3029
insert into t6 values (8,6),(12,1),(3,1);
 
3030
create table t8(a int not null, b int, primary key(a)) engine=innodb;
 
3031
insert into t8 values (1,2),(5,3),(4,2);
 
3032
create table t9(d int not null, e int, primary key(d)) engine=innodb;
 
3033
insert into t9 values (8,6),(12,1),(3,1);
 
3034
commit;
 
3035
set autocommit = 0;
 
3036
select * from t2 for update;
 
3037
a       b
 
3038
3       1
 
3039
8       6
 
3040
12      1
 
3041
SET binlog_format='MIXED';
 
3042
set autocommit = 0;
 
3043
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
 
3044
insert into t1 select * from t2;
 
3045
SET binlog_format='MIXED';
 
3046
set autocommit = 0;
 
3047
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
 
3048
update t3 set b = (select b from t2 where a = d);
 
3049
SET binlog_format='MIXED';
 
3050
set autocommit = 0;
 
3051
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
 
3052
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
 
3053
SET binlog_format='MIXED';
 
3054
set autocommit = 0;
 
3055
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
3056
insert into t5 (select * from t2 lock in share mode);
 
3057
SET binlog_format='MIXED';
 
3058
set autocommit = 0;
 
3059
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
3060
update t6 set e = (select b from t2 where a = d lock in share mode);
 
3061
SET binlog_format='MIXED';
 
3062
set autocommit = 0;
 
3063
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
3064
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
 
3065
SET binlog_format='MIXED';
 
3066
set autocommit = 0;
 
3067
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
3068
insert into t8 (select * from t2 for update);
 
3069
SET binlog_format='MIXED';
 
3070
set autocommit = 0;
 
3071
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
3072
update t9 set e = (select b from t2 where a = d for update);
 
3073
SET binlog_format='MIXED';
 
3074
set autocommit = 0;
 
3075
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
3076
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
 
3077
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3078
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3079
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3080
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3081
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3082
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3083
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3084
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3085
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
3086
commit;
 
3087
drop table t1, t2, t3, t5, t6, t8, t9;
 
3088
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
 
3089
ERROR HY000: Can't create table 'test.t1' (errno: -1)
 
3090
CREATE TABLE t1 (
 
3091
a BIGINT(20) NOT NULL,
 
3092
PRIMARY KEY  (a)
 
3093
) ENGINE=INNODB DEFAULT CHARSET=UTF8;
 
3094
CREATE TABLE t2 (
 
3095
a BIGINT(20) NOT NULL,
 
3096
b VARCHAR(128) NOT NULL,
 
3097
c TEXT NOT NULL,
 
3098
PRIMARY KEY  (a,b),
 
3099
KEY idx_t2_b_c (b,c(200)),
 
3100
CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a) 
 
3101
ON DELETE CASCADE
 
3102
) ENGINE=INNODB DEFAULT CHARSET=UTF8;
 
3103
INSERT INTO t1 VALUES (1);
 
3104
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
 
3105
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
 
3106
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
 
3107
INSERT INTO t2 VALUES (1, 'customer_over', '1');
 
3108
SELECT * FROM t2 WHERE b = 'customer_over';
 
3109
a       b       c
 
3110
1       customer_over   1
 
3111
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
 
3112
a       b       c
 
3113
1       customer_over   1
 
3114
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
 
3115
a
 
3116
1
 
3117
/* Bang: Empty result set, above was expected: */
 
3118
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
 
3119
a
 
3120
1
 
3121
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
 
3122
a
 
3123
1
 
3124
drop table t2, t1;
 
3125
CREATE TABLE t1 ( a int ) ENGINE=innodb;
 
3126
BEGIN;
 
3127
INSERT INTO t1 VALUES (1);
 
3128
OPTIMIZE TABLE t1;
 
3129
Table   Op      Msg_type        Msg_text
 
3130
test.t1 optimize        note    Table does not support optimize, doing recreate + analyze instead
 
3131
test.t1 optimize        status  OK
 
3132
DROP TABLE t1;
 
3133
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
 
3134
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
 
3135
CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
 
3136
ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
 
3137
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
 
3138
DELETE CASCADE ON UPDATE CASCADE;
 
3139
SHOW CREATE TABLE t2;
 
3140
Table   Create Table
 
3141
t2      CREATE TABLE `t2` (
 
3142
  `id` int(11) NOT NULL,
 
3143
  `f` int(11) NOT NULL,
 
3144
  PRIMARY KEY (`id`),
 
3145
  KEY `f` (`f`),
 
3146
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f`) REFERENCES `t1` (`f`) ON DELETE CASCADE ON UPDATE CASCADE,
 
3147
  CONSTRAINT `t2_t1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
 
3148
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
3149
DROP TABLE t2, t1;
 
3150
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
 
3151
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
 
3152
INSERT INTO t1 VALUES (1);
 
3153
INSERT INTO t2 VALUES (1);
 
3154
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
 
3155
ALTER TABLE t2 MODIFY a INT NOT NULL;
 
3156
ERROR HY000: Error on rename of '#sql-temporary' to './test/t2' (errno: 150)
 
3157
DELETE FROM t1;
 
3158
DROP TABLE t2,t1;
 
3159
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
 
3160
ENGINE=InnoDB;
 
3161
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
 
3162
DELETE FROM t1;
 
3163
INSERT INTO t1 VALUES ('DDD');
 
3164
SELECT * FROM t1;
 
3165
a
 
3166
DDD
 
3167
DROP TABLE t1;
 
3168
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
 
3169
AUTO_INCREMENT=42;
 
3170
INSERT INTO t1 VALUES (0),(347),(0);
 
3171
SELECT * FROM t1;
 
3172
id
 
3173
42
 
3174
347
 
3175
348
 
3176
SHOW CREATE TABLE t1;
 
3177
Table   Create Table
 
3178
t1      CREATE TABLE `t1` (
 
3179
  `id` int(11) NOT NULL AUTO_INCREMENT,
 
3180
  PRIMARY KEY (`id`)
 
3181
) ENGINE=InnoDB AUTO_INCREMENT=349 DEFAULT CHARSET=latin1
 
3182
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
 
3183
INSERT INTO t2 VALUES(42),(347),(348);
 
3184
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
 
3185
SHOW CREATE TABLE t1;
 
3186
Table   Create Table
 
3187
t1      CREATE TABLE `t1` (
 
3188
  `id` int(11) NOT NULL AUTO_INCREMENT,
 
3189
  PRIMARY KEY (`id`),
 
3190
  CONSTRAINT `t1_t2` FOREIGN KEY (`id`) REFERENCES `t2` (`id`)
 
3191
) ENGINE=InnoDB AUTO_INCREMENT=349 DEFAULT CHARSET=latin1
 
3192
DROP TABLE t1,t2;
 
3193
set innodb_strict_mode=on;
 
3194
CREATE TABLE t1 (
 
3195
c01 CHAR(255), c02 CHAR(255), c03 CHAR(255), c04 CHAR(255),
 
3196
c05 CHAR(255), c06 CHAR(255), c07 CHAR(255), c08 CHAR(255),
 
3197
c09 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
 
3198
c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
 
3199
c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
 
3200
c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
 
3201
c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
 
3202
c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255)
 
3203
) ENGINE = InnoDB;
 
3204
ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. You have to change some columns to TEXT or BLOBs
 
3205
DROP TABLE IF EXISTS t1;
 
3206
Warnings:
 
3207
Note    1051    Unknown table 't1'
 
3208
CREATE TABLE t1(
 
3209
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY
 
3210
) ENGINE=InnoDB;
 
3211
INSERT INTO t1 VALUES(-10);
 
3212
SELECT * FROM t1;
 
3213
id
 
3214
-10
 
3215
INSERT INTO t1 VALUES(NULL);
 
3216
SELECT * FROM t1;
 
3217
id
 
3218
-10
 
3219
1
 
3220
DROP TABLE t1;
 
3221
SET binlog_format='MIXED';
 
3222
SET TX_ISOLATION='read-committed';
 
3223
SET AUTOCOMMIT=0;
 
3224
DROP TABLE IF EXISTS t1, t2;
 
3225
Warnings:
 
3226
Note    1051    Unknown table 't1'
 
3227
Note    1051    Unknown table 't2'
 
3228
CREATE TABLE t1 ( a int ) ENGINE=InnoDB;
 
3229
CREATE TABLE t2 LIKE t1;
 
3230
SELECT * FROM t2;
 
3231
a
 
3232
SET binlog_format='MIXED';
 
3233
SET TX_ISOLATION='read-committed';
 
3234
SET AUTOCOMMIT=0;
 
3235
INSERT INTO t1 VALUES (1);
 
3236
COMMIT;
 
3237
SELECT * FROM t1 WHERE a=1;
 
3238
a
 
3239
1
 
3240
SET binlog_format='MIXED';
 
3241
SET TX_ISOLATION='read-committed';
 
3242
SET AUTOCOMMIT=0;
 
3243
SELECT * FROM t2;
 
3244
a
 
3245
SET binlog_format='MIXED';
 
3246
SET TX_ISOLATION='read-committed';
 
3247
SET AUTOCOMMIT=0;
 
3248
INSERT INTO t1 VALUES (2);
 
3249
COMMIT;
 
3250
SELECT * FROM t1 WHERE a=2;
 
3251
a
 
3252
2
 
3253
SELECT * FROM t1 WHERE a=2;
 
3254
a
 
3255
2
 
3256
DROP TABLE t1;
 
3257
DROP TABLE t2;
 
3258
create table t1 (i int, j int) engine=innodb;
 
3259
insert into t1 (i, j) values (1, 1), (2, 2);
 
3260
update t1 set j = 2;
 
3261
affected rows: 1
 
3262
info: Rows matched: 2  Changed: 1  Warnings: 0
 
3263
drop table t1;
 
3264
create table t1 (id int) comment='this is a comment' engine=innodb;
 
3265
select table_comment, data_free > 0 as data_free_is_set
 
3266
from information_schema.tables
 
3267
where table_schema='test' and table_name = 't1';
 
3268
table_comment   data_free_is_set
 
3269
this is a comment       1
 
3270
drop table t1;
 
3271
CREATE TABLE t1 (
 
3272
c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
 
3273
c2 VARCHAR(128) NOT NULL,
 
3274
PRIMARY KEY(c1)
 
3275
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
 
3276
CREATE TABLE t2 (
 
3277
c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
 
3278
c2 INT(10) UNSIGNED DEFAULT NULL,
 
3279
PRIMARY KEY(c1)
 
3280
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
 
3281
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
 
3282
AUTO_INCREMENT
 
3283
200
 
3284
ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
 
3285
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
 
3286
AUTO_INCREMENT
 
3287
200
 
3288
DROP TABLE t2;
 
3289
DROP TABLE t1;
 
3290
CREATE TABLE t1 (c1 int default NULL,
 
3291
c2 int default NULL
 
3292
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
3293
TRUNCATE TABLE t1;
 
3294
affected rows: 0
 
3295
INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
 
3296
affected rows: 5
 
3297
info: Records: 5  Duplicates: 0  Warnings: 0
 
3298
TRUNCATE TABLE t1;
 
3299
affected rows: 0
 
3300
DROP TABLE t1;
 
3301
Variable_name   Value
 
3302
Handler_update  0
 
3303
Variable_name   Value
 
3304
Handler_delete  0
 
3305
Variable_name   Value
 
3306
Handler_update  1
 
3307
Variable_name   Value
 
3308
Handler_delete  1