~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/r/innodb.result

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

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 not null auto_increment, code int not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
4
 
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
5
 
select id, code, name from t1 order by id;
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 NOT NULL auto_increment,
37
 
parent_id int DEFAULT '0' NOT NULL,
38
 
level int 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   4       const   #       Using index
145
 
explain select level,id from t1 where level=1;
146
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
147
 
1       SIMPLE  t1      ref     level   level   4       const   #       Using index
148
 
explain select level,id,parent_id from t1 where level=1;
149
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
150
 
1       SIMPLE  t1      ref     level   level   4       const   #       
151
 
select level,id from t1 where level=1;
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
 
alter table t1 ENGINE=innodb;
168
 
show keys from t1;
169
 
Table   Unique  Key_name        Seq_in_index    Column_name
170
 
t1      TRUE    PRIMARY 1       id
171
 
t1      FALSE   parent_id       1       parent_id
172
 
t1      FALSE   level   1       level
173
 
drop table t1;
174
 
CREATE TABLE t1 (
175
 
gesuchnr int DEFAULT '0' NOT NULL,
176
 
benutzer_id int DEFAULT '0' NOT NULL,
177
 
PRIMARY KEY (gesuchnr,benutzer_id)
178
 
) engine=innodb;
179
 
replace into t1 (gesuchnr,benutzer_id) values (2,1);
180
 
replace into t1 (gesuchnr,benutzer_id) values (1,1);
181
 
replace into t1 (gesuchnr,benutzer_id) values (1,1);
182
 
select * from t1;
183
 
gesuchnr        benutzer_id
184
 
1       1
185
 
2       1
186
 
drop table t1;
187
 
create table t1 (a int) engine=innodb;
188
 
insert into t1 values (1), (2);
189
 
alter table t1 engine=innodb;
190
 
delete from t1 where a = 1;
191
 
select * from t1;
192
 
a
193
 
2
194
 
check table t1;
195
 
Table   Op      Msg_type        Msg_text
196
 
test.t1 check   status  OK
197
 
drop table t1;
198
 
create table t1 (a int,b varchar(20)) engine=innodb;
199
 
insert into t1 values (1,""), (2,"testing");
200
 
delete from t1 where a = 1;
201
 
select * from t1;
202
 
a       b
203
 
2       testing
204
 
create index skr on t1 (a);
205
 
insert into t1 values (3,""), (4,"testing");
206
 
analyze table t1;
207
 
Table   Op      Msg_type        Msg_text
208
 
test.t1 analyze status  OK
209
 
show keys from t1;
210
 
Table   Unique  Key_name        Seq_in_index    Column_name
211
 
t1      FALSE   skr     1       a
212
 
drop table t1;
213
 
create table t1 (a int,b varchar(20),key(a)) engine=innodb;
214
 
insert into t1 values (1,""), (2,"testing");
215
 
select * from t1 where a = 1;
216
 
a       b
217
 
1       
218
 
drop table t1;
219
 
create table t1 (n int not null primary key) engine=innodb;
220
 
set autocommit=0;
221
 
insert into t1 values (4);
222
 
rollback;
223
 
select n, "after rollback" from t1;
224
 
n       after rollback
225
 
insert into t1 values (4);
226
 
commit;
227
 
select n, "after commit" from t1;
228
 
n       after commit
229
 
4       after commit
230
 
commit;
231
 
insert into t1 values (5);
232
 
insert into t1 values (4);
233
 
ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
234
 
commit;
235
 
select n, "after commit" from t1;
236
 
n       after commit
237
 
4       after commit
238
 
5       after commit
239
 
set autocommit=1;
240
 
insert into t1 values (6);
241
 
insert into t1 values (4);
242
 
ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
243
 
select n from t1;
244
 
n
245
 
4
246
 
5
247
 
6
248
 
set autocommit=0;
249
 
begin;
250
 
savepoint `my_savepoint`;
251
 
insert into t1 values (7);
252
 
savepoint `savept2`;
253
 
insert into t1 values (3);
254
 
select n from t1;
255
 
n
256
 
3
257
 
4
258
 
5
259
 
6
260
 
7
261
 
savepoint savept3;
262
 
rollback to savepoint savept2;
263
 
rollback to savepoint savept3;
264
 
ERROR 42000: SAVEPOINT savept3 does not exist
265
 
rollback to savepoint savept2;
266
 
release savepoint `my_savepoint`;
267
 
select n from t1;
268
 
n
269
 
4
270
 
5
271
 
6
272
 
7
273
 
rollback to savepoint `my_savepoint`;
274
 
ERROR 42000: SAVEPOINT my_savepoint does not exist
275
 
rollback to savepoint savept2;
276
 
insert into t1 values (8);
277
 
savepoint sv;
278
 
commit;
279
 
savepoint sv;
280
 
set autocommit=1;
281
 
rollback;
282
 
drop table t1;
283
 
create table t1 (n int not null primary key) engine=innodb;
284
 
start transaction;
285
 
insert into t1 values (4);
286
 
flush tables with read lock;
287
 
commit;
288
 
unlock tables;
289
 
commit;
290
 
select * from t1;
291
 
n
292
 
4
293
 
drop table t1;
294
 
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
295
 
begin;
296
 
insert into t1 values(1,'hamdouni');
297
 
select id as afterbegin_id,nom as afterbegin_nom from t1;
298
 
afterbegin_id   afterbegin_nom
299
 
1       hamdouni
300
 
rollback;
301
 
select id as afterrollback_id,nom as afterrollback_nom from t1;
302
 
afterrollback_id        afterrollback_nom
303
 
set autocommit=0;
304
 
insert into t1 values(2,'mysql');
305
 
select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
306
 
afterautocommit0_id     afterautocommit0_nom
307
 
2       mysql
308
 
rollback;
309
 
select id as afterrollback_id,nom as afterrollback_nom from t1;
310
 
afterrollback_id        afterrollback_nom
311
 
set autocommit=1;
312
 
drop table t1;
313
 
CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
314
 
insert into t1 values ('pippo', 12);
315
 
insert into t1 values ('pippo', 12);
316
 
ERROR 23000: Duplicate entry 'pippo' for key 'PRIMARY'
317
 
delete from t1;
318
 
delete from t1 where id = 'pippo';
319
 
select * from t1;
320
 
id      val
321
 
insert into t1 values ('pippo', 12);
322
 
set autocommit=0;
323
 
delete from t1;
324
 
rollback;
325
 
select * from t1;
326
 
id      val
327
 
pippo   12
328
 
delete from t1;
329
 
commit;
330
 
select * from t1;
331
 
id      val
332
 
drop table t1;
333
 
create table t1 (a integer) engine=innodb;
334
 
start transaction;
335
 
rename table t1 to t2;
336
 
create table t1 (b integer) engine=innodb;
337
 
insert into t1 values (1);
338
 
rollback;
339
 
drop table t1;
340
 
rename table t2 to t1;
341
 
drop table t1;
342
 
set autocommit=1;
343
 
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
344
 
INSERT INTO t1 VALUES (1, 'Jochen');
345
 
select * from t1;
346
 
ID      NAME
347
 
1       Jochen
348
 
drop table t1;
349
 
CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
350
 
set autocommit=0;
351
 
INSERT INTO t1  SET _userid='marc@anyware.co.uk';
352
 
COMMIT;
353
 
SELECT * FROM t1;
354
 
_userid
355
 
marc@anyware.co.uk
356
 
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
357
 
_userid
358
 
marc@anyware.co.uk
359
 
drop table t1;
360
 
set autocommit=1;
361
 
CREATE TABLE t1 (
362
 
user_id int DEFAULT '0' NOT NULL,
363
 
name varchar(100),
364
 
phone varchar(100),
365
 
ref_email varchar(100) DEFAULT '' NOT NULL,
366
 
detail varchar(200),
367
 
PRIMARY KEY (user_id,ref_email)
368
 
)engine=innodb;
369
 
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');
370
 
select * from t1 where user_id=10292;
371
 
user_id name    phone   ref_email       detail
372
 
10292   sanjeev 29153373        sansh777@hotmail.com    xxx
373
 
10292   shirish 2333604 shirish@yahoo.com       ddsds
374
 
10292   sonali  323232  sonali@bolly.com        filmstar
375
 
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
376
 
select * from t1 where user_id=10292;
377
 
user_id name    phone   ref_email       detail
378
 
10292   sanjeev 29153373        sansh777@hotmail.com    xxx
379
 
10292   shirish 2333604 shirish@yahoo.com       ddsds
380
 
10292   sonali  323232  sonali@bolly.com        filmstar
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
 
10293   shirish 2333604 shirish@yahoo.com       ddsds
387
 
select * from t1 where user_id>10292;
388
 
user_id name    phone   ref_email       detail
389
 
10293   shirish 2333604 shirish@yahoo.com       ddsds
390
 
select * from t1 where user_id<10292;
391
 
user_id name    phone   ref_email       detail
392
 
10291   sanjeev 29153373        sansh777@hotmail.com    xxx
393
 
drop table t1;
394
 
CREATE TABLE t1 (a int not null, b int not null,c int not null,
395
 
key(a),primary key(a,b), unique(c),key(a),unique(b));
396
 
show index from t1;
397
 
Table   Unique  Key_name        Seq_in_index    Column_name
398
 
t1      TRUE    PRIMARY 1       a
399
 
t1      TRUE    PRIMARY 2       b
400
 
t1      TRUE    c       1       c
401
 
t1      TRUE    b       1       b
402
 
t1      FALSE   a       1       a
403
 
t1      FALSE   a_2     1       a
404
 
drop table t1;
405
 
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
406
 
alter table t1 engine=innodb;
407
 
insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
408
 
select * from t1;
409
 
col1    col2
410
 
1       1
411
 
2       3
412
 
3       4
413
 
4       4
414
 
5       2
415
 
update t1 set col2='7' where col1='4';
416
 
select * from t1;
417
 
col1    col2
418
 
1       1
419
 
2       3
420
 
3       4
421
 
4       7
422
 
5       2
423
 
alter table t1 add co3 int not null;
424
 
select * from t1;
425
 
col1    col2    co3
426
 
1       1       0
427
 
2       3       0
428
 
3       4       0
429
 
4       7       0
430
 
5       2       0
431
 
update t1 set col2='9' where col1='2';
432
 
select * from t1;
433
 
col1    col2    co3
434
 
1       1       0
435
 
2       9       0
436
 
3       4       0
437
 
4       7       0
438
 
5       2       0
439
 
drop table t1;
440
 
create table t1 (a int not null , b int, primary key (a)) engine = innodb;
441
 
create TEMPORARY table t2 (a int not null , b int, primary key (a)) engine = myisam;
442
 
insert into t1 VALUES (1,3) , (2,3), (3,3);
443
 
select * from t1;
444
 
a       b
445
 
1       3
446
 
2       3
447
 
3       3
448
 
insert into t2 select * from t1;
449
 
select * from t2;
450
 
a       b
451
 
1       3
452
 
2       3
453
 
3       3
454
 
delete from t1 where b = 3;
455
 
select * from t1;
456
 
a       b
457
 
insert into t1 select * from t2;
458
 
select * from t1;
459
 
a       b
460
 
1       3
461
 
2       3
462
 
3       3
463
 
select * from t2;
464
 
a       b
465
 
1       3
466
 
2       3
467
 
3       3
468
 
drop table t1,t2;
469
 
CREATE TABLE t1 (
470
 
user_name varchar(12),
471
 
password text,
472
 
subscribed char(1),
473
 
user_id int DEFAULT '0' NOT NULL,
474
 
quota bigint,
475
 
weight double,
476
 
access_date date,
477
 
approved datetime,
478
 
dummy_primary_key int NOT NULL auto_increment,
479
 
PRIMARY KEY (dummy_primary_key)
480
 
) ENGINE=innodb;
481
 
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','2000-09-07 23:06:59',1);
482
 
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','2000-09-07 23:06:59',2);
483
 
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','2000-09-07 23:06:59',3);
484
 
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','2000-09-07 23:06:59',4);
485
 
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','2000-09-07 23:06:59',5);
486
 
select  user_name, password , subscribed, user_id, quota, weight, access_date, approved, dummy_primary_key from t1 order by user_name;
487
 
user_name       password        subscribed      user_id quota   weight  access_date     approved        dummy_primary_key
488
 
user_0  somepassword    N       0       0       0       2000-09-07      2000-09-07 23:06:59     1
489
 
