~drizzle-trunk/drizzle/development

641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
1
#######################################################################
2
#                                                                     #
3
# Please, DO NOT TOUCH this file as well as the innodb.result file.   #
4
# These files are to be modified ONLY BY INNOBASE guys.               #
5
#                                                                     #
6
# Use innodb_mysql.[test|result] files instead.                       #
7
#                                                                     #
8
# If nevertheless you need to make some changes here, please, forward #
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
9
# your commit message                                                 #
10
# To: innodb_dev_ww@oracle.com                                        #
11
# Cc: dev-innodb@mysql.com                                            #
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
12
# (otherwise your changes may be erased).                             #
13
#                                                                     #
14
#######################################################################
15
16
-- source include/have_innodb.inc
17
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
18
# Save the original values of some variables in order to be able to
19
# estimate how much they have changed during the tests. Previously this
20
# test assumed that e.g. rows_deleted is 0 here and after deleting 23
21
# rows it expected that rows_deleted will be 23. Now we do not make
22
# assumptions about the values of the variables at the beginning, e.g.
23
# rows_deleted should be 23 + "rows_deleted before the test". This allows
24
# the test to be run multiple times without restarting the mysqld server.
25
# See Bug#43309 Test main.innodb can't be run twice
26
-- disable_query_log
27
SET @innodb_thread_concurrency_orig = @@innodb_thread_concurrency;
28
29
SET @innodb_rows_deleted_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_deleted');
30
SET @innodb_rows_inserted_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_inserted');
31
SET @innodb_rows_updated_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_updated');
32
SET @innodb_row_lock_waits_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_waits');
33
SET @innodb_row_lock_current_waits_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_current_waits');
34
SET @innodb_row_lock_time_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time');
35
SET @innodb_row_lock_time_max_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_max');
36
SET @innodb_row_lock_time_avg_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_avg');
37
-- enable_query_log
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
38
39
--disable_warnings
40
drop table if exists t1,t2,t3,t4;
41
drop database if exists mysqltest;
42
--enable_warnings
43
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
44
#
45
# Small basic test with ignore
46
#
47
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
48
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
49
50
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
51
select id, code, name from t1 order by id;
52
53
update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
54
select id, code, name from t1 order by id;
55
update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
56
select id, code, name from t1 order by id;
57
58
drop table t1;
59
60
#
61
# A bit bigger test
62
# The 'replace_column' statements are needed because the cardinality calculated
63
# by innodb is not always the same between runs
64
#
65
66
CREATE TABLE t1 (
67
  id int(11) NOT NULL auto_increment,
68
  parent_id int(11) DEFAULT '0' NOT NULL,
69
  level tinyint(4) DEFAULT '0' NOT NULL,
70
  PRIMARY KEY (id),
71
  KEY parent_id (parent_id),
72
  KEY level (level)
73
) engine=innodb;
74
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);
75
update t1 set parent_id=parent_id+100;
76
select * from t1 where parent_id=102;
77
update t1 set id=id+1000;
78
-- error ER_DUP_ENTRY,1022
79
update t1 set id=1024 where id=1009; 
80
select * from t1;
81
update ignore t1 set id=id+1; # This will change all rows
82
select * from t1;
83
update ignore t1 set id=1023 where id=1010;
84
select * from t1 where parent_id=102;
85
--replace_column 9 #
86
explain select level from t1 where level=1;
87
--replace_column 9 #
88
explain select level,id from t1 where level=1;
89
--replace_column 9 #
90
explain select level,id,parent_id from t1 where level=1;
91
select level,id from t1 where level=1;
92
select level,id,parent_id from t1 where level=1;
93
optimize table t1;
94
--replace_column 7 #
95
show keys from t1;
96
drop table t1;
97
98
#
99
# Test replace
100
#
101
102
CREATE TABLE t1 (
103
  gesuchnr int(11) DEFAULT '0' NOT NULL,
104
  benutzer_id int(11) DEFAULT '0' NOT NULL,
105
  PRIMARY KEY (gesuchnr,benutzer_id)
106
) engine=innodb;
107
108
replace into t1 (gesuchnr,benutzer_id) values (2,1);
109
replace into t1 (gesuchnr,benutzer_id) values (1,1);
110
replace into t1 (gesuchnr,benutzer_id) values (1,1);
111
select * from t1;
112
drop table t1;
113
114
#
115
# test delete using hidden_primary_key
116
#
117
118
create table t1 (a int) engine=innodb;
119
insert into t1 values (1), (2);
120
optimize table t1;
121
delete from t1 where a = 1;
122
select * from t1;
123
check table t1;
124
drop table t1;
125
126
create table t1 (a int,b varchar(20)) engine=innodb;
127
insert into t1 values (1,""), (2,"testing");
128
delete from t1 where a = 1;
129
select * from t1;
130
create index skr on t1 (a);
131
insert into t1 values (3,""), (4,"testing");
132
analyze table t1;
133
--replace_column 7 #
134
show keys from t1;
135
drop table t1;
136
137
138
# Test of reading on secondary key with may be null
139
140
create table t1 (a int,b varchar(20),key(a)) engine=innodb;
141
insert into t1 values (1,""), (2,"testing");
142
select * from t1 where a = 1;
143
drop table t1;
144
145
#
146
# Test rollback
147
#
148
149
create table t1 (n int not null primary key) engine=innodb;
150
set autocommit=0;
151
insert into t1 values (4);
152
rollback;
153
select n, "after rollback" from t1;
154
insert into t1 values (4);
155
commit;
156
select n, "after commit" from t1;
157
commit;
158
insert into t1 values (5);
159
-- error ER_DUP_ENTRY
160
insert into t1 values (4);
161
commit;
162
select n, "after commit" from t1;
163
set autocommit=1;
164
insert into t1 values (6);
165
-- error ER_DUP_ENTRY
166
insert into t1 values (4);
167
select n from t1;
168
set autocommit=0;
169
#
170
# savepoints
171
#
172
begin;
173
savepoint `my_savepoint`;
174
insert into t1 values (7);
175
savepoint `savept2`;
176
insert into t1 values (3);
177
select n from t1;
178
savepoint savept3;
179
rollback to savepoint savept2;
180
--error 1305
181
rollback to savepoint savept3;
182
rollback to savepoint savept2;
183
release savepoint `my_savepoint`;
184
select n from t1;
185
-- error 1305
186
rollback to savepoint `my_savepoint`;
187
--error 1305
188
rollback to savepoint savept2;
189
insert into t1 values (8);
190
savepoint sv;
191
commit;
192
savepoint sv;
193
set autocommit=1;
194
# nop
195
rollback;
196
drop table t1;
197
198
#
199
# Test for commit and FLUSH TABLES WITH READ LOCK
200
#
201
202
create table t1 (n int not null primary key) engine=innodb;
203
start transaction;
204
insert into t1 values (4);
205
flush tables with read lock;
206
#
207
# Current code can't handle a read lock in middle of transaction
208
#--error 1223;
209
commit;
210
unlock tables;
211
commit;
212
select * from t1;
213
drop table t1;
214
215
#
216
# Testing transactions
217
#
218
219
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
220
begin;
221
insert into t1 values(1,'hamdouni');
222
select id as afterbegin_id,nom as afterbegin_nom from t1;
223
rollback;
224
select id as afterrollback_id,nom as afterrollback_nom from t1;
225
set autocommit=0;
226
insert into t1 values(2,'mysql');
227
select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
228
rollback;
229
select id as afterrollback_id,nom as afterrollback_nom from t1;
230
set autocommit=1;
231
drop table t1;
232
233
#
234
# Simple not autocommit test
235
# 
236
237
CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
238
insert into t1 values ('pippo', 12);
239
-- error ER_DUP_ENTRY
240
insert into t1 values ('pippo', 12); # Gives error
241
delete from t1;
242
delete from t1 where id = 'pippo';
243
select * from t1;
244
245
insert into t1 values ('pippo', 12);
246
set autocommit=0;
247
delete from t1;
248
rollback;
249
select * from t1;
250
delete from t1;
251
commit;
252
select * from t1;
253
drop table t1;
254
255
#
256
# Test of active transactions
257
#
258
259
create table t1 (a integer) engine=innodb;
260
start transaction;
261
rename table t1 to t2;
262
create table t1 (b integer) engine=innodb;
263
insert into t1 values (1);
264
rollback;
265
drop table t1;
266
rename table t2 to t1;
267
drop table t1;
268
set autocommit=1;
269
270
#
271
# The following simple tests failed at some point
272
#
273
274
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
275
INSERT INTO t1 VALUES (1, 'Jochen');
276
select * from t1;
277
drop table t1;
278
279
CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
280
set autocommit=0;
281
INSERT INTO t1  SET _userid='marc@anyware.co.uk';
282
COMMIT;
283
SELECT * FROM t1;
284
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
285
drop table t1;
286
set autocommit=1;
287
288
#
289
# Test when reading on part of unique key
290
#
291
CREATE TABLE t1 (
292
  user_id int(10) DEFAULT '0' NOT NULL,
293
  name varchar(100),
294
  phone varchar(100),
295
  ref_email varchar(100) DEFAULT '' NOT NULL,
296
  detail varchar(200),
297
  PRIMARY KEY (user_id,ref_email)
298
)engine=innodb;
299
300
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');
301
select * from t1 where user_id=10292;
302
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
303
select * from t1 where user_id=10292;
304
select * from t1 where user_id>=10292;
305
select * from t1 where user_id>10292;
306
select * from t1 where user_id<10292;
307
drop table t1;
308
309
#
310
# Test that keys are created in right order
311
#
312
313
CREATE TABLE t1 (a int not null, b int not null,c int not null,
314
key(a),primary key(a,b), unique(c),key(a),unique(b));
315
--replace_column 7 #
316
show index from t1;
317
drop table t1;
318
319
#
320
# Test of ALTER TABLE and innodb tables
321
#
322
323
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
324
alter table t1 engine=innodb;
325
insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
326
select * from t1;
327
update t1 set col2='7' where col1='4';
328
select * from t1;
329
alter table t1 add co3 int not null;
330
select * from t1;
331
update t1 set col2='9' where col1='2';
332
select * from t1;
333
drop table t1;
334
335
#
336
# INSERT INTO innodb tables
337
#
338
339
create table t1 (a int not null , b int, primary key (a)) engine = innodb;
340
create table t2 (a int not null , b int, primary key (a)) engine = myisam;
341
insert into t1 VALUES (1,3) , (2,3), (3,3);
342
select * from t1;
343
insert into t2 select * from t1;
344
select * from t2;
345
delete from t1 where b = 3;
346
select * from t1;
347
insert into t1 select * from t2;
348
select * from t1;
349
select * from t2;
350
drop table t1,t2;
351
352
#
353
# ORDER BY on not primary key
354
#
355
356
CREATE TABLE t1 (
357
  user_name varchar(12),
358
  password text,
359
  subscribed char(1),
360
  user_id int(11) DEFAULT '0' NOT NULL,
361
  quota bigint(20),
362
  weight double,
363
  access_date date,
364
  access_time time,
365
  approved datetime,
366
  dummy_primary_key int(11) NOT NULL auto_increment,
367
  PRIMARY KEY (dummy_primary_key)
368
) ENGINE=innodb;
369
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
370
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
371
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','23:06:59','2000-09-07 23:06:59',3);
372
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','23:06:59','2000-09-07 23:06:59',4);
373
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
374
select  user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
375
drop table t1;
376
377
#
378
# Testing of tables without primary keys
379
#
380
381
CREATE TABLE t1 (
382
  id int(11) NOT NULL auto_increment,
383
  parent_id int(11) DEFAULT '0' NOT NULL,
384
  level tinyint(4) DEFAULT '0' NOT NULL,
385
  KEY (id),
386
  KEY parent_id (parent_id),
387
  KEY level (level)
388
) engine=innodb;
389
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);
390
INSERT INTO t1 values (179,5,2);
391
update t1 set parent_id=parent_id+100;
392
select * from t1 where parent_id=102;
393
update t1 set id=id+1000;
394
update t1 set id=1024 where id=1009; 
395
select * from t1;
396
update ignore t1 set id=id+1; # This will change all rows
397
select * from t1;
398
update ignore t1 set id=1023 where id=1010;
399
select * from t1 where parent_id=102;
400
--replace_column 9 #
401
explain select level from t1 where level=1;
402
select level,id from t1 where level=1;
403
select level,id,parent_id from t1 where level=1;
404
select level,id from t1 where level=1 order by id;
405
delete from t1 where level=1;
406
select * from t1;
407
drop table t1;
408
409
#
410
# Test of index only reads
411
#
412
CREATE TABLE t1 (
413
   sca_code char(6) NOT NULL,
414
   cat_code char(6) NOT NULL,
415
   sca_desc varchar(50),
416
   lan_code char(2) NOT NULL,
417
   sca_pic varchar(100),
418
   sca_sdesc varchar(50),
419
   sca_sch_desc varchar(16),
420
   PRIMARY KEY (sca_code, cat_code, lan_code),
421
   INDEX sca_pic (sca_pic)
422
) engine = innodb ;
423
424
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');
425
select count(*) from t1 where sca_code = 'PD';
426
select count(*) from t1 where sca_code <= 'PD';
427
select count(*) from t1 where sca_pic is null;
428
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
429
select count(*) from t1 where sca_code='PD' and sca_pic is null;
430
select count(*) from t1 where cat_code='E';
431
432
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
433
select count(*) from t1 where sca_code='PD' and sca_pic is null;
434
select count(*) from t1 where sca_pic >= 'n';
435
select sca_pic from t1 where sca_pic is null;
436
update t1 set sca_pic="test" where sca_pic is null;
437
delete from t1 where sca_code='pd';
438
drop table t1;
439
440
#
441
# Test of opening table twice and timestamps
442
#
443
set @a:=now();
444
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
445
insert into t1 (a) values(1),(2),(3);
446
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
447
select a from t1 natural join t1 as t2 where b >= @a order by a;
448
update t1 set a=5 where a=1;
449
select a from t1;
450
drop table t1;
451
452
#
453
# Test with variable length primary key
454
#
455
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
456
insert into t1 values("hello",1),("world",2);
457
select * from t1 order by b desc;
458
optimize table t1;
459
--replace_column 7 #
460
show keys from t1;
461
drop table t1;
462
463
#
464
# Test of create index with NULL columns
465
#
466
create table t1 (i int, j int ) ENGINE=innodb;
467
insert into t1 values (1,2);
468
select * from t1 where i=1 and j=2;
469
create index ax1 on t1 (i,j);
470
select * from t1 where i=1 and j=2;
471
drop table t1;
472
473
#
474
# Test min-max optimization
475
#
476
477
CREATE TABLE t1 (
478
  a int3 unsigned NOT NULL,
479
  b int1 unsigned NOT NULL,
480
  UNIQUE (a, b)
481
) ENGINE = innodb;
482
 
