~drizzle-trunk/drizzle/development

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