user_1  somepassword    Y       1       1       1       2000-09-07      2000-09-07 23:06:59     2
490
 
user_2  somepassword    N       2       2       1.4142135623731 2000-09-07      2000-09-07 23:06:59     3
491
 
user_3  somepassword    Y       3       3       1.7320508075689 2000-09-07      2000-09-07 23:06:59     4
492
 
user_4  somepassword    N       4       4       2       2000-09-07      2000-09-07 23:06:59     5
493
 
drop table t1;
494
 
CREATE TABLE t1 (
495
 
id int NOT NULL auto_increment,
496
 
parent_id int DEFAULT '0' NOT NULL,
497
 
level int DEFAULT '0' NOT NULL,
498
 
KEY (id),
499
 
KEY parent_id (parent_id),
500
 
KEY level (level)
501
 
) engine=innodb;
502
 
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);
503
 
INSERT INTO t1 values (179,5,2);
504
 
update t1 set parent_id=parent_id+100;
505
 
select * from t1 where parent_id=102;
506
 
id      parent_id       level
507
 
8       102     2
508
 
9       102     2
509
 
15      102     2
510
 
update t1 set id=id+1000;
511
 
update t1 set id=1024 where id=1009;
512
 
select * from t1;
513
 
id      parent_id       level
514
 
1001    100     0
515
 
1003    101     1
516
 
1004    101     1
517
 
1008    102     2
518
 
1024    102     2
519
 
1017    103     2
520
 
1022    104     2
521
 
1024    104     2
522
 
1028    105     2
523
 
1029    105     2
524
 
1030    105     2
525
 
1031    106     2
526
 
1032    106     2
527
 
1033    106     2
528
 
1203    107     2
529
 
1202    107     2
530
 
1020    103     2
531
 
1157    100     0
532
 
1193    105     2
533
 
1040    107     2
534
 
1002    101     1
535
 
1015    102     2
536
 
1006    101     1
537
 
1034    106     2
538
 
1035    106     2
539
 
1016    103     2
540
 
1007    101     1
541
 
1036    107     2
542
 
1018    103     2
543
 
1026    105     2
544
 
1027    105     2
545
 
1183    104     2
546
 
1038    107     2
547
 
1025    105     2
548
 
1037    107     2
549
 
1021    104     2
550
 
1019    103     2
551
 
1005    101     1
552
 
1179    105     2
553
 
update ignore t1 set id=id+1;
554
 
select * from t1;
555
 
id      parent_id       level
556
 
1002    100     0
557
 
1004    101     1
558
 
1005    101     1
559
 
1009    102     2
560
 
1025    102     2
561
 
1018    103     2
562
 
1023    104     2
563
 
1025    104     2
564
 
1029    105     2
565
 
1030    105     2
566
 
1031    105     2
567
 
1032    106     2
568
 
1033    106     2
569
 
1034    106     2
570
 
1204    107     2
571
 
1203    107     2
572
 
1021    103     2
573
 
1158    100     0
574
 
1194    105     2
575
 
1041    107     2
576
 
1003    101     1
577
 
1016    102     2
578
 
1007    101     1
579
 
1035    106     2
580
 
1036    106     2
581
 
1017    103     2
582
 
1008    101     1
583
 
1037    107     2
584
 
1019    103     2
585
 
1027    105     2
586
 
1028    105     2
587
 
1184    104     2
588
 
1039    107     2
589
 
1026    105     2
590
 
1038    107     2
591
 
1022    104     2
592
 
1020    103     2
593
 
1006    101     1
594
 
1180    105     2
595
 
update ignore t1 set id=1023 where id=1010;
596
 
select * from t1 where parent_id=102;
597
 
id      parent_id       level
598
 
1009    102     2
599
 
1025    102     2
600
 
1016    102     2
601
 
explain select level from t1 where level=1;
602
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
603
 
1       SIMPLE  t1      ref     level   level   4       const   #       Using index
604
 
select level,id from t1 where level=1;
605
 
level   id
606
 
1       1004
607
 
1       1005
608
 
1       1003
609
 
1       1007
610
 
1       1008
611
 
1       1006
612
 
select level,id,parent_id from t1 where level=1;
613
 
level   id      parent_id
614
 
1       1004    101
615
 
1       1005    101
616
 
1       1003    101
617
 
1       1007    101
618
 
1       1008    101
619
 
1       1006    101
620
 
select level,id from t1 where level=1 order by id;
621
 
level   id
622
 
1       1003
623
 
1       1004
624
 
1       1005
625
 
1       1006
626
 
1       1007
627
 
1       1008
628
 
delete from t1 where level=1;
629
 
select * from t1;
630
 
id      parent_id       level
631
 
1002    100     0
632
 
1009    102     2
633
 
1025    102     2
634
 
1018    103     2
635
 
1023    104     2
636
 
1025    104     2
637
 
1029    105     2
638
 
1030    105     2
639
 
1031    105     2
640
 
1032    106     2
641
 
1033    106     2
642
 
1034    106     2
643
 
1204    107     2
644
 
1203    107     2
645
 
1021    103     2
646
 
1158    100     0
647
 
1194    105     2
648
 
1041    107     2
649
 
1016    102     2
650
 
1035    106     2
651
 
1036    106     2
652
 
1017    103     2
653
 
1037    107     2
654
 
1019    103     2
655
 
1027    105     2
656
 
1028    105     2
657
 
1184    104     2
658
 
1039    107     2
659
 
1026    105     2
660
 
1038    107     2
661
 
1022    104     2
662
 
1020    103     2
663
 
1180    105     2
664
 
drop table t1;
665
 
CREATE TABLE t1 (
666
 
sca_code char(6) NOT NULL,
667
 
cat_code char(6) NOT NULL,
668
 
sca_desc varchar(50),
669
 
lan_code char(2) NOT NULL,
670
 
sca_pic varchar(100),
671
 
sca_sdesc varchar(50),
672
 
sca_sch_desc varchar(16),
673
 
PRIMARY KEY (sca_code, cat_code, lan_code),
674
 
INDEX sca_pic (sca_pic)
675
 
) engine = innodb ;
676
 
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');
677
 
select count(*) from t1 where sca_code = 'PD';
678
 
count(*)
679
 
1
680
 
select count(*) from t1 where sca_code <= 'PD';
681
 
count(*)
682
 
1
683
 
select count(*) from t1 where sca_pic is null;
684
 
count(*)
685
 
2
686
 
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
687
 
select count(*) from t1 where sca_code='PD' and sca_pic is null;
688
 
count(*)
689
 
1
690
 
select count(*) from t1 where cat_code='E';
691
 
count(*)
692
 
0
693
 
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
694
 
select count(*) from t1 where sca_code='PD' and sca_pic is null;
695
 
count(*)
696
 
1
697
 
select count(*) from t1 where sca_pic >= 'n';
698
 
count(*)
699
 
1
700
 
select sca_pic from t1 where sca_pic is null;
701
 
sca_pic
702
 
NULL
703
 
NULL
704
 
update t1 set sca_pic="test" where sca_pic is null;
705
 
delete from t1 where sca_code='pd';
706
 
drop table t1;
707
 
set @a:=now();
708
 
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
709
 
insert into t1 (a) values(1),(2),(3);
710
 
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
711
 
a
712
 
1
713
 
2
714
 
3
715
 
select a from t1 natural join t1 as t2 where b >= @a order by a;
716
 
a
717
 
1
718
 
2
719
 
3
720
 
update t1 set a=5 where a=1;
721
 
select a from t1;
722
 
a
723
 
2
724
 
3
725
 
5
726
 
drop table t1;
727
 
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
728
 
insert into t1 values("hello",1),("world",2);
729
 
select * from t1 order by b desc;
730
 
a       b
731
 
world   2
732
 
hello   1
733
 
alter table t1 engine=innodb;
734
 
show keys from t1;
735
 
Table   Unique  Key_name        Seq_in_index    Column_name
736
 
t1      TRUE    PRIMARY 1       a
737
 
drop table t1;
738
 
create table t1 (i int, j int ) ENGINE=innodb;
739
 
insert into t1 values (1,2);
740
 
select * from t1 where i=1 and j=2;
741
 
i       j
742
 
1       2
743
 
create index ax1 on t1 (i,j);
744
 
select * from t1 where i=1 and j=2;
745
 
i       j
746
 
1       2
747
 
drop table t1;
748
 
CREATE TABLE t1 (
749
 
a int NOT NULL,
750
 
b int NOT NULL,
751
 
UNIQUE (a, b)
752
 
) ENGINE = innodb;
753
 
INSERT INTO t1 VALUES (1, 1);
754
 
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
755
 
MIN(B)  MAX(b)
756
 
1       1
757
 
drop table t1;
758
 
CREATE TABLE t1 (a int NOT NULL) engine=innodb;
759
 
INSERT INTO t1 VALUES (1);
760
 
SELECT * FROM t1;
761
 
a
762
 
1
763
 
DROP TABLE t1;
764
 
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;
765
 
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);
766
 
explain select * from t1 where a > 0 and a < 50;
767
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
768
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 4       NULL    #       Using where
769
 
drop table t1;
770
 
create table t1 (a char(20), unique (a(5))) engine=innodb;
771
 
drop table t1;
772
 
create table t1 (a char(20), index (a(5))) engine=innodb;
773
 
show create table t1;
774
 
Table   Create Table
775
 
t1      CREATE TABLE `t1` (
776
 
  `a` varchar(20) DEFAULT NULL,
777
 
  KEY `a` (`a`(5))
778
 
) ENGINE=InnoDB
779
 
drop table t1;
780
 
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
781
 
insert into t1 values (NULL),(NULL),(NULL);
782
 
delete from t1 where a=3;
783
 
insert into t1 values (NULL);
784
 
select * from t1;
785
 
a
786
 
1
787
 
2
788
 
4
789
 
alter table t1 add b int;
790
 
select * from t1;
791
 
a       b
792
 
1       NULL
793
 
2       NULL
794
 
4       NULL
795
 
drop table t1;
796
 
create table t1
797
 
(
798
 
id int auto_increment primary key,
799
 
name varchar(32) not null,
800
 
value text not null,
801
 
uid int not null,
802
 
unique key(name,uid)
803
 
) engine=innodb;
804
 
insert into t1 values (1,'one','one value',101),
805
 
(2,'two','two value',102),(3,'three','three value',103);
806
 
replace into t1 (value,name,uid) values ('other value','two',102);
807
 
delete from t1 where uid=102;
808
 
replace into t1 (value,name,uid) values ('other value','two',102);
809
 
replace into t1 (value,name,uid) values ('other value','two',102);
810
 
select * from t1;
811
 
id      name    value   uid
812
 
1       one     one value       101
813
 
3       three   three value     103
814
 
6       two     other value     102
815
 
drop table t1;
816
 
create database mysqltest;
817
 
create table mysqltest.t1 (a int not null) engine= innodb;
818
 
insert into mysqltest.t1 values(1);
819
 
create TEMPORARY table mysqltest.t2 (a int not null) engine= myisam;
820
 
insert into mysqltest.t2 values(1);
821
 
create temporary table mysqltest.t3 (a int not null) engine= MEMORY;
822
 
insert into mysqltest.t3 values(1);
823
 
commit;
824
 
drop database mysqltest;
825
 
show tables from mysqltest;
826
 
ERROR 42000: Unknown database 'mysqltest'
827
 
set autocommit=0;
828
 
create table t1 (a int not null) engine= innodb;
829
 
insert into t1 values(1),(2);
830
 
truncate table t1;
831
 
commit;
832
 
truncate table t1;
833
 
truncate table t1;
834
 
select * from t1;
835
 
a
836
 
insert into t1 values(1),(2);
837
 
delete from t1;
838
 
select * from t1;
839
 
a
840
 
commit;
841
 
drop table t1;
842
 
set autocommit=1;
843
 
create table t1 (a int not null) engine= innodb;
844
 
insert into t1 values(1),(2);
845
 
truncate table t1;
846
 
insert into t1 values(1),(2);
847
 
select * from t1;
848
 
a
849
 
1
850
 
2
851
 
truncate table t1;
852
 
insert into t1 values(1),(2);
853
 
delete from t1;
854
 
select * from t1;
855
 
a
856
 
drop table t1;
857
 
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
858
 
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
859
 
explain select * from t1 order by a;
860
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
861
 
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    #       
862
 
explain select * from t1 order by b;
863
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
864
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    #       Using filesort
865
 
