~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/mysql-test/innodb.test

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

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