~drizzle-trunk/drizzle/development

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