explain select * from t1 order by c;
866
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
867
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    #       Using filesort
868
 
explain select a from t1 order by a;
869
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
870
 
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    #       Using index
871
 
explain select b from t1 order by b;
872
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
873
 
1       SIMPLE  t1      index   NULL    b       4       NULL    #       Using index
874
 
explain select a,b from t1 order by b;
875
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
876
 
1       SIMPLE  t1      index   NULL    b       4       NULL    #       Using index
877
 
explain select a,b from t1;
878
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
879
 
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    #       
880
 
explain select a,b,c from t1;
881
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
882
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    #       
883
 
drop table t1;
884
 
create table t1 (t int not null default 1, key (t)) engine=innodb;
885
 
desc t1;
886
 
Field   Type    Null    Default Default_is_NULL On_Update
887
 
t       INTEGER FALSE   1       FALSE   
888
 
drop table t1;
889
 
create table t1 (id int not null auto_increment, code int not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
890
 
BEGIN;
891
 
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
892
 
SELECT @@tx_isolation,@@global.tx_isolation;
893
 
@@tx_isolation  @@global.tx_isolation
894
 
SERIALIZABLE    REPEATABLE-READ
895
 
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
896
 
select id, code, name from t1 order by id;
897
 
id      code    name
898
 
1       1       Tim
899
 
2       1       Monty
900
 
3       2       David
901
 
COMMIT;
902
 
BEGIN;
903
 
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
904
 
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
905
 
select id, code, name from t1 order by id;
906
 
id      code    name
907
 
1       1       Tim
908
 
2       1       Monty
909
 
3       2       David
910
 
4       2       Erik
911
 
5       3       Sasha
912
 
COMMIT;
913
 
BEGIN;
914
 
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
915
 
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
916
 
select id, code, name from t1 order by id;
917
 
id      code    name
918
 
1       1       Tim
919
 
2       1       Monty
920
 
3       2       David
921
 
4       2       Erik
922
 
5       3       Sasha
923
 
6       3       Jeremy
924
 
7       4       Matt
925
 
COMMIT;
926
 
DROP TABLE t1;
927
 
create table t1 (a int, b int) engine=innodb;
928
 
insert into t1 values(20,null);
929
 
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
930
 
t2.b=t3.a;
931
 
b       ifnull(t2.b,"this is null")
932
 
NULL    this is null
933
 
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
934
 
t2.b=t3.a order by 1;
935
 
b       ifnull(t2.b,"this is null")
936
 
NULL    this is null
937
 
insert into t1 values(10,null);
938
 
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
939
 
t2.b=t3.a order by 1;
940
 
b       ifnull(t2.b,"this is null")
941
 
NULL    this is null
942
 
NULL    this is null
943
 
drop table t1;
944
 
create TEMPORARY table t1 (a varchar(10) not null) engine=myisam;
945
 
create table t2 (b varchar(10) not null unique) engine=innodb;
946
 
select t1.a from t1,t2 where t1.a=t2.b;
947
 
a
948
 
drop table t1,t2;
949
 
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
950
 
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
951
 
insert into t1 values (10, 20);
952
 
insert into t2 values (10, 20);
953
 
drop table t1,t2;
954
 
set autocommit=0;
955
 
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
956
 
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
957
 
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
958
 
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
959
 
COMMIT;
960
 
INSERT INTO t1 VALUES("this-key", "will disappear");
961
 
INSERT INTO t2 VALUES("this-key", "will also disappear");
962
 
DELETE FROM t3 WHERE id1="my-test-1";
963
 
SELECT * FROM t1;
964
 
id      value
965
 
this-key        will disappear
966
 
SELECT * FROM t2;
967
 
id      value
968
 
this-key        will also disappear
969
 
SELECT * FROM t3;
970
 
id1     id2
971
 
ROLLBACK;
972
 
SELECT * FROM t1;
973
 
id      value
974
 
SELECT * FROM t2;
975
 
id      value
976
 
SELECT * FROM t3;
977
 
id1     id2
978
 
my-test-1       my-test-2
979
 
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
980
 
id1     id2
981
 
my-test-1       my-test-2
982
 
COMMIT;
983
 
set autocommit=1;
984
 
DROP TABLE t1,t2,t3;
985
 
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
986
 
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
987
 
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
988
 
SELECT * from t1;
989
 
a       b
990
 
1       1
991
 
4       4
992
 
5       5
993
 
6       6
994
 
7       7
995
 
8       8
996
 
9       9
997
 
102     2
998
 
103     3
999
 
drop table t1;
1000
 
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
1001
 
create table t2 (a int not null auto_increment primary key, b int);
1002
 
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
1003
 
insert into t2 (a) select b from t1;
1004
 
insert into t1 (b) select b from t2;
1005
 
insert into t2 (a) select b from t1;
1006
 
insert into t1 (a) select b from t2;
1007
 
insert into t2 (a) select b from t1;
1008
 
insert into t1 (a) select b from t2;
1009
 
insert into t2 (a) select b from t1;
1010
 
insert into t1 (a) select b from t2;
1011
 
insert into t2 (a) select b from t1;
1012
 
insert into t1 (a) select b from t2;
1013
 
select count(*) from t1;
1014
 
count(*)
1015
 
623
1016
 
explain select * from t1 where c between 1 and 2500;
1017
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1018
 
1       SIMPLE  t1      range   c       c       5       NULL    #       Using where
1019
 
update t1 set c=a;
1020
 
explain select * from t1 where c between 1 and 2500;
1021
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1022
 
1       SIMPLE  t1      ALL     c       NULL    NULL    NULL    #       Using where
1023
 
drop table t1,t2;
1024
 
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
1025
 
insert into t1 (id) values (null),(null),(null),(null),(null);
1026
 
update t1 set fk=69 where fk is null order by id limit 1;
1027
 
SELECT * from t1;
1028
 
id      fk
1029
 
1       69
1030
 
2       NULL
1031
 
3       NULL
1032
 
4       NULL
1033
 
5       NULL
1034
 
drop table t1;
1035
 
create table t1 (a int not null, b int not null, key (a));
1036
 
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);
1037
 
SET @tmp=0;
1038
 
update t1 set b=(@tmp:=@tmp+1) order by a;
1039
 
update t1 set b=99 where a=1 order by b asc limit 1;
1040
 
update t1 set b=100 where a=1 order by b desc limit 2;
1041
 
update t1 set a=a+10+b where a=1 order by b;
1042
 
select * from t1 order by a,b;
1043
 
a       b
1044
 
2       4
1045
 
2       5
1046
 
2       6
1047
 
3       7
1048
 
3       8
1049
 
3       9
1050
 
3       10
1051
 
3       11
1052
 
3       12
1053
 
13      2
1054
 
111     100
1055
 
111     100
1056
 
drop table t1;
1057
 
SET AUTOCOMMIT=1;
1058
 
create table t1 (a integer auto_increment primary key) engine=innodb;
1059
 
insert into t1 (a) values (NULL),(NULL);
1060
 
truncate table t1;
1061
 
insert into t1 (a) values (NULL),(NULL);
1062
 
SELECT * from t1;
1063
 
a
1064
 
1
1065
 
2
1066
 
drop table t1;
1067
 
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
1068
 
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;
1069
 
drop table t2,t1;
1070
 
create table t1(
1071
 
id int primary key,
1072
 
pid int,
1073
 
index(pid),
1074
 
foreign key(pid) references t1(id) on delete cascade) engine=innodb;
1075
 
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
1076
 
(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
1077
 
delete from t1 where id=0;
1078
 
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)
1079
 
delete from t1 where id=15;
1080
 
delete from t1 where id=0;
1081
 
drop table t1;
1082
 
CREATE TABLE t1 (col1 int) ENGINE=InnoDB;
1083
 
CREATE TABLE t2 (col1 int, stamp TIMESTAMP,INDEX stamp_idx (stamp)) ENGINE=InnoDB;
1084
 
insert into t1 values (1),(2),(3);
1085
 
insert into t2 values (1, 20020204110000),(2, 20020204110001),(4,20020204110002 ),(5,20020204110003);
1086
 
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
1087
 
'20020204120000' GROUP BY col1;
1088
 
col1
1089
 
1
1090
 
2
1091
 
3
1092
 
4
1093
 
5
1094
 
drop table t1,t2;
1095
 
CREATE TABLE t1 (
1096
 
`id` int NOT NULL auto_increment,
1097
 
`id_object` int default '0',
1098
 
`id_version` int NOT NULL default '1',
1099
 
`label` varchar(100) NOT NULL default '',
1100
 
`description` text,
1101
 
PRIMARY KEY  (`id`),
1102
 
KEY `id_object` (`id_object`),
1103
 
KEY `id_version` (`id_version`)
1104
 
) ENGINE=InnoDB;
1105
 
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);
1106
 
CREATE TABLE t2 (
1107
 
`id` int NOT NULL auto_increment,
1108
 
`id_version` int NOT NULL default '1',
1109
 
PRIMARY KEY  (`id`),
1110
 
KEY `id_version` (`id_version`)
1111
 
) ENGINE=InnoDB;
1112
 
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
1113
 
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
1114
 
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl 
1115
 
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
1116
 
id      label
1117
 
3382    Test
1118
 
102     Le Pekin (Test)
1119
 
1794    Test de resto
1120
 
1822    Test 3
1121
 
3524    Societe Test
1122
 
3525    Fournisseur Test
1123
 
drop table t1,t2;
1124
 
create TEMPORARY table t1 (a int, b varchar(200), c text not null)  engine=myisam;
1125
 
create table t2 (a int, b varchar(200), c text not null) engine=innodb;
1126
 
create table t3 (a int, b varchar(200), c text not null) engine=innodb;
1127
 
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
1128
 
insert t2 select * from t1;
1129
 
insert t3 select * from t1;
1130
 
checksum table t1, t2, t3, t4;
1131
 
Table   Checksum
1132
 
test.t1 2948697075
1133
 
test.t2 3505595080
1134
 
test.t3 3505595080
1135
 
test.t4 NULL
1136
 
Warnings:
1137
 
Error   1146    Table 'test.t4' doesn't exist
1138
 
checksum table t1, t2, t3, t4;
1139
 
Table   Checksum
1140
 
test.t1 2948697075
1141
 
test.t2 3505595080
1142
 
test.t3 3505595080
1143
 
test.t4 NULL
1144
 
Warnings:
1145
 
Error   1146    Table 'test.t4' doesn't exist
1146
 
checksum table t1, t2, t3, t4;
1147
 
Table   Checksum
1148
 
test.t1 2948697075
1149
 
test.t2 3505595080
1150
 
test.t3 3505595080
1151
 
test.t4 NULL
1152
 
Warnings:
1153
 
Error   1146    Table 'test.t4' doesn't exist
1154
 
drop table t1,t2,t3;
1155
 
create table t1 (id int,  name char(10) not null,  name2 char(10) not null) engine=innodb;
1156
 
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
1157
 
select trim(name2) from t1  union all  select trim(name) from t1 union all select trim(id) from t1;
1158
 
trim(name2)
1159
 
fff
1160
 
sss
1161
 
ttt
1162
 
first
1163
 
second
1164
 
third
1165
 
1
1166
 
2
1167
 
3
1168
 
drop table t1;
1169
 
create table t1 (a int) engine=innodb;
1170
 
create table t2 like t1;
1171
 
drop table t1,t2;
1172
 
create table t1 (id int not null, id2 int not null, unique (id,id2)) engine=innodb;
1173
 