483
INSERT INTO t1 VALUES (1, 1);
484
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
485
drop table t1;
486
487
#
488
# Test INSERT DELAYED
489
#
490
491
CREATE TABLE t1 (a int unsigned NOT NULL) engine=innodb;
492
# Can't test this in 3.23
493
# INSERT DELAYED INTO t1 VALUES (1);
494
INSERT INTO t1 VALUES (1);
495
SELECT * FROM t1;
496
DROP TABLE t1;
497
498
499
#
500
# Crash when using many tables (Test case by Jeremy D Zawodny)
501
#
502
503
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;
504
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);
505
--replace_column 9 #
506
explain select * from t1 where a > 0 and a < 50;
507
drop table t1;
508
509
#
510
# Test lock tables
511
#
512
513
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;
514
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
515
LOCK TABLES t1 WRITE;
516
--error ER_DUP_ENTRY
517
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
518
select id from t1;
519
select id from t1;
520
UNLOCK TABLES;
521
DROP TABLE t1;
522
523
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;
524
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
525
LOCK TABLES t1 WRITE;
526
begin;
527
--error ER_DUP_ENTRY
528
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
529
select id from t1;
530
insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
531
commit;
532
select id,id3 from t1;
533
UNLOCK TABLES;
534
DROP TABLE t1;
535
536
#
537
# Test prefix key
538
#
539
create table t1 (a char(20), unique (a(5))) engine=innodb;
540
drop table t1;
541
create table t1 (a char(20), index (a(5))) engine=innodb;
542
show create table t1;
543
drop table t1;
544
545
#
546
# Test using temporary table and auto_increment
547
#
548
549
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
550
insert into t1 values (NULL),(NULL),(NULL);
551
delete from t1 where a=3;
552
insert into t1 values (NULL);
553
select * from t1;
554
alter table t1 add b int;
555
select * from t1;
556
drop table t1;
557
558
#Slashdot bug
559
create table t1
560
 (
561
  id int auto_increment primary key,
562
  name varchar(32) not null,
563
  value text not null,
564
  uid int not null,
565
  unique key(name,uid)
566
 ) engine=innodb;
567
insert into t1 values (1,'one','one value',101),
568
 (2,'two','two value',102),(3,'three','three value',103);
569
set insert_id=5;
570
replace into t1 (value,name,uid) values ('other value','two',102);
571
delete from t1 where uid=102;
572
set insert_id=5;
573
replace into t1 (value,name,uid) values ('other value','two',102);
574
set insert_id=6;
575
replace into t1 (value,name,uid) values ('other value','two',102);
576
select * from t1;
577
drop table t1;
578
579
#
580
# Test DROP DATABASE
581
#
582
583
create database mysqltest;
584
create table mysqltest.t1 (a int not null) engine= innodb;
585
insert into mysqltest.t1 values(1);
586
create table mysqltest.t2 (a int not null) engine= myisam;
587
insert into mysqltest.t2 values(1);
588
create table mysqltest.t3 (a int not null) engine= heap;
589
insert into mysqltest.t3 values(1);
590
commit;
591
drop database mysqltest;
592
# Don't check error message
593
--error 1049
594
show tables from mysqltest;
595
596
#
597
# Test truncate table with and without auto_commit
598
#
599
600
set autocommit=0;
601
create table t1 (a int not null) engine= innodb;
602
insert into t1 values(1),(2);
603
truncate table t1;
604
commit;
605
truncate table t1;
606
truncate table t1;
607
select * from t1;
608
insert into t1 values(1),(2);
609
delete from t1;
610
select * from t1;
611
commit;
612
drop table t1;
613
set autocommit=1;
614
615
create table t1 (a int not null) engine= innodb;
616
insert into t1 values(1),(2);
617
truncate table t1;
618
insert into t1 values(1),(2);
619
select * from t1;
620
truncate table t1;
621
insert into t1 values(1),(2);
622
delete from t1;
623
select * from t1;
624
drop table t1;
625
626
#
627
# Test of how ORDER BY works when doing it on the whole table
628
#
629
630
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
631
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
632
--replace_column 9 #
633
explain select * from t1 order by a;
634
--replace_column 9 #
635
explain select * from t1 order by b;
636
--replace_column 9 #
637
explain select * from t1 order by c;
638
--replace_column 9 #
639
explain select a from t1 order by a;
640
--replace_column 9 #
641
explain select b from t1 order by b;
642
--replace_column 9 #
643
explain select a,b from t1 order by b;
644
--replace_column 9 #
645
explain select a,b from t1;
646
--replace_column 9 #
647
explain select a,b,c from t1;
648
drop table t1;
649
650
#
651
# Check describe
652
#
653
654
create table t1 (t int not null default 1, key (t)) engine=innodb;
655
desc t1;
656
drop table t1;
657
658
#
659
# Test of multi-table-delete
660
#
661
662
CREATE TABLE t1 (
663
  number bigint(20) NOT NULL default '0',
664
  cname char(15) NOT NULL default '',
665
  carrier_id smallint(6) NOT NULL default '0',
666
  privacy tinyint(4) NOT NULL default '0',
667
  last_mod_date timestamp NOT NULL,
668
  last_mod_id smallint(6) NOT NULL default '0',
669
  last_app_date timestamp NOT NULL,
670
  last_app_id smallint(6) default '-1',
671
  version smallint(6) NOT NULL default '0',
672
  assigned_scps int(11) default '0',
673
  status tinyint(4) default '0'
674
) ENGINE=InnoDB;
675
INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
676
INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
677
INSERT INTO t1 VALUES (650,'San Francisco',0,0,20011227111336,342,00000000000000,-1,1,24,1);
678
INSERT INTO t1 VALUES (302467,'Sue\'s Subshop',90,3,20020109113241,500,20020102115111,501,7,24,0);
679
INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
680
INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
681
CREATE TABLE t2 (
682
  number bigint(20) NOT NULL default '0',
683
  cname char(15) NOT NULL default '',
684
  carrier_id smallint(6) NOT NULL default '0',
685
  privacy tinyint(4) NOT NULL default '0',
686
  last_mod_date timestamp NOT NULL,
687
  last_mod_id smallint(6) NOT NULL default '0',
688
  last_app_date timestamp NOT NULL,
689
  last_app_id smallint(6) default '-1',
690
  version smallint(6) NOT NULL default '0',
691
  assigned_scps int(11) default '0',
692
  status tinyint(4) default '0'
693
) ENGINE=InnoDB;
694
INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
695
INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
696
INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,00000000000000,-1,1,24,1);
697
INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
698
select * from t1;
699
select * from t2;
700
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);
701
select * from t1;
702
select * from t2; 
703
select * from t2;
704
drop table t1,t2;
705
706
#
707
# A simple test with some isolation levels
708
# TODO: Make this into a test using replication to really test how
709
# this works.
710
#
711
712
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
713
714
BEGIN;
715
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
716
SELECT @@tx_isolation,@@global.tx_isolation;
717
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
718
select id, code, name from t1 order by id;
719
COMMIT;
720
721
BEGIN;
722
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
723
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
724
select id, code, name from t1 order by id;
725
COMMIT;
726
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
727
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
728
BEGIN;
729
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
730
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
731
select id, code, name from t1 order by id;
732
COMMIT;
733
DROP TABLE t1;
734
735
#
736
# Test of multi-table-update
737
#
738
create table t1 (n int(10), d int(10)) engine=innodb;
739
create table t2 (n int(10), d int(10)) engine=innodb;
740
insert into t1 values(1,1),(1,2);
741
insert into t2 values(1,10),(2,20);
742
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
743
select * from t1;
744
select * from t2;
745
drop table t1,t2;
746
747
#
748
# Bug #29136  	erred multi-delete on trans table does not rollback 
749
#
750
751
# prepare
752
--disable_warnings
753
drop table if exists t1, t2;
754
--enable_warnings
755
CREATE TABLE t1 (a int, PRIMARY KEY (a));
756
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
757
create trigger trg_del_t2 after  delete on t2 for each row
758
       insert into t1 values (1);
