~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/innodb.result

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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