create table t2 (id int not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
1174
 
show create table t1;
1175
 
Table   Create Table
1176
 
t1      CREATE TABLE `t1` (
1177
 
  `id` int NOT NULL,
1178
 
  `id2` int NOT NULL,
1179
 
  UNIQUE KEY `id` (`id`,`id2`)
1180
 
) ENGINE=InnoDB
1181
 
show create table t2;
1182
 
Table   Create Table
1183
 
t2      CREATE TABLE `t2` (
1184
 
  `id` int NOT NULL,
1185
 
  KEY `t1_id_fk` (`id`),
1186
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1187
 
) ENGINE=InnoDB
1188
 
create index id on t2 (id);
1189
 
show create table t2;
1190
 
Table   Create Table
1191
 
t2      CREATE TABLE `t2` (
1192
 
  `id` int NOT NULL,
1193
 
  KEY `id` (`id`),
1194
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1195
 
) ENGINE=InnoDB
1196
 
create index id2 on t2 (id);
1197
 
show create table t2;
1198
 
Table   Create Table
1199
 
t2      CREATE TABLE `t2` (
1200
 
  `id` int NOT NULL,
1201
 
  KEY `id` (`id`),
1202
 
  KEY `id2` (`id`),
1203
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1204
 
) ENGINE=InnoDB
1205
 
drop index id2 on t2;
1206
 
drop index id on t2;
1207
 
Got one of the listed errors
1208
 
show create table t2;
1209
 
Table   Create Table
1210
 
t2      CREATE TABLE `t2` (
1211
 
  `id` int NOT NULL,
1212
 
  KEY `id` (`id`),
1213
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1214
 
) ENGINE=InnoDB
1215
 
drop table t2;
1216
 
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;
1217
 
show create table t2;
1218
 
Table   Create Table
1219
 
t2      CREATE TABLE `t2` (
1220
 
  `id` int NOT NULL,
1221
 
  `id2` int NOT NULL,
1222
 
  KEY `t1_id_fk` (`id`,`id2`),
1223
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1224
 
) ENGINE=InnoDB
1225
 
create unique index id on t2 (id,id2);
1226
 
show create table t2;
1227
 
Table   Create Table
1228
 
t2      CREATE TABLE `t2` (
1229
 
  `id` int NOT NULL,
1230
 
  `id2` int NOT NULL,
1231
 
  UNIQUE KEY `id` (`id`,`id2`),
1232
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1233
 
) ENGINE=InnoDB
1234
 
drop table t2;
1235
 
create table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
1236
 
show create table t2;
1237
 
Table   Create Table
1238
 
t2      CREATE TABLE `t2` (
1239
 
  `id` int NOT NULL,
1240
 
  `id2` int NOT NULL,
1241
 
  UNIQUE KEY `id` (`id`,`id2`),
1242
 
  KEY `t1_id_fk` (`id2`,`id`),
1243
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1244
 
) ENGINE=InnoDB
1245
 
drop table t2;
1246
 
create table t2 (id int not null, id2 int not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;
1247
 
show create table t2;
1248
 
Table   Create Table
1249
 
t2      CREATE TABLE `t2` (
1250
 
  `id` int NOT NULL,
1251
 
  `id2` int NOT NULL,
1252
 
  UNIQUE KEY `id` (`id`,`id2`),
1253
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1254
 
) ENGINE=InnoDB
1255
 
drop table t2;
1256
 
create table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
1257
 
show create table t2;
1258
 
Table   Create Table
1259
 
t2      CREATE TABLE `t2` (
1260
 
  `id` int NOT NULL,
1261
 
  `id2` int NOT NULL,
1262
 
  UNIQUE KEY `id` (`id`,`id2`),
1263
 
  KEY `t1_id_fk` (`id2`,`id`),
1264
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1265
 
) ENGINE=InnoDB
1266
 
drop table t2;
1267
 
create table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
1268
 
show create table t2;
1269
 
Table   Create Table
1270
 
t2      CREATE TABLE `t2` (
1271
 
  `id` int NOT NULL AUTO_INCREMENT,
1272
 
  `id2` int NOT NULL,
1273
 
  PRIMARY KEY (`id`),
1274
 
  KEY `id` (`id`,`id2`),
1275
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1276
 
) ENGINE=InnoDB
1277
 
drop table t2;
1278
 
create table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
1279
 
show create table t2;
1280
 
Table   Create Table
1281
 
t2      CREATE TABLE `t2` (
1282
 
  `id` int NOT NULL AUTO_INCREMENT,
1283
 
  `id2` int NOT NULL,
1284
 
  KEY `t1_id_fk` (`id`),
1285
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1286
 
) ENGINE=InnoDB
1287
 
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1288
 
show create table t2;
1289
 
Table   Create Table
1290
 
t2      CREATE TABLE `t2` (
1291
 
  `id` int NOT NULL AUTO_INCREMENT,
1292
 
  `id2` int NOT NULL,
1293
 
  KEY `id_test` (`id`),
1294
 
  KEY `id_test2` (`id`,`id2`),
1295
 
  CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1296
 
) ENGINE=InnoDB
1297
 
drop table t2;
1298
 
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
1299
 
ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match
1300
 
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
1301
 
show create table t2;
1302
 
Table   Create Table
1303
 
t2      CREATE TABLE `t2` (
1304
 
  `a` int NOT NULL AUTO_INCREMENT,
1305
 
  `b` int DEFAULT NULL,
1306
 
  PRIMARY KEY (`a`),
1307
 
  UNIQUE KEY `b_2` (`b`),
1308
 
  KEY `b` (`b`),
1309
 
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1310
 
) ENGINE=InnoDB
1311
 
drop table t2;
1312
 
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;
1313
 
show create table t2;
1314
 
Table   Create Table
1315
 
t2      CREATE TABLE `t2` (
1316
 
  `a` int NOT NULL AUTO_INCREMENT,
1317
 
  `b` int DEFAULT NULL,
1318
 
  PRIMARY KEY (`a`),
1319
 
  UNIQUE KEY `b` (`b`),
1320
 
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
1321
 
  CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1322
 
) ENGINE=InnoDB
1323
 
drop table t2, t1;
1324
 
create table t1 (c char(10), index (c,c)) engine=innodb;
1325
 
ERROR 42S21: Duplicate column name 'c'
1326
 
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
1327
 
ERROR 42S21: Duplicate column name 'c1'
1328
 
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
1329
 
ERROR 42S21: Duplicate column name 'c1'
1330
 
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
1331
 
ERROR 42S21: Duplicate column name 'c1'
1332
 
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
1333
 
alter table t1 add key (c1,c1);
1334
 
ERROR 42S21: Duplicate column name 'c1'
1335
 
alter table t1 add key (c2,c1,c1);
1336
 
ERROR 42S21: Duplicate column name 'c1'
1337
 
alter table t1 add key (c1,c2,c1);
1338
 
ERROR 42S21: Duplicate column name 'c1'
1339
 
alter table t1 add key (c1,c1,c2);
1340
 
ERROR 42S21: Duplicate column name 'c1'
1341
 
drop table t1;
1342
 
create table t1(a int, b int) engine=innodb;
1343
 
insert into t1 values ('1111', '3333');
1344
 
select distinct concat(a, b) from t1;
1345
 
concat(a, b)
1346
 
11113333
1347
 
drop table t1;
1348
 
CREATE TABLE t1 (a_id int NOT NULL default '0', PRIMARY KEY  (a_id)) ENGINE=InnoDB;
1349
 
INSERT INTO t1 VALUES (1),(2),(3);
1350
 
CREATE TABLE t2 (b_id int NOT NULL default '0',b_a int NOT NULL default '0', PRIMARY KEY  (b_id), KEY  (b_a), 
1351
 
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB;
1352
 
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
1353
 
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;
1354
 
a_id    b_list
1355
 
1       1,2,3
1356
 
2       4,5
1357
 
3       NULL
1358
 
DROP TABLE t2;
1359
 
DROP TABLE t1;
1360
 
create temporary table t1 (a int) engine=innodb;
1361
 
insert into t1 values (4711);
1362
 
truncate t1;
1363
 
insert into t1 values (42);
1364
 
select * from t1;
1365
 
a
1366
 
42
1367
 
drop table t1;
1368
 
create table t1 (a int) engine=innodb;
1369
 
insert into t1 values (4711);
1370
 
truncate t1;
1371
 
insert into t1 values (42);
1372
 
select * from t1;
1373
 
a
1374
 
42
1375
 
drop table t1;
1376
 
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;
1377
 
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
1378
 
select * from t1 order by a,b,c,d;
1379
 
a       b       c       d       e
1380
 
1       1       a       1       1
1381
 
2       2       b       2       2
1382
 
3       3       ab      3       3
1383
 
explain select * from t1 order by a,b,c,d;
1384
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1385
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using filesort
1386
 
drop table t1;
1387
 
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1388
 
insert into t1 values ('8', '6'), ('4', '7');
1389
 
select min(a) from t1;
1390
 
min(a)
1391
 
4
1392
 
select min(b) from t1 where a='8';
1393
 
min(b)
1394
 
6
1395
 
drop table t1;
1396
 
create table t1 (x bigint not null primary key) engine=innodb;
1397
 
insert into t1(x) values (0x0ffffffffffffff0),(0x0ffffffffffffff1);
1398
 
select * from t1;
1399
 
x
1400
 
1152921504606846960
1401
 
1152921504606846961
1402
 
select count(*) from t1 where x>0;
1403
 
count(*)
1404
 
2
1405
 
select count(*) from t1 where x=0;
1406
 
count(*)
1407
 
0
1408
 
select count(*) from t1 where x<0;
1409
 
count(*)
1410
 
0
1411
 
select count(*) from t1 where x < -16;
1412
 
count(*)
1413
 
0
1414
 
select count(*) from t1 where x = -16;
1415
 
count(*)
1416
 
0
1417
 
explain select count(*) from t1 where x > -16;
1418
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1419
 
1       SIMPLE  t1      range   PRIMARY PRIMARY 8       NULL    1       Using where; Using index
1420
 
select count(*) from t1 where x > -16;
1421
 
count(*)
1422
 
2
1423
 
select * from t1 where x > -16;
1424
 
x
1425
 
1152921504606846960
1426
 
1152921504606846961
1427
 
select count(*) from t1 where x = 1152921504606846961;
1428
 
count(*)
1429
 
1
1430
 
drop table t1;
1431
 
show status like "Innodb_buffer_pool_pages_total";
1432
 
Variable_name   Value
1433
 
show status like "Innodb_page_size";
1434
 
Variable_name   Value
1435
 
show status like "Innodb_rows_deleted";
1436
 
Variable_name   Value
1437
 
show status like "Innodb_rows_inserted";
1438
 
Variable_name   Value
1439
 
show status like "Innodb_rows_updated";
1440
 
Variable_name   Value
1441
 
show status like "Innodb_row_lock_waits";
1442
 
Variable_name   Value
1443
 
show status like "Innodb_row_lock_current_waits";
1444
 
Variable_name   Value
1445
 
show status like "Innodb_row_lock_time";
1446
 
Variable_name   Value
1447
 
show status like "Innodb_row_lock_time_max";
1448
 
Variable_name   Value
1449
 
show status like "Innodb_row_lock_time_avg";
1450
 
Variable_name   Value
1451
 
show variables like "innodb_sync_spin_loops";
1452
 
Variable_name   Value
1453
 
innodb_sync_spin_loops  30
1454
 
set global innodb_sync_spin_loops=1000;
1455
 
show variables like "innodb_sync_spin_loops";
1456
 
Variable_name   Value
1457
 
innodb_sync_spin_loops  1000
1458
 
set global innodb_sync_spin_loops=0;
1459
 
show variables like "innodb_sync_spin_loops";
1460
 
Variable_name   Value
1461
 
innodb_sync_spin_loops  0
1462
 
set global innodb_sync_spin_loops=20;
1463
 
show variables like "innodb_sync_spin_loops";
1464
 
Variable_name   Value
1465
 
innodb_sync_spin_loops  20
1466
 
show variables like "innodb_thread_concurrency";
1467
 
Variable_name   Value
1468
 
innodb_thread_concurrency       0
1469
 
set global innodb_thread_concurrency=1001;
1470
 
Warnings:
1471
 
Error   1292    Truncated incorrect thread_concurrency value: '1001'
1472
 
show variables like "innodb_thread_concurrency";
1473
 
Variable_name   Value
1474
 
innodb_thread_concurrency       1000
1475
 
set global innodb_thread_concurrency=0;
1476
 
show variables like "innodb_thread_concurrency";
1477
 
Variable_name   Value
1478
 
innodb_thread_concurrency       0
1479
 
set global innodb_thread_concurrency=16;
1480
 
show variables like "innodb_thread_concurrency";
1481
 
Variable_name   Value
1482
 
innodb_thread_concurrency       16
1483
 
show variables like "innodb_concurrency_tickets";
1484
 
Variable_name   Value
1485
 
innodb_concurrency_tickets      500
1486
 
set global innodb_concurrency_tickets=1000;
1487
 
show variables like "innodb_concurrency_tickets";
1488
 
Variable_name   Value
1489
 
innodb_concurrency_tickets      1000
1490
 
set global innodb_concurrency_tickets=0;
1491
 
Warnings:
1492
 
Error   1292    Truncated incorrect concurrency_tickets value: '0'
1493
 
show variables like "innodb_concurrency_tickets";
1494
 
Variable_name   Value
1495
 
innodb_concurrency_tickets      1
1496
 
set global innodb_concurrency_tickets=500;
1497
 
show variables like "innodb_concurrency_tickets";
1498
 
Variable_name   Value
1499
 
innodb_concurrency_tickets      500
1500
 
show variables like "innodb_thread_sleep_delay";
1501
 
Variable_name   Value
1502
 
innodb_thread_sleep_delay       10000
1503
 
set global innodb_thread_sleep_delay=100000;
1504
 
show variables like "innodb_thread_sleep_delay";
1505
 
Variable_name   Value
1506
 
innodb_thread_sleep_delay       100000
1507
 
set global innodb_thread_sleep_delay=0;
1508
 
show variables like "innodb_thread_sleep_delay";
1509
 
Variable_name   Value
1510
 
innodb_thread_sleep_delay       0
1511
 
set global innodb_thread_sleep_delay=10000;
1512
 
show variables like "innodb_thread_sleep_delay";
1513
 
Variable_name   Value
1514
 
innodb_thread_sleep_delay       10000
1515
 
set storage_engine=INNODB;
1516
 
drop table if exists t1,t2,t3;
1517
 
--- Testing varchar ---
1518
 
--- Testing varchar ---
1519
 
create  table t1 (v varchar(10), c char(10), t text);
1520
 
insert into t1 values('+ ', '+ ', '+ ');
1521
 
set @a=repeat(' ',20);
1522
 
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1523
 
Warnings:
1524
 
Note    1265    Data truncated for column 'v' at row 1
1525
 
Note    1265    Data truncated for column 'c' at row 1
1526
 
select concat('*',v,'*',c,'*',t,'*') from t1;
1527
 
concat('*',v,'*',c,'*',t,'*')
1528
 
*+ *+ *+ *
1529
 
*+         *+         *+                    *
1530
 
show create table t1;
1531
 
Table   Create Table
1532
 
t1      CREATE TABLE `t1` (
1533
 
  `v` varchar(10) DEFAULT NULL,
1534
 
  `c` varchar(10) DEFAULT NULL,
1535
 
  `t` text
1536
 
) ENGINE=InnoDB
1537
 
create  table t2 like t1;
1538
 
show create table t2;
1539
 
Table   Create Table
1540
 
t2      CREATE TABLE `t2` (
1541
 
  `v` varchar(10) DEFAULT NULL,
1542
 
  `c` varchar(10) DEFAULT NULL,
1543
 
  `t` text
1544
 
) ENGINE=InnoDB
1545
 
create  table t3 select * from t1;
1546
 
show create table t3;
1547
 
Table   Create Table
1548
 
t3      CREATE TABLE `t3` (
1549
 
  `v` varchar(10) DEFAULT NULL,
1550
 
  `c` varchar(10) DEFAULT NULL,
1551
 
  `t` text
1552
 
) ENGINE=InnoDB
1553
 
alter table t1 modify c varchar(10);
1554
 
show create table t1;
1555
 
Table   Create Table
1556
 
t1      CREATE TABLE `t1` (
1557
 
  `v` varchar(10) DEFAULT NULL,
1558
 
  `c` varchar(10) DEFAULT NULL,
1559
 
  `t` text
1560
 
) ENGINE=InnoDB
1561
 
alter table t1 modify v char(10);
1562
 
show create table t1;
1563
 
Table   Create Table
1564
 
t1      CREATE TABLE `t1` (
1565
 
  `v` varchar(10) DEFAULT NULL,
1566
 
  `c` varchar(10) DEFAULT NULL,
1567
 
  `t` text
1568
 
) ENGINE=InnoDB
1569
 
alter table t1 modify t varchar(10);
1570
 
Warnings:
1571
 
Note    1265    Data truncated for column 't' at row 2
1572
 
show create table t1;
1573
 
Table   Create Table
1574
 
t1      CREATE TABLE `t1` (
1575
 
  `v` varchar(10) DEFAULT NULL,
1576
 
  `c` varchar(10) DEFAULT NULL,
1577
 
  `t` varchar(10) DEFAULT NULL
1578
 
) ENGINE=InnoDB
1579
 
select concat('*',v,'*',c,'*',t,'*') from t1;
1580
 
concat('*',v,'*',c,'*',t,'*')
1581
 
*+ *+ *+ *
1582
 
*+         *+         *+         *
1583
 
drop table t1,t2,t3;
1584
 
create  table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
1585
 
show create table t1;
1586
 
Table   Create Table
1587
 
t1      CREATE TABLE `t1` (
1588
 
  `v` varchar(10) DEFAULT NULL,
1589
 
  `c` varchar(10) DEFAULT NULL,
1590
 
  `t` text,
1591
 
  KEY `v` (`v`),
1592
 
  KEY `c` (`c`),
1593
 
  KEY `t` (`t`(10))
1594
 
) ENGINE=InnoDB
1595
 
select count(*) from t1;
1596
 
count(*)
1597
 
270
1598
 
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
1599
 
select count(*) from t1 where v='a';
1600
 
count(*)
1601
 
10
1602
 
select count(*) from t1 where c='a';
1603
 
count(*)
1604
 
10
1605
 
select count(*) from t1 where t='a';
1606
 
count(*)
1607
 
10
1608
 
select count(*) from t1 where v='a  ';
1609
 
count(*)
1610
 
10
1611
 
select count(*) from t1 where c='a  ';
1612
 
count(*)
1613
 
10
1614
 
select count(*) from t1 where t='a  ';
1615
 
count(*)
1616
 
10
1617
 
select count(*) from t1 where v between 'a' and 'a ';
1618
 
count(*)
1619
 
10
1620
 
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
1621
 
count(*)
1622
 
10
1623
 
select count(*) from t1 where v like 'a%';
1624
 
count(*)
1625
 
11
1626
 
select count(*) from t1 where c like 'a%';
1627
 
count(*)
1628
 
11
1629
 
select count(*) from t1 where t like 'a%';
1630
 
count(*)
1631
 
11
1632
 
select count(*) from t1 where v like 'a %';
1633
 
count(*)
1634
 
9
1635
 
explain select count(*) from t1 where v='a  ';
1636
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1637
 
1       SIMPLE  t1      ref     v       v       43      const   #       Using where; Using index
1638
 
explain select count(*) from t1 where c='a  ';
1639
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1640
 
1       SIMPLE  t1      ref     c       c       43      const   #       Using where; Using index
1641
 
explain select count(*) from t1 where t='a  ';
1642
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1643
 
1       SIMPLE  t1      ref     t       t       43      const   #       Using where
1644
 
explain select count(*) from t1 where v like 'a%';
1645
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1646
 
1       SIMPLE  t1      range   v       v       43      NULL    #       Using where; Using index
1647
 
explain select count(*) from t1 where v between 'a' and 'a ';
1648
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1649
 
1       SIMPLE  t1      ref     v       v       43      const   #       Using where; Using index
1650
 
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
1651
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1652
 
1       SIMPLE  t1      ref     v       v       43      const   #       Using where; Using index
1653
 
alter table t1 add unique(v);
1654
 
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
1655
 
alter table t1 add key(v);
1656
 
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
1657
 
qq
1658
 
*a*a*a*
1659
 
*a *a *a *
1660
 
*a  *a  *a  *
1661
 
*a   *a   *a   *
1662
 
*a    *a    *a    *
1663
 
*a     *a     *a     *
1664
 
*a      *a      *a      *
1665
 
*a       *a       *a       *
1666
 
*a        *a        *a        *
1667
 
*a         *a         *a         *
1668
 
explain select * from t1 where v='a';
1669
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1670
 
1       SIMPLE  t1      ref     v,v_2   #       43      const   #       Using where
1671
 
select v,count(*) from t1 group by v limit 10;
1672
 
v       count(*)
1673
 
a      1
1674
 
a       10
1675
 
b       10
1676
 
c       10
1677
 
d       10
1678
 
e       10
1679
 
f       10
1680
 
g       10
1681
 
h       10
1682
 
i       10
1683
 
select v,count(t) from t1 group by v limit 10;
1684
 
v       count(t)
1685
 
a      1
1686
 
a       10
1687
 
b       10
1688
 
c       10
1689
 
d       10
1690
 
e       10
1691
 
f       10
1692
 
g       10
1693
 
h       10
1694
 
i       10
1695
 
select v,count(c) from t1 group by v limit 10;
1696
 
v       count(c)
1697
 
a      1
1698
 
a       10
1699
 
b       10
1700
 
c       10
1701
 
d       10
1702
 
e       10
1703
 
f       10
1704
 
g       10
1705
 
h       10
1706
 
i       10
1707
 
select sql_big_result v,count(t) from t1 group by v limit 10;
1708
 
v       count(t)
1709
 
a      1
1710
 
a       10
1711
 
b       10
1712
 
c       10
1713
 
d       10
1714
 
e       10
1715
 
f       10
1716
 
g       10
1717
 
h       10
1718
 
i       10
1719
 
select sql_big_result v,count(c) from t1 group by v limit 10;
1720
 
v       count(c)
1721
 
a      1
1722
 
a       10
1723
 
b       10
1724
 
c       10
1725
 
d       10
1726
 
e       10
1727
 
f       10
1728
 
g       10
1729
 
h       10
1730
 
i       10
1731
 
select c,count(*) from t1 group by c limit 10;
1732
 
c       count(*)
1733
 
a      1
1734
 
a       10
1735
 
b       10
1736
 
c       10
1737
 
d       10
1738
 
e       10
1739
 
f       10
1740
 
g       10
1741
 
h       10
1742
 
i       10
1743
 
select c,count(t) from t1 group by c limit 10;
1744
 
c       count(t)
1745
 
a      1
1746
 
a       10
1747
 
b       10
1748
 
c       10
1749
 
d       10
1750
 
e       10
1751
 
f       10
1752
 
g       10
1753
 
h       10
1754
 
i       10
1755
 
select sql_big_result c,count(t) from t1 group by c limit 10;
1756
 
c       count(t)
1757
 
a      1
1758
 
a       10
1759
 
b       10
1760
 
c       10
1761
 
d       10
1762
 
e       10
1763
 
f       10
1764
 
g       10
1765
 
h       10
1766
 
i       10
1767
 
select t,count(*) from t1 group by t limit 10;
1768
 
t       count(*)
1769
 
a      1
1770
 
a       10
1771
 
b       10
1772
 
c       10
1773
 
d       10
1774
 
e       10
1775
 
f       10
1776
 
g       10
1777
 
h       10
1778
 
i       10
1779
 
select t,count(t) from t1 group by t limit 10;
1780
 
t       count(t)
1781
 
a      1
1782
 
a       10
1783
 
b       10
1784
 
c       10
1785
 
d       10
1786
 
e       10
1787
 
f       10
1788
 
g       10
1789
 
h       10
1790
 
i       10
1791
 
select sql_big_result t,count(t) from t1 group by t limit 10;
1792
 
t       count(t)
1793
 
a      1
1794
 
a       10
1795
 
b       10
1796
 
c       10
1797
 
d       10
1798
 
e       10
1799
 
f       10
1800
 
g       10
1801
 
h       10
1802
 
i       10
1803
 
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
1804
 
Warnings:
1805
 
Warning 1071    Specified key was too long; max key length is 767 bytes
1806
 
show create table t1;
1807
 
Table   Create Table
1808
 
t1      CREATE TABLE `t1` (
1809
 
  `v` varchar(300) DEFAULT NULL,
1810
 
  `c` varchar(10) DEFAULT NULL,
1811
 
  `t` text,
1812
 
  KEY `c` (`c`),
1813
 
  KEY `t` (`t`(10)),
1814
 
  KEY `v` (`v`(191))
1815
 
) ENGINE=InnoDB
1816
 
select count(*) from t1 where v='a';
1817
 
count(*)
1818
 
10
1819
 
select count(*) from t1 where v='a  ';
1820
 
count(*)
1821
 
10
1822
 
select count(*) from t1 where v between 'a' and 'a ';
1823
 
count(*)
1824
 
10
1825
 
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
1826
 
count(*)
1827
 
10
1828
 
select count(*) from t1 where v like 'a%';
1829
 
count(*)
1830
 
11
1831
 
select count(*) from t1 where v like 'a %';
1832
 
count(*)
1833
 
9
1834
 
explain select count(*) from t1 where v='a  ';
1835
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1836
 
1       SIMPLE  t1      ref     v       v       767     const   #       Using where
1837
 
explain select count(*) from t1 where v like 'a%';
1838
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1839
 
1       SIMPLE  t1      range   v       v       767     NULL    #       Using where
1840
 
explain select count(*) from t1 where v between 'a' and 'a ';
1841
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1842
 
1       SIMPLE  t1      ref     v       v       767     const   #       Using where
1843
 
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
1844
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1845
 
1       SIMPLE  t1      ref     v       v       767     const   #       Using where
1846
 
explain select * from t1 where v='a';
1847
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1848
 
1       SIMPLE  t1      ref     v       v       767     const   #       Using where
1849
 
select v,count(*) from t1 group by v limit 10;
1850
 
v       count(*)
1851
 
a      1
1852
 
a       10
1853
 
b       10
1854
 
c       10
1855
 
d       10
1856
 
e       10
1857
 
f       10
1858
 
g       10
1859
 
h       10
1860
 
i       10
1861
 
select v,count(t) from t1 group by v limit 10;
1862
 
v       count(t)
1863
 
a      1
1864
 
a       10
1865
 
b       10
1866
 
c       10
1867
 
d       10
1868
 
e       10
1869
 
f       10
1870
 
g       10
1871
 
h       10
1872
 
i       10
1873
 
select sql_big_result v,count(t) from t1 group by v limit 10;
1874
 
v       count(t)
1875
 
a      1
1876
 
a       10
1877
 
b       10
1878
 
c       10
1879
 
d       10
1880
 
e       10
1881
 
f       10
1882
 
g       10
1883
 
h       10
1884
 
i       10
1885
 
alter table t1 drop key v, add key v (v(30));
1886
 
show create table t1;
1887
 
Table   Create Table
1888
 
t1      CREATE TABLE `t1` (
1889
 
  `v` varchar(300) DEFAULT NULL,
1890
 
  `c` varchar(10) DEFAULT NULL,
1891
 
  `t` text,
1892
 
  KEY `c` (`c`),
1893
 
  KEY `t` (`t`(10)),
1894
 
  KEY `v` (`v`(30))
1895
 
) ENGINE=InnoDB
1896
 
select count(*) from t1 where v='a';
1897
 
count(*)
1898
 
10
1899
 
select count(*) from t1 where v='a  ';
1900
 
count(*)
1901
 
10
1902
 
select count(*) from t1 where v between 'a' and 'a ';
1903
 
count(*)
1904
 
10
1905
 
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
1906
 
count(*)
1907
 
10
1908
 
select count(*) from t1 where v like 'a%';
1909
 
count(*)
1910
 
11
1911
 
select count(*) from t1 where v like 'a %';
1912
 
count(*)
1913
 
9
1914
 
explain select count(*) from t1 where v='a  ';
1915
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1916
 
1       SIMPLE  t1      ref     v       v       123     const   #       Using where
1917
 
explain select count(*) from t1 where v like 'a%';
1918
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1919
 
1       SIMPLE  t1      range   v       v       123     NULL    #       Using where
1920
 
explain select count(*) from t1 where v between 'a' and 'a ';
1921
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1922
 
1       SIMPLE  t1      ref     v       v       123     const   #       Using where
1923
 
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
1924
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1925
 
1       SIMPLE  t1      ref     v       v       123     const   #       Using where
1926
 
explain select * from t1 where v='a';
1927
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1928
 
1       SIMPLE  t1      ref     v       v       123     const   #       Using where
1929
 
select v,count(*) from t1 group by v limit 10;
1930
 
v       count(*)
1931
 
a      1
1932
 
a       10
1933
 
b       10
1934
 
c       10
1935
 
d       10
1936
 
e       10
1937
 
f       10
1938
 
g       10
1939
 
h       10
1940
 
i       10
1941
 
select v,count(t) from t1 group by v limit 10;
1942
 
v       count(t)
1943
 
a      1
1944
 
a       10
1945
 
b       10
1946
 
c       10
1947
 
d       10
1948
 
e       10
1949
 
f       10
1950
 
g       10
1951
 
h       10
1952
 
i       10
1953
 
select sql_big_result v,count(t) from t1 group by v limit 10;
1954
 
v       count(t)
1955
 
a      1
1956
 
a       10
1957
 
b       10
1958
 
c       10
1959
 
d       10
1960
 
e       10
1961
 
f       10
1962
 
g       10
1963
 
h       10
1964
 
i       10
1965
 
alter table t1 modify v varchar(600), drop key v, add key v (v);
1966
 
Warnings:
1967
 
Warning 1071    Specified key was too long; max key length is 767 bytes
1968
 
show create table t1;
1969
 
Table   Create Table
1970
 
t1      CREATE TABLE `t1` (
1971
 
  `v` varchar(600) DEFAULT NULL,
1972
 
  `c` varchar(10) DEFAULT NULL,
1973
 
  `t` text,
1974
 
  KEY `c` (`c`),
1975
 
  KEY `t` (`t`(10)),
1976
 
  KEY `v` (`v`(191))
1977
 
) ENGINE=InnoDB
1978
 
select v,count(*) from t1 group by v limit 10;
1979
 
v       count(*)
1980
 
a      1
1981
 
a       10
1982
 
b       10
1983
 
c       10
1984
 
d       10
1985
 
e       10
1986
 
f       10
1987
 
g       10
1988
 
h       10
1989
 
i       10
1990
 
select v,count(t) from t1 group by v limit 10;
1991
 
v       count(t)
1992
 
a      1
1993
 
a       10
1994
 
b       10
1995
 
c       10
1996
 
d       10
1997
 
e       10
1998
 
f       10
1999
 
g       10
2000
 
h       10
2001
 
i       10
2002
 
select sql_big_result v,count(t) from t1 group by v limit 10;
2003
 
v       count(t)
2004
 
a      1
2005
 
a       10
2006
 
b       10
2007
 
c       10
2008
 
d       10
2009
 
e       10
2010
 
f       10
2011
 
g       10
2012
 
h       10
2013
 
i       10
2014
 
drop table t1;
2015
 
create  table t1 (a char(10), unique (a));
2016
 
insert into t1 values ('a   ');
2017
 
insert into t1 values ('a ');
2018
 
ERROR 23000: Duplicate entry 'a ' for key 'a'
2019
 
alter table t1 modify a varchar(10);
2020
 
insert into t1 values ('a '),('a  '),('a   '),('a         ');
2021
 
ERROR 23000: Duplicate entry 'a ' for key 'a'
2022
 
insert into t1 values ('a     ');
2023
 
ERROR 23000: Duplicate entry 'a     ' for key 'a'
2024
 
insert into t1 values ('a          ');
2025
 
ERROR 23000: Duplicate entry 'a         ' for key 'a'
2026
 
insert into t1 values ('a ');
2027
 
ERROR 23000: Duplicate entry 'a ' for key 'a'
2028
 
update t1 set a='a  ' where a like 'a%';
2029
 
select concat(a,'.') from t1;
2030
 
concat(a,'.')
2031
 
a  .
2032
 
update t1 set a='abc    ' where a like 'a ';
2033
 
select concat(a,'.') from t1;
2034
 
concat(a,'.')
2035
 
a  .
2036
 
update t1 set a='a      ' where a like 'a %';
2037
 
select concat(a,'.') from t1;
2038
 
concat(a,'.')
2039
 
a      .
2040
 
update t1 set a='a  ' where a like 'a      ';
2041
 
select concat(a,'.') from t1;
2042
 
concat(a,'.')
2043
 
a  .
2044
 
drop table t1;
2045
 
create  table t1 (v varchar(10), c char(10), t text, key(v(5)), key(c(5)), key(t(5)));
2046
 
show create table t1;
2047
 
Table   Create Table
2048
 
t1      CREATE TABLE `t1` (
2049
 
  `v` varchar(10) DEFAULT NULL,
2050
 
  `c` varchar(10) DEFAULT NULL,
2051
 
  `t` text,
2052
 
  KEY `v` (`v`(5)),
2053
 
  KEY `c` (`c`(5)),
2054
 
  KEY `t` (`t`(5))
2055
 
) ENGINE=InnoDB
2056
 
drop table t1;
2057
 
create  table t1 (v char(10));
2058
 
show create table t1;
2059
 
Table   Create Table
2060
 
t1      CREATE TABLE `t1` (
2061
 
  `v` varchar(10) DEFAULT NULL
2062
 
) ENGINE=InnoDB
2063
 
drop table t1;
2064
 
create  table t1 (v varchar(10), c char(10));
2065
 
show create table t1;
2066
 
Table   Create Table
2067
 
t1      CREATE TABLE `t1` (
2068
 
  `v` varchar(10) DEFAULT NULL,
2069
 
  `c` varchar(10) DEFAULT NULL
2070
 
) ENGINE=InnoDB
2071
 
insert into t1 values('a','a'),('a ','a ');
2072
 
select concat('*',v,'*',c,'*') from t1;
2073
 
concat('*',v,'*',c,'*')
2074
 
*a*a*
2075
 
*a *a *
2076
 
drop table t1;
2077
 
create  table t1(a int, b varchar(12), key ba(b, a));
2078
 
insert into t1 values (1, 'A'), (20, NULL);
2079
 
explain select * from t1 where a=20 and b is null;
2080
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2081
 
1       SIMPLE  t1      ref     ba      ba      56      const,const     1       Using where; Using index
2082
 
select * from t1 where a=20 and b is null;
2083
 
a       b
2084
 
20      NULL
2085
 
drop table t1;
2086
 
create table t1 (v varchar(16383), key(v));
2087
 
Warnings:
2088
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2089
 
drop table t1;
2090
 
create table t1 (v varchar(16383));
2091
 
show create table t1;
2092
 
Table   Create Table
2093
 
t1      CREATE TABLE `t1` (
2094
 
  `v` varchar(16383) DEFAULT NULL
2095
 
) ENGINE=InnoDB
2096
 
drop table t1;
2097
 
create table t1 (v varchar(16383));
2098
 
show create table t1;
2099
 
Table   Create Table
2100
 
t1      CREATE TABLE `t1` (
2101
 
  `v` varchar(16383) DEFAULT NULL
2102
 
) ENGINE=InnoDB
2103
 
drop table t1;
2104
 
set storage_engine=InnoDB;
2105
 
create table t1 (v varchar(16383)) engine=innodb;
2106
 
drop table t1;
2107
 
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
2108
 
insert into t1 values ('8', '6'), ('4', '7');
2109
 
select min(a) from t1;
2110
 
min(a)
2111
 
4
2112
 
select min(b) from t1 where a='8';
2113
 
min(b)
2114
 
6
2115
 
drop table t1;
2116
 
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
2117
 
insert into t1 (b) values (1);
2118
 
replace into t1 (b) values (2), (1), (3);
2119
 
select * from t1;
2120
 
a       b
2121
 
2       2
2122
 
3       1
2123
 
4       3
2124
 
truncate table t1;
2125
 
insert into t1 (b) values (1);
2126
 
replace into t1 (b) values (2);
2127
 
replace into t1 (b) values (1);
2128
 
replace into t1 (b) values (3);
2129
 
select * from t1;
2130
 
a       b
2131
 
2       2
2132
 
3       1
2133
 
4       3
2134
 
drop table t1;
2135
 
create table t1 (rowid int not null auto_increment, val int not null,primary
2136
 
key (rowid), unique(val)) engine=innodb;
2137
 
replace into t1 (val) values ('1'),('2');
2138
 
replace into t1 (val) values ('1'),('2');
2139
 
insert into t1 (val) values ('1'),('2');
2140
 
ERROR 23000: Duplicate entry '1' for key 'val'
2141
 
select * from t1;
2142
 
rowid   val
2143
 
3       1
2144
 
4       2
2145
 
drop table t1;
2146
 
create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
2147
 
insert into t1 (val) values (1);
2148
 
update t1 set a=2 where a=1;
2149
 
insert into t1 (val) values (1);
2150
 
ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
2151
 
select * from t1;
2152
 
a       val
2153
 
2       1
2154
 
drop table t1;
2155
 
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
2156
 
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
2157
 
SELECT GRADE  FROM t1 WHERE GRADE > 160 AND GRADE < 300;
2158
 
GRADE
2159
 
252
2160
 
SELECT GRADE  FROM t1 WHERE GRADE= 151;
2161
 
GRADE
2162
 
151
2163
 
DROP TABLE t1;
2164
 
CREATE TABLE t1 (
2165
 
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
2166
 
) ENGINE=InnoDB;
2167
 
CREATE TABLE t2 (
2168
 
id INTEGER NOT NULL,
2169
 
FOREIGN KEY (id) REFERENCES t1 (id)
2170
 
) ENGINE=InnoDB;
2171
 
INSERT INTO t1 (id) VALUES (NULL);
2172
 
SELECT * FROM t1;
2173
 
id
2174
 
1
2175
 
TRUNCATE t1;
2176
 
INSERT INTO t1 (id) VALUES (NULL);
2177
 
SELECT * FROM t1;
2178
 
id
2179
 
1
2180
 
DELETE FROM t1;
2181
 
TRUNCATE t1;
2182
 
INSERT INTO t1 (id) VALUES (NULL);
2183
 
SELECT * FROM t1;
2184
 
id
2185
 
1
2186
 
DROP TABLE t2, t1;
2187
 
CREATE TABLE t1
2188
 
(
2189
 
id INT PRIMARY KEY
2190
 
) ENGINE=InnoDB;
2191
 
CREATE TEMPORARY TABLE t2
2192
 
(
2193
 
id INT NOT NULL PRIMARY KEY,
2194
 
b INT,
2195
 
FOREIGN KEY (b) REFERENCES test.t1(id)
2196
 
) ENGINE=InnoDB;
2197
 
Got one of the listed errors
2198
 
DROP TABLE t1;
2199
 
create table t1 (col1 varchar(2000), index (col1(767)))
2200
 
engine = innodb;
2201
 
Warnings:
2202
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2203
 
create table t2 (col1 char(255), index (col1))
2204
 
engine = innodb;
2205
 
Warnings:
2206
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2207
 
create table t4 (col1 varchar(767), index (col1))
2208
 
engine = innodb;
2209
 
Warnings:
2210
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2211
 
create table t5 (col1 varchar(190) primary key)
2212
 
engine = innodb;
2213
 
create table t6 (col1 varbinary(254) primary key)
2214
 
engine = innodb;
2215
 
create table t7 (col1 text, index(col1(767)))
2216
 
engine = innodb;
2217
 
Warnings:
2218
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2219
 
create table t8 (col1 blob, index(col1(767)))
2220
 
engine = innodb;
2221
 
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
2222
 
engine = innodb;
2223
 
Warnings:
2224
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2225
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2226
 
show create table t9;
2227
 
Table   Create Table
2228
 
t9      CREATE TABLE `t9` (
2229
 
  `col1` varchar(512) DEFAULT NULL,
2230
 
  `col2` varchar(512) DEFAULT NULL,
2231
 
  KEY `col1` (`col1`(191),`col2`(191))
2232
 
) ENGINE=InnoDB
2233
 
drop table t1, t2, t4, t5, t6, t7, t8, t9;
2234
 
create table t1 (col1 varchar(768), index(col1))
2235
 
engine = innodb;
2236
 
Warnings:
2237
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2238
 
create table t2 (col1 varbinary(768), index(col1))
2239
 
engine = innodb;
2240
 
Warnings:
2241
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2242
 
create table t3 (col1 text, index(col1(768)))
2243
 
engine = innodb;
2244
 
Warnings:
2245
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2246
 
create table t4 (col1 blob, index(col1(768)))
2247
 
engine = innodb;
2248
 
Warnings:
2249
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2250
 
show create table t1;
2251
 
Table   Create Table
2252
 
t1      CREATE TABLE `t1` (
2253
 
  `col1` varchar(768) DEFAULT NULL,
2254
 
  KEY `col1` (`col1`(191))
2255
 
) ENGINE=InnoDB
2256
 
drop table t1, t2, t3, t4;
2257
 
create table t1 (col1 varchar(768) primary key)
2258
 
engine = innodb;
2259
 
ERROR 42000: Specified key was too long; max key length is 767 bytes
2260
 
create table t2 (col1 varbinary(768) primary key)
2261
 
engine = innodb;
2262
 
ERROR 42000: Specified key was too long; max key length is 767 bytes
2263
 
create table t3 (col1 text, primary key(col1(768)))
2264
 
engine = innodb;
2265
 
ERROR 42000: Specified key was too long; max key length is 767 bytes
2266
 
create table t4 (col1 blob, primary key(col1(768)))
2267
 
engine = innodb;
2268
 
ERROR 42000: Specified key was too long; max key length is 767 bytes
2269
 
CREATE TABLE t1
2270
 
(
2271
 
id INT PRIMARY KEY
2272
 
) ENGINE=InnoDB;
2273
 
CREATE TABLE t2
2274
 
(
2275
 
v INT,
2276
 
CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
2277
 
) ENGINE=InnoDB;
2278
 
INSERT INTO t2 VALUES(2);
2279
 
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2280
 
INSERT INTO t1 VALUES(1);
2281
 
INSERT INTO t2 VALUES(1);
2282
 
DELETE FROM t1 WHERE id = 1;
2283
 
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2284
 
DROP TABLE t1;
2285
 
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
2286
 
SET FOREIGN_KEY_CHECKS=0;
2287
 
DROP TABLE t1;
2288
 
SET FOREIGN_KEY_CHECKS=1;
2289
 
INSERT INTO t2 VALUES(3);
2290
 
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2291
 
DROP TABLE t2;
2292
 
create table t1(a int not null) engine=innodb;
2293
 
insert into t1 values (1),(2);
2294
 
set autocommit=0;
2295
 
checksum table t1;
2296
 
Table   Checksum
2297
 
test.t1 1531596814
2298
 
insert into t1 values(3);
2299
 
checksum table t1;
2300
 
Table   Checksum
2301
 
test.t1 1531596814
2302
 
commit;
2303
 
checksum table t1;
2304
 
Table   Checksum
2305
 
test.t1 2050879373
2306
 
commit;
2307
 
drop table t1;
2308
 
create table t1(a int not null) engine=innodb;
2309
 
insert into t1 values (1),(2);
2310
 
set autocommit=1;
2311
 
checksum table t1;
2312
 
Table   Checksum
2313
 
test.t1 1531596814
2314
 
set autocommit=1;
2315
 
insert into t1 values(3);
2316
 
checksum table t1;
2317
 
Table   Checksum
2318
 
test.t1 2050879373
2319
 
drop table t1;
2320
 
set foreign_key_checks=0;
2321
 
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
2322
 
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
2323
 
ERROR HY000: Can't create table 'test.t1' (errno: 150)
2324
 
set foreign_key_checks=1;
2325
 
drop table t2;
2326
 
set foreign_key_checks=0;
2327
 
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
2328
 
create table t1(a varchar(10) primary key) engine = innodb;
2329
 
alter table t1 modify column a int;
2330
 
Got one of the listed errors
2331
 
set foreign_key_checks=1;
2332
 
drop table t2,t1;
2333
 
create table t1(a int primary key) row_format=redundant engine=innodb;
2334
 
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
2335
 
create table t3(a int primary key) row_format=compact engine=innodb;
2336
 
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
2337
 
insert into t1 values(1);
2338
 
insert into t3 values(1);
2339
 
insert into t2 values(2);
2340
 
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`))
2341
 
insert into t4 values(2);
2342
 
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
2343
 
insert into t2 values(1);
2344
 
insert into t4 values(1);
2345
 
update t1 set a=2;
2346
 
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`))
2347
 
update t2 set a=2;
2348
 
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`))
2349
 
update t3 set a=2;
2350
 
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`))
2351
 