759
insert into t1 values (1);
760
insert into t2 values (1),(2);
761
762
763
# exec cases A, B - see multi_update.test
764
765
# A. send_error() w/o send_eof() branch
766
767
--error ER_DUP_ENTRY
768
delete t2 from t2;
769
770
# check
771
772
select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
773
774
# cleanup bug#29136
775
776
drop table t1, t2;
777
778
779
#
780
# Bug #29136  	erred multi-delete on trans table does not rollback 
781
#
782
783
# prepare
784
--disable_warnings
785
drop table if exists t1, t2;
786
--enable_warnings
787
CREATE TABLE t1 (a int, PRIMARY KEY (a));
788
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
789
create trigger trg_del_t2 after  delete on t2 for each row
790
       insert into t1 values (1);
791
insert into t1 values (1);
792
insert into t2 values (1),(2);
793
794
795
# exec cases A, B - see multi_update.test
796
797
# A. send_error() w/o send_eof() branch
798
799
--error ER_DUP_ENTRY
800
delete t2 from t2;
801
802
# check
803
804
select count(*) from t2 /* must be 2 as restored after rollback caused by the error */;
805
806
# cleanup bug#29136
807
808
drop table t1, t2;
809
810
811
#
812
# Testing of IFNULL
813
#
814
create table t1 (a int, b int) engine=innodb;
815
insert into t1 values(20,null);
816
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
817
t2.b=t3.a;
818
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
819
t2.b=t3.a order by 1;
820
insert into t1 values(10,null);
821
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
822
t2.b=t3.a order by 1;
823
drop table t1;
824
825
#
826
# Test of read_through not existing const_table
827
#
828
829
create table t1 (a varchar(10) not null) engine=myisam;
830
create table t2 (b varchar(10) not null unique) engine=innodb;
831
select t1.a from t1,t2 where t1.a=t2.b;
832
drop table t1,t2;
833
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
834
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
835
insert into t1 values (10, 20);
836
insert into t2 values (10, 20);
837
update t1, t2 set t1.b = 150, t2.b = t1.b where t2.a = t1.a and t1.a = 10;
838
drop table t1,t2;
839
840
#
841
# Test of multi-table-delete with foreign key constraints
842
#
843
844
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
845
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;
846
insert into t1 set id=1;
847
insert into t2 set id=1, t1_id=1;
848
delete t1,t2 from t1,t2 where t1.id=t2.t1_id;
849
select * from t1;
850
select * from t2;
851
drop table t2,t1;
852
CREATE TABLE t1(id INT NOT NULL,  PRIMARY KEY (id)) ENGINE=INNODB;
853
CREATE TABLE t2(id  INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id)  ) ENGINE=INNODB;
854
INSERT INTO t1 VALUES(1);
855
INSERT INTO t2 VALUES(1, 1);
856
SELECT * from t1;
857
UPDATE t1,t2 SET t1.id=t1.id+1, t2.t1_id=t1.id+1;
858
SELECT * from t1;
859
UPDATE t1,t2 SET t1.id=t1.id+1 where t1.id!=t2.id;
860
SELECT * from t1;
861
DROP TABLE t1,t2;
862
863
#
864
# Test of range_optimizer
865
#
866
867
set autocommit=0;
868
869
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
870
871
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
872
873
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
874
875
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
876
COMMIT;
877
878
INSERT INTO t1 VALUES("this-key", "will disappear");
879
INSERT INTO t2 VALUES("this-key", "will also disappear");
880
DELETE FROM t3 WHERE id1="my-test-1";
881
882
SELECT * FROM t1;
883
SELECT * FROM t2;
884
SELECT * FROM t3;
885
ROLLBACK;
886
887
SELECT * FROM t1;
888
SELECT * FROM t2;
889
SELECT * FROM t3;
890
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
891
COMMIT;
892
set autocommit=1;
893
DROP TABLE t1,t2,t3;
894
895
#
896
# Check update with conflicting key
897
#
898
899
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
900
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
901
# We need the a < 1000 test here to quard against the halloween problems
902
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
903
SELECT * from t1;
904
drop table t1;
905
906
#
907
# Test multi update with different join methods
908
#
909
910
CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) engine=innodb;
911
CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) engine=innodb;
912
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);
913
INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
914
915
# Full join, without key
916
update t1,t2 set t1.a=t1.a+100;
917
select * from t1;
918
919
# unique key
920
update t1,t2 set t1.a=t1.a+100 where t1.a=101;
921
select * from t1;
922
923
# ref key
924
update t1,t2 set t1.b=t1.b+10 where t1.b=2;
925
select * from t1;
926
927
# Range key (in t1)
928
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;
929
select * from t1;
930
select * from t2;
931
932
drop table t1,t2;
933
CREATE TABLE t2 (   NEXT_T         BIGINT NOT NULL PRIMARY KEY) ENGINE=MyISAM;
934
CREATE TABLE t1 (  B_ID           INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB;
935
SET AUTOCOMMIT=0;
936
INSERT INTO t1 ( B_ID ) VALUES ( 1 );
937
INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );
938
ROLLBACK;
939
SELECT * FROM t1;
940
drop table  t1,t2;
941
create table t1  ( pk         int primary key,    parent     int not null,    child      int not null,       index (parent)  ) engine = innodb;
942
insert into t1 values   (1,0,4),  (2,1,3),  (3,2,1),  (4,1,2);
943
select distinct  parent,child   from t1   order by parent;
944
drop table t1;
945
946
#
947
# Test that MySQL priorities clustered indexes
948
#
949
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
950
create table t2 (a int not null auto_increment primary key, b int);
951
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
952
insert into t2 (a) select b from t1;
953
insert into t1 (b) select b from t2;
954
insert into t2 (a) select b from t1;
955
insert into t1 (a) select b from t2;
956
insert into t2 (a) select b from t1;
957
insert into t1 (a) select b from t2;
958
insert into t2 (a) select b from t1;
959
insert into t1 (a) select b from t2;
960
insert into t2 (a) select b from t1;
961
insert into t1 (a) select b from t2;
962
select count(*) from t1;
963
--replace_column 9 #
964
explain select * from t1 where c between 1 and 2500;
965
update t1 set c=a;
966
--replace_column 9 #
967
explain select * from t1 where c between 1 and 2500;
968
drop table t1,t2;
969
970
#
971
# Test of UPDATE ... ORDER BY
972
#
973
974
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
975
976
insert into t1 (id) values (null),(null),(null),(null),(null);
977
update t1 set fk=69 where fk is null order by id limit 1;
978
SELECT * from t1;
979
drop table t1;
980
981
create table t1 (a int not null, b int not null, key (a));
982
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);
983
SET @tmp=0;
984
update t1 set b=(@tmp:=@tmp+1) order by a;
985
update t1 set b=99 where a=1 order by b asc limit 1;
986
update t1 set b=100 where a=1 order by b desc limit 2;
987
update t1 set a=a+10+b where a=1 order by b;
988
select * from t1 order by a,b;
989
drop table t1;
990
991
#
992
# Test of multi-table-updates (bug #1980).
993
#
994
995
create table t1 ( c char(8) not null ) engine=innodb;
996
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
997
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
998
999
alter table t1 add b char(8) not null;
1000
alter table t1 add a char(8) not null;
1001
alter table t1 add primary key (a,b,c);
1002
update t1 set a=c, b=c;
1003
1004
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;
1005
insert into t2 select * from t1;
1006
1007
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
1008
drop table t1,t2;
1009
1010
#
1011
# test autoincrement with TRUNCATE
1012
#
1013
1014
SET AUTOCOMMIT=1;
1015
create table t1 (a integer auto_increment primary key) engine=innodb;
1016
insert into t1 (a) values (NULL),(NULL);
1017
truncate table t1;
1018
insert into t1 (a) values (NULL),(NULL);
1019
SELECT * from t1;
1020
drop table t1;
1021
1022
#
1023
# Test dictionary handling with spaceand quoting
1024
#
1025
1026
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
1027
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;
1028
#show create table t2;
1029
drop table t2,t1;
1030
1031
#
1032
# Test of multi updated and foreign keys
1033
#
1034
1035
create table `t1` (`id` int( 11 ) not null  ,primary key ( `id` )) engine = innodb;
1036
insert into `t1`values ( 1 ) ;
1037
create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = innodb;
1038
insert into `t2`values ( 1 ) ;
1039
create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb;
1040
insert into `t3`values ( 1 ) ;
1041
--error 1451
1042
delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
1043
--error 1451
1044
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;
1045
--error 1054
1046
update t3 set  t3.id=7  where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
1047
drop table t3,t2,t1;
1048
1049
#
1050
# test for recursion depth limit
1051
#
1052
create table t1(
1053
	id int primary key,
1054
	pid int,
1055
	index(pid),
1056
	foreign key(pid) references t1(id) on delete cascade) engine=innodb;
