~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

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