update t4 set a=2;
2352
 
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`))
2353
 
truncate t1;
2354
 
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`))
2355
 
truncate t3;
2356
 
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`))
2357
 
truncate t2;
2358
 
truncate t4;
2359
 
truncate t1;
2360
 
truncate t3;
2361
 
drop table t4,t3,t2,t1;
2362
 
create table t1 (a varchar(255),
2363
 
b varchar(255),
2364
 
c varchar(255),
2365
 
d varchar(255),
2366
 
key (a,b,c,d)) engine=innodb;
2367
 
Warnings:
2368
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2369
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2370
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2371
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2372
 
drop table t1;
2373
 
create table t1 (a varchar(255),
2374
 
b varchar(255),
2375
 
c varchar(255),
2376
 
d varchar(255),
2377
 
e varchar(255),
2378
 
key (a,b,c,d,e)) engine=innodb;
2379
 
ERROR 42000: Specified key was too long; max key length is 3500 bytes
2380
 
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
2381
 
create table t3 (s1 varchar(2) ,primary key (s1)) engine=innodb;
2382
 
create table t4 (s1 char(2) ,primary key (s1)) engine=innodb;
2383
 
insert into t1 values (0x41),(0x4120),(0x4100);
2384
 
insert into t3 values (0x41),(0x4120),(0x4100);
2385
 
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2386
 
insert into t3 values (0x41),(0x4100);
2387
 
insert into t4 values (0x41),(0x4120),(0x4100);
2388
 
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2389
 
insert into t4 values (0x41),(0x4100);
2390
 
select hex(s1) from t1;
2391
 
hex(s1)
2392
 
41
2393
 
4100
2394
 
4120
2395
 
select hex(s1) from t3;
2396
 
hex(s1)
2397
 
4100
2398
 
41
2399
 
select hex(s1) from t4;
2400
 
hex(s1)
2401
 
4100
2402
 
41
2403
 
drop table t1,t3,t4;
2404
 
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
2405
 
create table t2 (s1 varbinary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
2406
 
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
2407
 
insert into t2 values(0x42);
2408
 
insert into t2 values(0x41);
2409
 
select hex(s1) from t2;
2410
 
hex(s1)
2411
 
41
2412
 
42
2413
 
update t1 set s1=0x123456 where a=2;
2414
 
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)
2415
 
select hex(s1) from t2;
2416
 
hex(s1)
2417
 
41
2418
 
42
2419
 
update t1 set s1=0x12 where a=1;
2420
 
update t1 set s1=0x12345678 where a=1;
2421
 
ERROR 22001: Data too long for column 's1' at row 1
2422
 
update t1 set s1=0x123457 where a=1;
2423
 
update t1 set s1=0x1220 where a=1;
2424
 
select hex(s1) from t2;
2425
 
hex(s1)
2426
 
41
2427
 
42
2428
 
update t1 set s1=0x1200 where a=1;
2429
 
select hex(s1) from t2;
2430
 
hex(s1)
2431
 
41
2432
 
42
2433
 
update t1 set s1=0x4200 where a=1;
2434
 
select hex(s1) from t2;
2435
 
hex(s1)
2436
 
41
2437
 
42
2438
 
delete from t1 where a=1;
2439
 
update t2 set s1=0x4120;
2440
 
delete from t1;
2441
 
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)
2442
 
delete from t1 where a!=3;
2443
 
select a,hex(s1) from t1;
2444
 
a       hex(s1)
2445
 
3       4120
2446
 
select hex(s1) from t2;
2447
 
hex(s1)
2448
 
4120
2449
 
4120
2450
 
drop table t2,t1;
2451
 
create table t1 (a int primary key,s1 varchar(2) not null unique) engine=innodb;
2452
 
create table t2 (s1 char(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
2453
 
insert into t1 values(1,0x4100),(2,0x41);
2454
 
insert into t2 values(0x41);
2455
 
select hex(s1) from t2;
2456
 
hex(s1)
2457
 
41
2458
 
update t1 set s1=0x1234 where a=1;
2459
 
select hex(s1) from t2;
2460
 
hex(s1)
2461
 
41
2462
 
update t1 set s1=0x12 where a=2;
2463
 
select hex(s1) from t2;
2464
 
hex(s1)
2465
 
12
2466
 
delete from t1 where a=1;
2467
 
delete from t1 where a=2;
2468
 
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)
2469
 
select a,hex(s1) from t1;
2470
 
a       hex(s1)
2471
 
2       12
2472
 
select hex(s1) from t2;
2473
 
hex(s1)
2474
 
12
2475
 
drop table t2,t1;
2476
 
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
2477
 
CREATE TABLE t2(a INT) ENGINE=InnoDB;
2478
 
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
2479
 
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
2480
 
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
2481
 
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
2482
 
SHOW CREATE TABLE t2;
2483
 
Table   Create Table
2484
 
t2      CREATE TABLE `t2` (
2485
 
  `a` int DEFAULT NULL,
2486
 
  KEY `t2_ibfk_0` (`a`)
2487
 
) ENGINE=InnoDB
2488
 
DROP TABLE t2,t1;
2489
 
CREATE TABLE t1 (
2490
 
field1 varchar(8) NOT NULL DEFAULT '',
2491
 
field2 varchar(8) NOT NULL DEFAULT '',
2492
 
PRIMARY KEY  (field1, field2)
2493
 
) ENGINE=InnoDB;
2494
 
CREATE TABLE t2 (
2495
 
field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
2496
 
FOREIGN KEY (field1) REFERENCES t1 (field1)
2497
 
ON DELETE CASCADE ON UPDATE CASCADE
2498
 
) ENGINE=InnoDB;
2499
 
INSERT INTO t1 VALUES ('old', 'somevalu');
2500
 
INSERT INTO t1 VALUES ('other', 'anyvalue');
2501
 
INSERT INTO t2 VALUES ('old');
2502
 
INSERT INTO t2 VALUES ('other');
2503
 
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
2504
 
ERROR 23000: Upholding foreign key constraints for table 't1', entry 'other-somevalu', key 1 would lead to a duplicate entry
2505
 
DROP TABLE t2;
2506
 
DROP TABLE t1;
2507
 
create table t1 (
2508
 
c1 bigint not null,
2509
 
c2 bigint not null,
2510
 
primary key (c1),
2511
 
unique  key (c2)
2512
 
) engine=innodb;
2513
 
create table t2 (
2514
 
c1 bigint not null,
2515
 
primary key (c1)
2516
 
) engine=innodb;
2517
 
alter table t1 add constraint c2_fk foreign key (c2)
2518
 
references t2(c1) on delete cascade;
2519
 
show create table t1;
2520
 
Table   Create Table
2521
 
t1      CREATE TABLE `t1` (
2522
 
  `c1` bigint NOT NULL,
2523
 
  `c2` bigint NOT NULL,
2524
 
  PRIMARY KEY (`c1`),
2525
 
  UNIQUE KEY `c2` (`c2`),
2526
 
  CONSTRAINT `c2_fk` FOREIGN KEY (`c2`) REFERENCES `t2` (`c1`) ON DELETE CASCADE
2527
 
) ENGINE=InnoDB
2528
 
alter table t1 drop foreign key c2_fk;
2529
 
show create table t1;
2530
 
Table   Create Table
2531
 
t1      CREATE TABLE `t1` (
2532
 
  `c1` bigint NOT NULL,
2533
 
  `c2` bigint NOT NULL,
2534
 
  PRIMARY KEY (`c1`),
2535
 
  UNIQUE KEY `c2` (`c2`)
2536
 
) ENGINE=InnoDB
2537
 
drop table t1, t2;
2538
 
create table t1(a date) engine=innodb;
2539
 
create table t2(a date, key(a)) engine=innodb;
2540
 
insert into t1 values('2005-10-01');
2541
 
insert into t2 values('2005-10-01');
2542
 
select * from t1, t2
2543
 
where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
2544
 
a       a
2545
 
2005-10-01      2005-10-01
2546
 
drop table t1, t2;
2547
 
create table t1 (id int not null, f_id int not null, f int not null,
2548
 
primary key(f_id, id)) engine=innodb;
2549
 
create table t2 (id int not null,s_id int not null,s varchar(200),
2550
 
primary key(id)) engine=innodb;
2551
 
INSERT INTO t1 VALUES (8, 1, 3);
2552
 
INSERT INTO t1 VALUES (1, 2, 1);
2553
 
INSERT INTO t2 VALUES (1, 0, '');
2554
 
INSERT INTO t2 VALUES (8, 1, '');
2555
 
commit;
2556
 
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
2557
 
where mm.id is null lock in share mode;
2558
 
id      f_id    f
2559
 
drop table t1,t2;
2560
 
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2561
 
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
2562
 
commit;
2563
 
set autocommit = 0;
2564
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2565
 
update t1 set b = 5 where b = 1;
2566
 
set autocommit = 0;
2567
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2568
 
select * from t1 where a = 7 and b = 3 for update;
2569
 
a       b
2570
 
7       3
2571
 
commit;
2572
 
commit;
2573
 
drop table t1;
2574
 
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2575
 
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
2576
 
commit;
2577
 
set autocommit = 0;
2578
 
select * from t1 lock in share mode;
2579
 
a       b
2580
 
1       1
2581
 
2       2
2582
 
3       1
2583
 
4       2
2584
 
5       1
2585
 
6       2
2586
 
update t1 set b = 5 where b = 1;
2587
 
set autocommit = 0;
2588
 
select * from t1 where a = 2 and b = 2 for update;
2589
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2590
 
commit;
2591
 
commit;
2592
 
drop table t1;
2593
 
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2594
 
insert into t1 values (1,2),(5,3),(4,2);
2595
 
create table t2(d int not null, e int, primary key(d)) engine=innodb;
2596
 
insert into t2 values (8,6),(12,1),(3,1);
2597
 
commit;
2598
 
set autocommit = 0;
2599
 
select * from t2 for update;
2600
 
d       e
2601
 
3       1
2602
 
8       6
2603
 
12      1
2604
 
set autocommit = 0;
2605
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2606
 
insert into t1 select * from t2;
2607
 
update t1 set b = (select e from t2 where a = d);
2608
 
create table t3(d int not null, e int, primary key(d)) engine=innodb
2609
 
select * from t2;
2610
 
commit;
2611
 
commit;
2612
 
drop table t1, t2, t3;
2613
 
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2614
 
insert into t1 values (1,2),(5,3),(4,2);
2615
 
create table t2(a int not null, b int, primary key(a)) engine=innodb;
2616
 
insert into t2 values (8,6),(12,1),(3,1);
2617
 
create table t3(d int not null, b int, primary key(d)) engine=innodb;
2618
 
insert into t3 values (8,6),(12,1),(3,1);
2619
 
create table t5(a int not null, b int, primary key(a)) engine=innodb;
2620
 
insert into t5 values (1,2),(5,3),(4,2);
2621
 
create table t6(d int not null, e int, primary key(d)) engine=innodb;
2622
 
insert into t6 values (8,6),(12,1),(3,1);
2623
 
create table t8(a int not null, b int, primary key(a)) engine=innodb;
2624
 
insert into t8 values (1,2),(5,3),(4,2);
2625
 
create table t9(d int not null, e int, primary key(d)) engine=innodb;
2626
 
insert into t9 values (8,6),(12,1),(3,1);
2627
 
commit;
2628
 
set autocommit = 0;
2629
 
select * from t2 for update;
2630
 
a       b
2631
 
3       1
2632
 
8       6
2633
 
12      1
2634
 
set autocommit = 0;
2635
 
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2636
 
insert into t1 select * from t2;
2637
 
set autocommit = 0;
2638
 
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2639
 
update t3 set b = (select b from t2 where a = d);
2640
 
set autocommit = 0;
2641
 
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2642
 
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
2643
 
set autocommit = 0;
2644
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2645
 
insert into t5 (select * from t2 lock in share mode);
2646
 
set autocommit = 0;
2647
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2648
 
update t6 set e = (select b from t2 where a = d lock in share mode);
2649
 
set autocommit = 0;
2650
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2651
 
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
2652
 
set autocommit = 0;
2653
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2654
 
insert into t8 (select * from t2 for update);
2655
 
set autocommit = 0;
2656
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2657
 
update t9 set e = (select b from t2 where a = d for update);
2658
 
set autocommit = 0;
2659
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2660
 
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
2661
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2662
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2663
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2664
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2665
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2666
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2667
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2668
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2669
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2670
 
commit;
2671
 
drop table t1, t2, t3, t5, t6, t8, t9;
2672
 
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
2673
 
ERROR HY000: Can't create table 'test.t1' (errno: -1)
2674
 
CREATE TABLE t1 (
2675
 
a BIGINT NOT NULL,
2676
 
PRIMARY KEY  (a)
2677
 
) ENGINE=INNODB;
2678
 
CREATE TABLE t2 (
2679
 
a BIGINT NOT NULL,
2680
 
b VARCHAR(128) NOT NULL,
2681
 
c TEXT NOT NULL,
2682
 
PRIMARY KEY  (a,b),
2683
 
KEY idx_t2_b_c (b,c(200)),
2684
 
CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a) 
2685
 
ON DELETE CASCADE
2686
 
) ENGINE=INNODB;
2687
 
Warnings:
2688
 
Warning 1071    Specified key was too long; max key length is 767 bytes
2689
 
INSERT INTO t1 VALUES (1);
2690
 
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
2691
 
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
2692
 
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
2693
 
INSERT INTO t2 VALUES (1, 'customer_over', '1');
2694
 
SELECT * FROM t2 WHERE b = 'customer_over';
2695
 
a       b       c
2696
 
1       customer_over   1
2697
 
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
2698
 
a       b       c
2699
 
1       customer_over   1
2700
 
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
2701
 
a
2702
 
1
2703
 
/* Bang: Empty result set, above was expected: */
2704
 
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2705
 
a
2706
 
1
2707
 
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2708
 
a
2709
 
1
2710
 
drop table t2, t1;
2711
 
CREATE TABLE t1 ( a int ) ENGINE=innodb;
2712
 
BEGIN;
2713
 
INSERT INTO t1 VALUES (1);
2714
 
ALTER TABLE t1 ENGINE=innodb;
2715
 
DROP TABLE t1;
2716
 
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
2717
 
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
2718
 
CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
2719
 
ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
2720
 
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
2721
 
DELETE CASCADE ON UPDATE CASCADE;
2722
 
SHOW CREATE TABLE t2;
2723
 
Table   Create Table
2724
 
t2      CREATE TABLE `t2` (
2725
 
  `id` int NOT NULL,
2726
 
  `f` int NOT NULL,
2727
 
  PRIMARY KEY (`id`),
2728
 
  KEY `f` (`f`),
2729
 
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f`) REFERENCES `t1` (`f`) ON DELETE CASCADE ON UPDATE CASCADE,
2730
 
  CONSTRAINT `t2_t1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2731
 
) ENGINE=InnoDB
2732
 
DROP TABLE t2, t1;
2733
 
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
2734
 
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
2735
 
INSERT INTO t1 VALUES (1);
2736
 
INSERT INTO t2 VALUES (1);
2737
 
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
2738
 
ALTER TABLE t2 MODIFY a INT NOT NULL;
2739
 
ERROR HY000: Error on rename of '#sql-temporary' to './test/t2' (errno: 150)
2740
 
DELETE FROM t1;
2741
 
DROP TABLE t2,t1;
2742
 
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
2743
 
ENGINE=InnoDB;
2744
 
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
2745
 
DELETE FROM t1;
2746
 
INSERT INTO t1 VALUES ('DDD');
2747
 
SELECT * FROM t1;
2748
 
a
2749
 
DDD
2750
 
DROP TABLE t1;
2751
 
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
2752
 
AUTO_INCREMENT=42;
2753
 
INSERT INTO t1 VALUES (NULL),(347),(NULL);
2754
 
SELECT * FROM t1;
2755
 
id
2756
 
42
2757
 
347
2758
 
348
2759
 
SHOW CREATE TABLE t1;
2760
 
Table   Create Table
2761
 
t1      CREATE TABLE `t1` (
2762
 
  `id` int NOT NULL AUTO_INCREMENT,
2763
 
  PRIMARY KEY (`id`)
2764
 
) ENGINE=InnoDB
2765
 
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
2766
 
INSERT INTO t2 VALUES(42),(347),(348);
2767
 
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
2768
 
SHOW CREATE TABLE t1;
2769
 
Table   Create Table
2770
 
t1      CREATE TABLE `t1` (
2771
 
  `id` int NOT NULL AUTO_INCREMENT,
2772
 
  PRIMARY KEY (`id`),
2773
 
  CONSTRAINT `t1_t2` FOREIGN KEY (`id`) REFERENCES `t2` (`id`)
2774
 
) ENGINE=InnoDB
2775
 
DROP TABLE t1,t2;
2776
 
DROP TABLE IF EXISTS t1;
2777
 
Warnings:
2778
 
Note    1051    Unknown table 't1'
2779
 
CREATE TABLE t1(
2780
 
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
2781
 
) ENGINE=InnoDB;
2782
 
INSERT INTO t1 VALUES(-10);
2783
 
SELECT * FROM t1;
2784
 
id
2785
 
-10
2786
 
INSERT INTO t1 VALUES(NULL);
2787
 
SELECT * FROM t1;
2788
 
id
2789
 
-10
2790
 
1
2791
 
DROP TABLE t1;