~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

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