1057
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
1058
	(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
1059
-- error 1451
1060
delete from t1 where id=0;
1061
delete from t1 where id=15;
1062
delete from t1 where id=0;
1063
1064
drop table t1;
1065
1066
#
1067
# Test timestamps
1068
#
1069
1070
CREATE TABLE t1 (col1 int(1))ENGINE=InnoDB;
1071
CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx
1072
(stamp))ENGINE=InnoDB;
1073
insert into t1 values (1),(2),(3);
1074
# Note that timestamp 3 is wrong
1075
insert into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);
1076
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
1077
'20020204120000' GROUP BY col1;
1078
drop table t1,t2;
1079
1080
#
1081
# Test by Francois MASUREL
1082
#
1083
1084
CREATE TABLE t1 (
1085
  `id` int(10) unsigned NOT NULL auto_increment,
1086
  `id_object` int(10) unsigned default '0',
1087
  `id_version` int(10) unsigned NOT NULL default '1',
1088
  `label` varchar(100) NOT NULL default '',
1089
  `description` text,
1090
  PRIMARY KEY  (`id`),
1091
  KEY `id_object` (`id_object`),
1092
  KEY `id_version` (`id_version`)
1093
) ENGINE=InnoDB;
1094
1095
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);
1096
1097
CREATE TABLE t2 (
1098
  `id` int(10) unsigned NOT NULL auto_increment,
1099
  `id_version` int(10) unsigned NOT NULL default '1',
1100
  PRIMARY KEY  (`id`),
1101
  KEY `id_version` (`id_version`)
1102
) ENGINE=InnoDB;
1103
1104
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
1105
1106
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
1107
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl 
1108
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
1109
drop table t1,t2;
1110
1111
create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=myisam;
1112
create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=innodb;
1113
create table t3 (a int, b varchar(200), c text not null) checksum=1 engine=innodb;
1114
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
1115
insert t2 select * from t1;
1116
insert t3 select * from t1;
1117
checksum table t1, t2, t3, t4 quick;
1118
checksum table t1, t2, t3, t4;
1119
checksum table t1, t2, t3, t4 extended;
1120
#show table status;
1121
drop table t1,t2,t3;
1122
1123
#
1124
# Test problem with refering to different fields in same table in UNION
1125
# (Bug #2552)
1126
#
1127
create table t1 (id int,  name char(10) not null,  name2 char(10) not null) engine=innodb;
1128
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
1129
select trim(name2) from t1  union all  select trim(name) from t1 union all select trim(id) from t1;
1130
drop table t1;
1131
1132
#
1133
# Bug2160
1134
#
1135
create table t1 (a int) engine=innodb;
1136
create table t2 like t1;
1137
drop table t1,t2;
1138
1139
#
1140
# Test of automaticly created foreign keys
1141
#
1142
1143
create table t1 (id int(11) not null, id2 int(11) not null, unique (id,id2)) engine=innodb;
1144
create table t2 (id int(11) not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
1145
show create table t1;
1146
show create table t2;
1147
create index id on t2 (id);
1148
show create table t2;
1149
create index id2 on t2 (id);
1150
show create table t2;
1151
drop index id2 on t2;
1152
--error ER_DROP_INDEX_FK
1153
drop index id on t2;
1154
show create table t2;
1155
drop table t2;
1156
1157
create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;
1158
show create table t2;
1159
create unique index id on t2 (id,id2);
1160
show create table t2;
1161
drop table t2;
1162
1163
# Check foreign key columns created in different order than key columns
1164
create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
1165
show create table t2;
1166
drop table t2;
1167
1168
create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;
1169
show create table t2;
1170
drop table t2;
1171
1172
create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
1173
show create table t2;
1174
drop table t2;
1175
1176
create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
1177
show create table t2;
1178
drop table t2;
1179
1180
create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
1181
show create table t2;
1182
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1183
show create table t2;
1184
drop table t2;
1185
1186
# Test error handling
1187
1188
# Embedded server doesn't chdir to data directory
1189
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1190
--error ER_WRONG_FK_DEF
1191
create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
1192
1193
# bug#3749
1194
1195
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
1196
show create table t2;
1197
drop table t2;
1198
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;
1199
show create table t2;
1200
drop table t2, t1;
1201
1202
1203
#
1204
# Bug #6126: Duplicate columns in keys gives misleading error message
1205
#
1206
--error 1060
1207
create table t1 (c char(10), index (c,c)) engine=innodb;
1208
--error 1060
1209
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
1210
--error 1060
1211
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
1212
--error 1060
1213
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
1214
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
1215
--error 1060
1216
alter table t1 add key (c1,c1);
1217
--error 1060
1218
alter table t1 add key (c2,c1,c1);
1219
--error 1060
1220
alter table t1 add key (c1,c2,c1);
1221
--error 1060
1222
alter table t1 add key (c1,c1,c2);
1223
drop table t1;
1224
1225
#
1226
# Bug #4082: integer truncation
1227
#
1228
1229
create table t1(a int(1) , b int(1)) engine=innodb;
1230
insert into t1 values ('1111', '3333');
1231
select distinct concat(a, b) from t1;
1232
drop table t1;
1233
1234
#
1235
# BUG#7709 test case - Boolean fulltext query against unsupported 
1236
#                      engines does not fail
1237
#
1238
1239
CREATE TABLE t1 ( a char(10) ) ENGINE=InnoDB;
1240
--error 1214
1241
SELECT a FROM t1 WHERE MATCH (a) AGAINST ('test' IN BOOLEAN MODE);
1242
DROP TABLE t1;
1243
1244
#
1245
# check null values #1
1246
#
1247
1248
--disable_warnings
1249
CREATE TABLE t1 (a_id tinyint(4) NOT NULL default '0', PRIMARY KEY  (a_id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
1250
INSERT INTO t1 VALUES (1),(2),(3);
1251
CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL default '0', PRIMARY KEY  (b_id), KEY  (b_a), 
1252
                CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=latin1;
1253
--enable_warnings
1254
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
1255
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;
1256
DROP TABLE t2;
1257
DROP TABLE t1;
1258
1259
#
1260
# Bug#11816 - Truncate table doesn't work with temporary innodb tables
1261
# This is not an innodb bug, but we test it using innodb.
1262
#
1263
create temporary table t1 (a int) engine=innodb;
1264
insert into t1 values (4711);
1265
truncate t1;
1266
insert into t1 values (42);
1267
select * from t1;
1268
drop table t1;
1269
# Show that it works with permanent tables too.
1270
create table t1 (a int) engine=innodb;
1271
insert into t1 values (4711);
1272
truncate t1;
1273
insert into t1 values (42);
1274
select * from t1;
1275
drop table t1;
1276
1277
#
1278
# Bug #13025  Server crash during filesort	
1279
#
1280
1281
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;
1282
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
1283
select * from t1 order by a,b,c,d;
1284
explain select * from t1 order by a,b,c,d;
1285
drop table t1;
1286
1287
#
1288
# BUG#11039,#13218 Wrong key length in min()
1289
#
1290
1291
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1292
insert into t1 values ('8', '6'), ('4', '7');
1293
select min(a) from t1;
1294
select min(b) from t1 where a='8';
1295
drop table t1;
1296
1297
# End of 4.1 tests
1298
1299
#
1300
# range optimizer problem
1301
#
1302
1303
create table t1 (x bigint unsigned not null primary key) engine=innodb;
1304
insert into t1(x) values (0xfffffffffffffff0),(0xfffffffffffffff1);
1305
select * from t1;
1306
select count(*) from t1 where x>0;
1307
select count(*) from t1 where x=0;
1308
select count(*) from t1 where x<0;
1309
select count(*) from t1 where x < -16;
1310
select count(*) from t1 where x = -16;
1311
explain select count(*) from t1 where x > -16;
1312
select count(*) from t1 where x > -16;
1313
select * from t1 where x > -16;
1314
select count(*) from t1 where x = 18446744073709551601;
1315
drop table t1;
1316
1317
1318
# Test for testable InnoDB status variables. This test
1319
# uses previous ones(pages_created, rows_deleted, ...).
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
1320
--replace_result 8192 8191
1321
SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_buffer_pool_pages_total';
1322
SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_page_size';
1323
SELECT variable_value - @innodb_rows_deleted_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_deleted';
1324
SELECT variable_value - @innodb_rows_inserted_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_inserted';
1325
SELECT variable_value - @innodb_rows_updated_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_updated';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
1326
1327
# Test for row locks InnoDB status variables.
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
1328
SELECT variable_value - @innodb_row_lock_waits_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_waits';
1329
SELECT variable_value - @innodb_row_lock_current_waits_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_current_waits';
1330
SELECT variable_value - @innodb_row_lock_time_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time';
1331
SELECT variable_value - @innodb_row_lock_time_max_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_max';
1332
SELECT variable_value - @innodb_row_lock_time_avg_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_avg';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
1333
1334
# Test for innodb_sync_spin_loops variable
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
1335
SET @innodb_sync_spin_loops_orig = @@innodb_sync_spin_loops;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
1336
show variables like "innodb_sync_spin_loops";
1337
set global innodb_sync_spin_loops=1000;
1338
show variables like "innodb_sync_spin_loops";
1339
set global innodb_sync_spin_loops=0;
1340
show variables like "innodb_sync_spin_loops";
1341
set global innodb_sync_spin_loops=20;
1342
show variables like "innodb_sync_spin_loops";
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
1343
set global innodb_sync_spin_loops=@innodb_sync_spin_loops_orig;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
1344
1345
# Test for innodb_thread_concurrency variable
1346
show variables like "innodb_thread_concurrency";
1347
set global innodb_thread_concurrency=1001;
1348
show variables like "innodb_thread_concurrency";
1349
set global innodb_thread_concurrency=0;
1350
show variables like "innodb_thread_concurrency";
1351
set global innodb_thread_concurrency=16;
1352
show variables like "innodb_thread_concurrency";
1353
1354
# Test for innodb_concurrency_tickets variable
1355
show variables like "innodb_concurrency_tickets";
1356
set global innodb_concurrency_tickets=1000;
1357
show variables like "innodb_concurrency_tickets";
1358
set global innodb_concurrency_tickets=0;
1359
show variables like "innodb_concurrency_tickets";
1360
set global innodb_concurrency_tickets=500;
1361
show variables like "innodb_concurrency_tickets";
1362
1363
# Test for innodb_thread_sleep_delay variable
1364
show variables like "innodb_thread_sleep_delay";
1365
set global innodb_thread_sleep_delay=100000;
1366
show variables like "innodb_thread_sleep_delay";
1367
set global innodb_thread_sleep_delay=0;
1368
show variables like "innodb_thread_sleep_delay";
1369
set global innodb_thread_sleep_delay=10000;
1370
show variables like "innodb_thread_sleep_delay";
1371
1372
#
1373
# Test varchar
1374
#
1375
1376
let $default=`select @@storage_engine`;
1377
set storage_engine=INNODB;
1378
source include/varchar.inc;
1379
1380
#
1381
# Some errors/warnings on create
1382
#
1383
1384
# Embedded server doesn't chdir to data directory
1385
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1386
create table t1 (v varchar(65530), key(v));
1387
drop table t1;
1388
create table t1 (v varchar(65536));
1389
show create table t1;
1390
drop table t1;
1391
create table t1 (v varchar(65530) character set utf8);
1392
show create table t1;
1393
drop table t1;
1394
1395
eval set storage_engine=$default;
1396
1397
# InnoDB specific varchar tests
1398
create table t1 (v varchar(16384)) engine=innodb;
1399
drop table t1;
1400
1401
#
1402
# BUG#11039 Wrong key length in min()
1403
#
1404
1405
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1406
insert into t1 values ('8', '6'), ('4', '7');
1407
select min(a) from t1;
1408
select min(b) from t1 where a='8';
1409
drop table t1;
1410
1411
#
1412
# Bug #11080 & #11005  Multi-row REPLACE fails on a duplicate key error
1413
#
1414
1415
CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
1416
insert into t1 (b) values (1);
1417
replace into t1 (b) values (2), (1), (3);
1418
select * from t1;
1419
truncate table t1;
1420
insert into t1 (b) values (1);
1421
replace into t1 (b) values (2);
1422
replace into t1 (b) values (1);
1423
replace into t1 (b) values (3);
1424
select * from t1;
1425
drop table t1;
1426
1427
create table t1 (rowid int not null auto_increment, val int not null,primary
1428
key (rowid), unique(val)) engine=innodb;
1429
replace into t1 (val) values ('1'),('2');
1430
replace into t1 (val) values ('1'),('2');
1431
--error ER_DUP_ENTRY
1432
insert into t1 (val) values ('1'),('2');
1433
select * from t1;
1434
drop table t1;
1435
1436
#
1437
# Test that update does not change internal auto-increment value
1438
#
1439
1440
create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
1441
insert into t1 (val) values (1);
1442
update t1 set a=2 where a=1;
1443
# We should get the following error because InnoDB does not update the counter
1444
--error ER_DUP_ENTRY
1445
insert into t1 (val) values (1);
1446
select * from t1;
1447
drop table t1;
1448
#
1449
# Bug #10465
1450
#
1451
1452
--disable_warnings
1453
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
1454
--enable_warnings
1455
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
1456
SELECT GRADE  FROM t1 WHERE GRADE > 160 AND GRADE < 300;
1457
SELECT GRADE  FROM t1 WHERE GRADE= 151;
1458
DROP TABLE t1;
1459
1460
#
1461
# Bug #12340 multitable delete deletes only one record
1462
#
1463
create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb;
1464
create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb;
1465
insert into t2 values ('aa','cc');
1466
insert into t1 values ('aa','bb'),('aa','cc');
1467
delete t1 from t1,t2 where f1=f3 and f4='cc';
1468
select * from t1;
1469
drop table t1,t2;
1470
1471
#
1472
# Test that the slow TRUNCATE implementation resets autoincrement columns
1473
# (bug #11946)
1474
#
1475
1476
CREATE TABLE t1 (
1477
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
1478
) ENGINE=InnoDB;
1479
1480
CREATE TABLE t2 (
1481
id INTEGER NOT NULL,
1482
FOREIGN KEY (id) REFERENCES t1 (id)
1483
) ENGINE=InnoDB;
1484
1485
INSERT INTO t1 (id) VALUES (NULL);
1486
SELECT * FROM t1;
1487
TRUNCATE t1;
1488
INSERT INTO t1 (id) VALUES (NULL);
1489
SELECT * FROM t1;
1490
1491
# continued from above; test that doing a slow TRUNCATE on a table with 0
1492
# rows resets autoincrement columns
1493
DELETE FROM t1;
1494
TRUNCATE t1;
1495
INSERT INTO t1 (id) VALUES (NULL);
1496
SELECT * FROM t1;
1497
DROP TABLE t2, t1;
1498
1499
# Test that foreign keys in temporary tables are not accepted (bug #12084)
1500
CREATE TABLE t1
1501
(
1502
 id INT PRIMARY KEY
1503
) ENGINE=InnoDB;
1504
1505
--error 1005,1005
1506
CREATE TEMPORARY TABLE t2
1507
(
1508
 id INT NOT NULL PRIMARY KEY,
1509
 b INT,
1510
 FOREIGN KEY (b) REFERENCES test.t1(id)
1511
) ENGINE=InnoDB;
1512
DROP TABLE t1;
1513
1514
#
1515
# Test that index column max sizes are honored (bug #13315)
1516
#
1517
1518
# prefix index
1519
create table t1 (col1 varchar(2000), index (col1(767)))
1520
 character set = latin1 engine = innodb;
1521
1522
# normal indexes
1523
create table t2 (col1 char(255), index (col1))
1524
 character set = latin1 engine = innodb;
1525
create table t3 (col1 binary(255), index (col1))
1526
 character set = latin1 engine = innodb;
1527
create table t4 (col1 varchar(767), index (col1))
1528
 character set = latin1 engine = innodb;
1529
create table t5 (col1 varchar(767) primary key)
1530
 character set = latin1 engine = innodb;
1531
create table t6 (col1 varbinary(767) primary key)
1532
 character set = latin1 engine = innodb;
1533
create table t7 (col1 text, index(col1(767)))
1534
 character set = latin1 engine = innodb;
1535
create table t8 (col1 blob, index(col1(767)))
1536
 character set = latin1 engine = innodb;
1537
1538
# multi-column indexes are allowed to be longer
1539
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
1540
 character set = latin1 engine = innodb;
1541
1542
show create table t9;
1543
1544
drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
1545
1546
# these should have their index length trimmed
1547
create table t1 (col1 varchar(768), index(col1))
1548
 character set = latin1 engine = innodb;
1549
create table t2 (col1 varbinary(768), index(col1))
1550
 character set = latin1 engine = innodb;
1551
create table t3 (col1 text, index(col1(768)))
1552
 character set = latin1 engine = innodb;
1553
create table t4 (col1 blob, index(col1(768)))
1554
 character set = latin1 engine = innodb;
1555
1556
show create table t1;
1557
1558
drop table t1, t2, t3, t4;
1559
1560
# these should be refused
1561
--error 1071
1562
create table t1 (col1 varchar(768) primary key)
1563
 character set = latin1 engine = innodb;
1564
--error 1071
1565
create table t2 (col1 varbinary(768) primary key)
1566
 character set = latin1 engine = innodb;
1567
--error 1071
1568
create table t3 (col1 text, primary key(col1(768)))
1569
 character set = latin1 engine = innodb;
1570
--error 1071
1571
create table t4 (col1 blob, primary key(col1(768)))
1572
 character set = latin1 engine = innodb;
1573
1574
#
1575
# Test improved foreign key error messages (bug #3443)
1576
#
1577
1578
CREATE TABLE t1
1579
(
1580
 id INT PRIMARY KEY
1581
) ENGINE=InnoDB;
1582
1583
CREATE TABLE t2
1584
(
1585
 v INT,
1586
 CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
1587
) ENGINE=InnoDB;
1588
1589
--error 1452
1590
INSERT INTO t2 VALUES(2);
1591
1592
INSERT INTO t1 VALUES(1);
1593
INSERT INTO t2 VALUES(1);
1594
1595
--error 1451
1596
DELETE FROM t1 WHERE id = 1;
1597
1598
--error 1217
1599
DROP TABLE t1;
1600
1601
SET FOREIGN_KEY_CHECKS=0;
1602
DROP TABLE t1;
1603
SET FOREIGN_KEY_CHECKS=1;
1604
1605
--error 1452
1606
INSERT INTO t2 VALUES(3);
1607
1608
DROP TABLE t2;
1609
#
1610
# Test that checksum table uses a consistent read Bug #12669
1611
#
1612
connect (a,localhost,root,,);
1613
connect (b,localhost,root,,);
1614
connection a;
1615
create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
1616
insert into t1 values (1),(2);
1617
set autocommit=0;
1618
checksum table t1;
1619
connection b;
1620
insert into t1 values(3);
1621
connection a;
1622
#
1623
# Here checksum should not see insert
1624
#
1625
checksum table t1;
1626
connection a;
1627
commit;
1628
checksum table t1;
1629
commit;
1630
drop table t1;
1631
#
1632
# autocommit = 1
1633
#
1634
connection a;
1635
create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
1636
insert into t1 values (1),(2);
1637
set autocommit=1;
1638
checksum table t1;
1639
connection b;
1640
set autocommit=1;
1641
insert into t1 values(3);
1642
connection a;
1643
#
1644
# Here checksum sees insert
1645
#
1646
checksum table t1;
1647
drop table t1;
1648
1649
connection default;
1650
disconnect a;
1651
disconnect b;
1652
1653
# tests for bugs #9802 and #13778
1654
1655
# test that FKs between invalid types are not accepted
1656
1657
set foreign_key_checks=0;
1658
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
1659
# Embedded server doesn't chdir to data directory
1660
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1661
-- error 1005
1662
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
1663
set foreign_key_checks=1;
1664
drop table t2;
1665
1666
# test that FKs between different charsets are not accepted in CREATE even
1667
# when f_k_c is 0
1668
1669
set foreign_key_checks=0;
1670
create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
1671
# Embedded server doesn't chdir to data directory
1672
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1673
-- error 1005
1674
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=utf8;
1675
set foreign_key_checks=1;
1676
drop table t1;
1677
1678
# test that invalid datatype conversions with ALTER are not allowed
1679
1680
set foreign_key_checks=0;
1681
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
1682
create table t1(a varchar(10) primary key) engine = innodb;
1683
-- error 1025,1025
1684
alter table t1 modify column a int;
1685
set foreign_key_checks=1;
1686
drop table t2,t1;
1687
1688
# test that charset conversions with ALTER are allowed when f_k_c is 0
1689
1690
set foreign_key_checks=0;
1691
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
1692
create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
1693
alter table t1 convert to character set utf8;
1694
set foreign_key_checks=1;
1695
drop table t2,t1;
1696
1697
# test that RENAME does not allow invalid charsets when f_k_c is 0
1698
1699
set foreign_key_checks=0;
1700
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
1701
create table t3(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=utf8;
1702
# Embedded server doesn't chdir to data directory
1703
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1704
-- error 1025
1705
rename table t3 to t1;
1706
set foreign_key_checks=1;
1707
drop table t2,t3;
1708
1709
# test that foreign key errors are reported correctly (Bug #15550)
1710
1711
create table t1(a int primary key) row_format=redundant engine=innodb;
1712
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
1713
create table t3(a int primary key) row_format=compact engine=innodb;
1714
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
1715
1716
insert into t1 values(1);
1717
insert into t3 values(1);
1718
-- error 1452
1719
insert into t2 values(2);
1720
-- error 1452
1721
insert into t4 values(2);
1722
insert into t2 values(1);
1723
insert into t4 values(1);
1724
-- error 1451
1725
update t1 set a=2;
1726
-- error 1452
1727
update t2 set a=2;
1728
-- error 1451
1729
update t3 set a=2;
1730
-- error 1452
1731
update t4 set a=2;
1732
-- error 1451
1733
truncate t1;
1734
-- error 1451
1735
truncate t3;
1736
truncate t2;
1737
truncate t4;
1738
truncate t1;
1739
truncate t3;
1740
1741
drop table t4,t3,t2,t1;
1742
1743
1744
#
1745
# Test that we can create a large (>1K) key
1746
#
1747
create table t1 (a varchar(255) character set utf8,
1748
                 b varchar(255) character set utf8,
1749
                 c varchar(255) character set utf8,
1750
                 d varchar(255) character set utf8,
1751
                 key (a,b,c,d)) engine=innodb;
1752
drop table t1;
1753
--error ER_TOO_LONG_KEY
1754
create table t1 (a varchar(255) character set utf8,
1755
                 b varchar(255) character set utf8,
1756
                 c varchar(255) character set utf8,
1757
                 d varchar(255) character set utf8,
1758
                 e varchar(255) character set utf8,
1759
                 key (a,b,c,d,e)) engine=innodb;
1760
1761
1762
# test the padding of BINARY types and collations (Bug #14189)
1763
1764
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
1765
create table t2 (s1 binary(2),primary key (s1)) engine=innodb;
1766
create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb;
1767
create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb;
1768
1769
insert into t1 values (0x41),(0x4120),(0x4100);
1770
-- error ER_DUP_ENTRY
1771
insert into t2 values (0x41),(0x4120),(0x4100);
1772
insert into t2 values (0x41),(0x4120);
1773
-- error ER_DUP_ENTRY
1774
insert into t3 values (0x41),(0x4120),(0x4100);
1775
insert into t3 values (0x41),(0x4100);
1776
-- error ER_DUP_ENTRY
1777
insert into t4 values (0x41),(0x4120),(0x4100);
1778
insert into t4 values (0x41),(0x4100);
1779
select hex(s1) from t1;
1780
select hex(s1) from t2;
1781
select hex(s1) from t3;
1782
select hex(s1) from t4;
1783
drop table t1,t2,t3,t4;
1784
1785
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
1786
create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
1787
1788
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
1789
-- error 1452
1790
insert into t2 values(0x42);
1791
insert into t2 values(0x41);
1792
select hex(s1) from t2;
1793
update t1 set s1=0x123456 where a=2;
1794
select hex(s1) from t2;
1795
-- error 1451
1796
update t1 set s1=0x12 where a=1;
1797
-- error 1451
1798
update t1 set s1=0x12345678 where a=1;
1799
-- error 1451
1800
update t1 set s1=0x123457 where a=1;
1801
update t1 set s1=0x1220 where a=1;
1802
select hex(s1) from t2;
1803
update t1 set s1=0x1200 where a=1;
1804
select hex(s1) from t2;
1805
update t1 set s1=0x4200 where a=1;
1806
select hex(s1) from t2;
1807
-- error 1451
1808
delete from t1 where a=1;
1809
delete from t1 where a=2;
1810
update t2 set s1=0x4120;
1811
-- error 1451
1812
delete from t1;
1813
delete from t1 where a!=3;
1814
select a,hex(s1) from t1;
1815
select hex(s1) from t2;
1816
1817
drop table t2,t1;
1818
1819
create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=innodb;
1820
create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
1821
1822
insert into t1 values(1,0x4100),(2,0x41);
1823
insert into t2 values(0x41);
1824
select hex(s1) from t2;
1825
update t1 set s1=0x1234 where a=1;
1826
select hex(s1) from t2;
1827
update t1 set s1=0x12 where a=2;
1828
select hex(s1) from t2;
1829
delete from t1 where a=1;
1830
-- error 1451
1831
delete from t1 where a=2;
1832
select a,hex(s1) from t1;
1833
select hex(s1) from t2;
1834
1835
drop table t2,t1;
1836
# Ensure that <tablename>_ibfk_0 is not mistreated as a
1837
# generated foreign key identifier.  (Bug #16387)
1838
1839
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
1840
CREATE TABLE t2(a INT) ENGINE=InnoDB;
1841
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
1842
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
1843
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
1844
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
1845
SHOW CREATE TABLE t2;
1846
DROP TABLE t2,t1;
1847
1848
#
1849
# Test case for bug #16229: MySQL/InnoDB uses full explicit table locks in trigger processing
1850
#
1851
1852
connect (a,localhost,root,,);
1853
connect (b,localhost,root,,);
1854
connection a;
1855
create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1856
insert into t1(a) values (1),(2),(3);
1857
commit;
1858
connection b;
1859
set autocommit = 0;
1860
update t1 set b = 5 where a = 2;
1861
connection a;
1862
delimiter |;
1863
create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
1864
delimiter ;|
1865
set autocommit = 0;
1866
connection a;
1867
insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
1868
(11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
1869
(12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
1870
(13),(23),(33),(43),(53),(63),(73),(83),(93),(103),
1871
(14),(24),(34),(44),(54),(64),(74),(84),(94),(104);
1872
connection b;
1873
commit;
1874
connection a;
1875
commit;
1876
drop trigger t1t;
1877
drop table t1;
1878
disconnect a;
1879
disconnect b;
1880
#
1881
# Another trigger test
1882
#
1883
connect (a,localhost,root,,);
1884
connect (b,localhost,root,,);
1885
connection a;
1886
create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1887
create table t2(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1888
create table t3(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1889
create table t4(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1890
create table t5(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
1891
insert into t1(a) values (1),(2),(3);
1892
insert into t2(a) values (1),(2),(3);
1893
insert into t3(a) values (1),(2),(3);
1894
insert into t4(a) values (1),(2),(3);
1895
insert into t3(a) values (5),(7),(8);
1896
insert into t4(a) values (5),(7),(8);
1897
insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
1898
1899
delimiter |;
1900
create trigger t1t before insert on t1 for each row begin 
1901
    INSERT INTO t2 SET a = NEW.a;
1902
end |
1903
1904
create trigger t2t before insert on t2 for each row begin
1905
    DELETE FROM t3 WHERE a = NEW.a;
1906
end |
1907
1908
create trigger t3t before delete on t3 for each row begin  
1909
    UPDATE t4 SET b = b + 1 WHERE a = OLD.a;
1910
end |
1911
1912
create trigger t4t before update on t4 for each row begin
1913
    UPDATE t5 SET b = b + 1 where a = NEW.a;
1914
end |
1915
delimiter ;|
1916
commit;
1917
set autocommit = 0;
1918
update t1 set b = b + 5 where a = 1;
1919
update t2 set b = b + 5 where a = 1;
1920
update t3 set b = b + 5 where a = 1;
1921
update t4 set b = b + 5 where a = 1;
1922
insert into t5(a) values(20);
1923
connection b;
1924
set autocommit = 0;
1925
insert into t1(a) values(7);
1926
insert into t2(a) values(8);
1927
delete from t2 where a = 3;
1928
update t4 set b = b + 1 where a = 3;
1929
commit;
1930
drop trigger t1t;
1931
drop trigger t2t;
1932
drop trigger t3t;
1933
drop trigger t4t;
1934
drop table t1, t2, t3, t4, t5;
1935
connection default;
1936
disconnect a;
1937
disconnect b;
1938
1939
#
1940
# Test that cascading updates leading to duplicate keys give the correct
1941
# error message (bug #9680)
1942
#
1943
1944
CREATE TABLE t1 (
1945
  field1 varchar(8) NOT NULL DEFAULT '',
1946
  field2 varchar(8) NOT NULL DEFAULT '',
1947
  PRIMARY KEY  (field1, field2)
1948
) ENGINE=InnoDB;
1949
1950
CREATE TABLE t2 (
1951
  field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
1952
  FOREIGN KEY (field1) REFERENCES t1 (field1)
1953
    ON DELETE CASCADE ON UPDATE CASCADE
1954
) ENGINE=InnoDB;
1955
1956
INSERT INTO t1 VALUES ('old', 'somevalu');
1957
INSERT INTO t1 VALUES ('other', 'anyvalue');
1958
1959
INSERT INTO t2 VALUES ('old');
1960
INSERT INTO t2 VALUES ('other');
1961
1962
--error ER_FOREIGN_DUPLICATE_KEY
1963
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
1964
1965
DROP TABLE t2;
1966
DROP TABLE t1;
1967
1968
#
1969
# Bug#18477 - MySQL/InnoDB Ignoring Foreign Keys in ALTER TABLE
1970
#
1971
create table t1 (
1972
  c1 bigint not null,
1973
  c2 bigint not null,
1974
  primary key (c1),
1975
  unique  key (c2)
1976
) engine=innodb;
1977
#
1978
create table t2 (
1979
  c1 bigint not null,
1980
  primary key (c1)
1981
) engine=innodb;
1982
#
1983
alter table t1 add constraint c2_fk foreign key (c2)
1984
  references t2(c1) on delete cascade;
1985
show create table t1;
1986
#
1987
alter table t1 drop foreign key c2_fk;
1988
show create table t1;
1989
#
1990
drop table t1, t2;
1991
1992
#
1993
# Bug #14360: problem with intervals
1994
#
1995
1996
create table t1(a date) engine=innodb;
1997
create table t2(a date, key(a)) engine=innodb;
1998
insert into t1 values('2005-10-01');
1999
insert into t2 values('2005-10-01');
2000
select * from t1, t2
2001
  where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
2002
drop table t1, t2;
2003
2004
create table t1 (id int not null, f_id int not null, f int not null,
2005
primary key(f_id, id)) engine=innodb;
2006
create table t2 (id int not null,s_id int not null,s varchar(200),
2007
primary key(id)) engine=innodb;
2008
INSERT INTO t1 VALUES (8, 1, 3);
2009
INSERT INTO t1 VALUES (1, 2, 1);
2010
INSERT INTO t2 VALUES (1, 0, '');
2011
INSERT INTO t2 VALUES (8, 1, '');
2012
commit;
2013
DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
2014
WHERE mm.id IS NULL;
2015
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
2016
where mm.id is null lock in share mode;
2017
drop table t1,t2;
2018
2019
#
2020
# Test case where X-locks on unused rows should be released in a
2021
# update (because READ COMMITTED isolation level)
2022
#
2023
2024
connect (a,localhost,root,,);
2025
connect (b,localhost,root,,);
2026
connection a;
2027
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2028
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
2029
commit;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2030
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2031
set autocommit = 0; 
2032
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2033
update t1 set b = 5 where b = 1;
2034
connection b;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2035
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2036
set autocommit = 0;
2037
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2038
#
2039
# X-lock to record (7,3) should be released in a update 
2040
#
2041
select * from t1 where a = 7 and b = 3 for update;
2042
connection a;
2043
commit;
2044
connection b;
2045
commit;
2046
drop table t1;
2047
connection default;
2048
disconnect a;
2049
disconnect b;
2050
2051
#
2052
# Test case where no locks should be released (because we are not
2053
# using READ COMMITTED isolation level)
2054
#
2055
2056
connect (a,localhost,root,,);
2057
connect (b,localhost,root,,);
2058
connection a;
2059
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2060
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
2061
commit;
2062
set autocommit = 0; 
2063
select * from t1 lock in share mode;
2064
update t1 set b = 5 where b = 1;
2065
connection b;
2066
set autocommit = 0;
2067
#
2068
# S-lock to records (2,2),(4,2), and (6,2) should not be released in a update
2069
#
2070
--error 1205
2071
select * from t1 where a = 2 and b = 2 for update;
2072
#
2073
# X-lock to record (1,1),(3,1),(5,1) should not be released in a update
2074
#
2075
--error 1205
2076
connection a;
2077
commit;
2078
connection b;
2079
commit;
2080
connection default;
2081
disconnect a;
2082
disconnect b;
2083
drop table t1;
2084
2085
#
2086
# Consistent read should be used in following selects
2087
#
2088
# 1) INSERT INTO ... SELECT
2089
# 2) UPDATE ... = ( SELECT ...)
2090
# 3) CREATE ... SELECT
2091
2092
connect (a,localhost,root,,);
2093
connect (b,localhost,root,,);
2094
connection a;
2095
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2096
insert into t1 values (1,2),(5,3),(4,2);
2097
create table t2(d int not null, e int, primary key(d)) engine=innodb;
2098
insert into t2 values (8,6),(12,1),(3,1);
2099
commit;
2100
set autocommit = 0;
2101
select * from t2 for update;
2102
connection b;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2103
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2104
set autocommit = 0;
2105
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2106
insert into t1 select * from t2;
2107
update t1 set b = (select e from t2 where a = d);
2108
create table t3(d int not null, e int, primary key(d)) engine=innodb
2109
select * from t2;
2110
commit;
2111
connection a;
2112
commit;
2113
connection default;
2114
disconnect a;
2115
disconnect b;
2116
drop table t1, t2, t3;
2117
2118
#
2119
# Consistent read should not be used if 
2120
#
2121
# (a) isolation level is serializable OR
2122
# (b) select ... lock in share mode OR
2123
# (c) select ... for update
2124
#
2125
# in following queries:
2126
#
2127
# 1) INSERT INTO ... SELECT
2128
# 2) UPDATE ... = ( SELECT ...)
2129
# 3) CREATE ... SELECT
2130
2131
connect (a,localhost,root,,);
2132
connect (b,localhost,root,,);
2133
connect (c,localhost,root,,);
2134
connect (d,localhost,root,,);
2135
connect (e,localhost,root,,);
2136
connect (f,localhost,root,,);
2137
connect (g,localhost,root,,);
2138
connect (h,localhost,root,,);
2139
connect (i,localhost,root,,);
2140
connect (j,localhost,root,,);
2141
connection a;
2142
create table t1(a int not null, b int, primary key(a)) engine=innodb;
2143
insert into t1 values (1,2),(5,3),(4,2);
2144
create table t2(a int not null, b int, primary key(a)) engine=innodb;
2145
insert into t2 values (8,6),(12,1),(3,1);
2146
create table t3(d int not null, b int, primary key(d)) engine=innodb;
2147
insert into t3 values (8,6),(12,1),(3,1);
2148
create table t5(a int not null, b int, primary key(a)) engine=innodb;
2149
insert into t5 values (1,2),(5,3),(4,2);
2150
create table t6(d int not null, e int, primary key(d)) engine=innodb;
2151
insert into t6 values (8,6),(12,1),(3,1);
2152
create table t8(a int not null, b int, primary key(a)) engine=innodb;
2153
insert into t8 values (1,2),(5,3),(4,2);
2154
create table t9(d int not null, e int, primary key(d)) engine=innodb;
2155
insert into t9 values (8,6),(12,1),(3,1);
2156
commit;
2157
set autocommit = 0;
2158
select * from t2 for update;
2159
connection b;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2160
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2161
set autocommit = 0;
2162
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2163
--send
2164
insert into t1 select * from t2;
2165
connection c;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2166
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2167
set autocommit = 0;
2168
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2169
--send
2170
update t3 set b = (select b from t2 where a = d);
2171
connection d;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2172
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2173
set autocommit = 0;
2174
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
2175
--send
2176
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
2177
connection e;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2178
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2179
set autocommit = 0;
2180
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2181
--send
2182
insert into t5 (select * from t2 lock in share mode);
2183
connection f;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2184
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2185
set autocommit = 0;
2186
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2187
--send
2188
update t6 set e = (select b from t2 where a = d lock in share mode);
2189
connection g;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2190
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2191
set autocommit = 0;
2192
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2193
--send
2194
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
2195
connection h;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2196
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2197
set autocommit = 0;
2198
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2199
--send
2200
insert into t8 (select * from t2 for update);
2201
connection i;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2202
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2203
set autocommit = 0;
2204
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2205
--send
2206
update t9 set e = (select b from t2 where a = d for update);
2207
connection j;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2208
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2209
set autocommit = 0;
2210
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2211
--send
2212
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
2213
2214
connection b;
2215
--error 1205
2216
reap;
2217
2218
connection c;
2219
--error 1205
2220
reap;
2221
2222
connection d;
2223
--error 1205
2224
reap;
2225
2226
connection e;
2227
--error 1205
2228
reap;
2229
2230
connection f;
2231
--error 1205
2232
reap;
2233
2234
connection g;
2235
--error 1205
2236
reap;
2237
2238
connection h;
2239
--error 1205
2240
reap;
2241
2242
connection i;
2243
--error 1205
2244
reap;
2245
2246
connection j;
2247
--error 1205
2248
reap;
2249
2250
connection a;
2251
commit;
2252
2253
connection default;
2254
disconnect a;
2255
disconnect b;
2256
disconnect c;
2257
disconnect d;
2258
disconnect e;
2259
disconnect f;
2260
disconnect g;
2261
disconnect h;
2262
disconnect i;
2263
disconnect j;
2264
drop table t1, t2, t3, t5, t6, t8, t9;
2265
2266
# bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID"
2267
--error 1005
2268
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
2269
2270
#
2271
# Bug #17152: Wrong result with BINARY comparison on aliased column
2272
#
2273
2274
CREATE TABLE t1 (
2275
   a BIGINT(20) NOT NULL,
2276
    PRIMARY KEY  (a)
2277
 ) ENGINE=INNODB DEFAULT CHARSET=UTF8;
2278
2279
CREATE TABLE t2 (
2280
  a BIGINT(20) NOT NULL,
2281
  b VARCHAR(128) NOT NULL,
2282
  c TEXT NOT NULL,
2283
  PRIMARY KEY  (a,b),
2284
  KEY idx_t2_b_c (b,c(200)),
2285
  CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a) 
2286
   ON DELETE CASCADE
2287
 ) ENGINE=INNODB DEFAULT CHARSET=UTF8;
2288
2289
INSERT INTO t1 VALUES (1);
2290
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
2291
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
2292
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
2293
INSERT INTO t2 VALUES (1, 'customer_over', '1');
2294
2295
SELECT * FROM t2 WHERE b = 'customer_over';
2296
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
2297
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
2298
/* Bang: Empty result set, above was expected: */
2299
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2300
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
2301
2302
drop table t2, t1;
2303
2304
#
2305
# Test optimize on table with open transaction
2306
#
2307
2308
CREATE TABLE t1 ( a int ) ENGINE=innodb;
2309
BEGIN;
2310
INSERT INTO t1 VALUES (1);
2311
OPTIMIZE TABLE t1;
2312
DROP TABLE t1;
2313
2314
#
2315
# Bug #24741 (existing cascade clauses disappear when adding foreign keys)
2316
#
2317
2318
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
2319
2320
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
2321
  CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
2322
  ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
2323
2324
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
2325
DELETE CASCADE ON UPDATE CASCADE;
2326
2327
SHOW CREATE TABLE t2;
2328
DROP TABLE t2, t1;
2329
2330
#
2331
# Bug #25927: Prevent ALTER TABLE ... MODIFY ... NOT NULL on columns
2332
# for which there is a foreign key constraint ON ... SET NULL.
2333
#
2334
2335
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
2336
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
2337
INSERT INTO t1 VALUES (1);
2338
INSERT INTO t2 VALUES (1);
2339
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
2340
# mysqltest first does replace_regex, then replace_result
2341
--replace_regex /'[^']*test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
2342
# Embedded server doesn't chdir to data directory
2343
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
2344
--error 1025
2345
ALTER TABLE t2 MODIFY a INT NOT NULL;
2346
DELETE FROM t1;
2347
DROP TABLE t2,t1;
2348
2349
#
2350
# Bug #26835: table corruption after delete+insert
2351
#
2352
2353
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
2354
ENGINE=InnoDB;
2355
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
2356
DELETE FROM t1;
2357
INSERT INTO t1 VALUES ('DDD');
2358
SELECT * FROM t1;
2359
DROP TABLE t1;
2360
2361
#
2362
# Bug #23313 (AUTO_INCREMENT=# not reported back for InnoDB tables)
2363
# Bug #21404 (AUTO_INCREMENT value reset when Adding FKEY (or ALTER?))
2364
#
2365
2366
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
2367
AUTO_INCREMENT=42;
2368
2369
INSERT INTO t1 VALUES (0),(347),(0);
2370
SELECT * FROM t1;
2371
2372
SHOW CREATE TABLE t1;
2373
2374
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
2375
INSERT INTO t2 VALUES(42),(347),(348);
2376
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
2377
SHOW CREATE TABLE t1;
2378
2379
DROP TABLE t1,t2;
2380
2381
#
2382
# Bug #21101 (Prints wrong error message if max row size is too large)
2383
#
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2384
set innodb_strict_mode=on;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2385
--error 1118
2386
CREATE TABLE t1 (
2387
	c01 CHAR(255), c02 CHAR(255), c03 CHAR(255), c04 CHAR(255),
2388
	c05 CHAR(255), c06 CHAR(255), c07 CHAR(255), c08 CHAR(255),
2389
	c09 CHAR(255), c10 CHAR(255), c11 CHAR(255), c12 CHAR(255),
2390
	c13 CHAR(255), c14 CHAR(255), c15 CHAR(255), c16 CHAR(255),
2391
	c17 CHAR(255), c18 CHAR(255), c19 CHAR(255), c20 CHAR(255),
2392
	c21 CHAR(255), c22 CHAR(255), c23 CHAR(255), c24 CHAR(255),
2393
	c25 CHAR(255), c26 CHAR(255), c27 CHAR(255), c28 CHAR(255),
2394
	c29 CHAR(255), c30 CHAR(255), c31 CHAR(255), c32 CHAR(255)
2395
	) ENGINE = InnoDB;
2396
2397
#
2398
# Bug #31860 InnoDB assumes AUTOINC values can only be positive.
2399
#
2400
DROP TABLE IF EXISTS t1;
2401
CREATE TABLE t1(
2402
	id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY
2403
	) ENGINE=InnoDB;
2404
INSERT INTO t1 VALUES(-10);
2405
SELECT * FROM t1;
2406
#
2407
# NOTE: The server really needs to be restarted at this point
2408
# for the test to be useful.  
2409
#
2410
# Without the fix InnoDB would trip over an assertion here.
2411
INSERT INTO t1 VALUES(NULL);
2412
# The next value should be 1 and not -9 or a -ve number
2413
SELECT * FROM t1;
2414
DROP TABLE t1;
2415
2416
# 
2417
# Bug #21409 Incorrect result returned when in READ-COMMITTED with
2418
# query_cache ON
2419
#
2420
CONNECT (c1,localhost,root,,);
2421
CONNECT (c2,localhost,root,,);
2422
CONNECTION c1;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2423
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2424
SET TX_ISOLATION='read-committed';
2425
SET AUTOCOMMIT=0;
2426
DROP TABLE IF EXISTS t1, t2;
2427
CREATE TABLE t1 ( a int ) ENGINE=InnoDB;
2428
CREATE TABLE t2 LIKE t1;
2429
SELECT * FROM t2;
2430
CONNECTION c2;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2431
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2432
SET TX_ISOLATION='read-committed';
2433
SET AUTOCOMMIT=0;
2434
INSERT INTO t1 VALUES (1);
2435
COMMIT;
2436
CONNECTION c1;
2437
SELECT * FROM t1 WHERE a=1;
2438
DISCONNECT c1;
2439
DISCONNECT c2;
2440
CONNECT (c1,localhost,root,,);
2441
CONNECT (c2,localhost,root,,);
2442
CONNECTION c1;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2443
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2444
SET TX_ISOLATION='read-committed';
2445
SET AUTOCOMMIT=0;
2446
SELECT * FROM t2;
2447
CONNECTION c2;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
2448
SET binlog_format='MIXED';
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2449
SET TX_ISOLATION='read-committed';
2450
SET AUTOCOMMIT=0;
2451
INSERT INTO t1 VALUES (2);
2452
COMMIT;
2453
CONNECTION c1;
2454
# The result set below should be the same for both selects
2455
SELECT * FROM t1 WHERE a=2;
2456
SELECT * FROM t1 WHERE a=2;
2457
DROP TABLE t1;
2458
DROP TABLE t2;
2459
DISCONNECT c1;
2460
DISCONNECT c2;
2461
CONNECTION default;
2462
2463
#
2464
# Bug #29157 UPDATE, changed rows incorrect
2465
#
2466
create table t1 (i int, j int) engine=innodb;
2467
insert into t1 (i, j) values (1, 1), (2, 2);
2468
--enable_info
2469
update t1 set j = 2;
2470
--disable_info
2471
drop table t1;
2472
2473
#
2474
# Bug #32440 InnoDB free space info does not appear in SHOW TABLE STATUS or
2475
# I_S
2476
#
2477
create table t1 (id int) comment='this is a comment' engine=innodb;
2478
select table_comment, data_free > 0 as data_free_is_set
2479
  from information_schema.tables
2480
  where table_schema='test' and table_name = 't1';
2481
drop table t1;
2482
2483
#
2484
# Bug 34920 test
2485
#
2486
CONNECTION default;
2487
CREATE TABLE t1 (
2488
	c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
2489
	c2 VARCHAR(128) NOT NULL,
2490
	PRIMARY KEY(c1)
2491
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
2492
2493
CREATE TABLE t2 (
2494
	c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
2495
	c2 INT(10) UNSIGNED DEFAULT NULL,
2496
	PRIMARY KEY(c1)
2497
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
2498
2499
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
2500
ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
2501
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
2502
DROP TABLE t2;
2503
DROP TABLE t1;
2504
# End 34920 test
2505
#
2506
# Bug #29507 TRUNCATE shows to many rows effected
2507
#
2508
CONNECTION default;
2509
CREATE TABLE t1 (c1 int default NULL,
2510
		 c2 int default NULL
2511
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2512
2513
--enable_info
2514
TRUNCATE TABLE t1;
2515
2516
INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
2517
TRUNCATE TABLE t1;
2518
2519
--disable_info
2520
DROP TABLE t1;
2521
#
2522
# Bug#35537 Innodb doesn't increment handler_update and handler_delete.
2523
#
2524
-- disable_query_log
2525
-- disable_result_log
2526
2527
CONNECT (c1,localhost,root,,);
2528
2529
DROP TABLE IF EXISTS bug35537;
2530
CREATE TABLE bug35537 (
2531
  c1 int
2532
) ENGINE=InnoDB;
2533
2534
INSERT INTO bug35537 VALUES (1);
2535
2536
-- enable_result_log
2537
2538
SHOW SESSION STATUS LIKE 'Handler_update%';
2539
SHOW SESSION STATUS LIKE 'Handler_delete%';
2540
2541
UPDATE bug35537 SET c1 = 2 WHERE c1 = 1;
2542
DELETE FROM bug35537 WHERE c1 = 2;
2543
2544
SHOW SESSION STATUS LIKE 'Handler_update%';
2545
SHOW SESSION STATUS LIKE 'Handler_delete%';
2546
2547
DROP TABLE bug35537;
2548
2549
DISCONNECT c1;
2550
CONNECTION default;
2551
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
2552
SET GLOBAL innodb_thread_concurrency = @innodb_thread_concurrency_orig;
2553
2554
-- enable_query_log
2555
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2556
#######################################################################
2557
#                                                                     #
2558
# Please, DO NOT TOUCH this file as well as the innodb.result file.   #
2559
# These files are to be modified ONLY BY INNOBASE guys.               #
2560
#                                                                     #
2561
# Use innodb_mysql.[test|result] files instead.                       #
2562
#                                                                     #
2563
# If nevertheless you need to make some changes here, please, forward #
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
2564
# your commit message                                                 #
2565
# To: innodb_dev_ww@oracle.com                                        #
2566
# Cc: dev-innodb@mysql.com                                            #
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
2567
# (otherwise your changes may be erased).                             #
2568
#                                                                     #
2569
#######################################################################