~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/innodb.test

Cleanup around SAFEMALLOC

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
 
#set engine_condition_pushdown=0;
24
 
create table t1 (id int not null auto_increment, code int not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
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 NOT NULL auto_increment,
44
 
  parent_id int DEFAULT '0' NOT NULL,
45
 
  level int 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
 
alter table t1 ENGINE=innodb;
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 DEFAULT '0' NOT NULL,
79
 
  benutzer_id int 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
 
alter table t1 engine=innodb;
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
 
rollback to savepoint savept2;
160
 
insert into t1 values (8);
161
 
savepoint sv;
162
 
commit;
163
 
savepoint sv;
164
 
set autocommit=1;
165
 
# nop
166
 
rollback;
167
 
drop table t1;
168
 
 
169
 
#
170
 
# Test for commit and FLUSH TABLES WITH READ LOCK
171
 
#
172
 
 
173
 
create table t1 (n int not null primary key) engine=innodb;
174
 
start transaction;
175
 
insert into t1 values (4);
176
 
flush tables with read lock;
177
 
#
178
 
# Current code can't handle a read lock in middle of transaction
179
 
#--error 1223;
180
 
commit;
181
 
unlock tables;
182
 
commit;
183
 
select * from t1;
184
 
drop table t1;
185
 
 
186
 
#
187
 
# Testing transactions
188
 
#
189
 
 
190
 
create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
191
 
begin;
192
 
insert into t1 values(1,'hamdouni');
193
 
select id as afterbegin_id,nom as afterbegin_nom from t1;
194
 
rollback;
195
 
select id as afterrollback_id,nom as afterrollback_nom from t1;
196
 
set autocommit=0;
197
 
insert into t1 values(2,'mysql');
198
 
select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
199
 
rollback;
200
 
select id as afterrollback_id,nom as afterrollback_nom from t1;
201
 
set autocommit=1;
202
 
drop table t1;
203
 
 
204
 
#
205
 
# Simple not autocommit test
206
 
207
 
 
208
 
CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
209
 
insert into t1 values ('pippo', 12);
210
 
insert into t1 values ('pippo', 12); # Gives error
211
 
delete from t1;
212
 
delete from t1 where id = 'pippo';
213
 
select * from t1;
214
 
 
215
 
insert into t1 values ('pippo', 12);
216
 
set autocommit=0;
217
 
delete from t1;
218
 
rollback;
219
 
select * from t1;
220
 
delete from t1;
221
 
commit;
222
 
select * from t1;
223
 
drop table t1;
224
 
 
225
 
#
226
 
# Test of active transactions
227
 
#
228
 
 
229
 
create table t1 (a integer) engine=innodb;
230
 
start transaction;
231
 
rename table t1 to t2;
232
 
create table t1 (b integer) engine=innodb;
233
 
insert into t1 values (1);
234
 
rollback;
235
 
drop table t1;
236
 
rename table t2 to t1;
237
 
drop table t1;
238
 
set autocommit=1;
239
 
 
240
 
#
241
 
# The following simple tests failed at some point
242
 
#
243
 
 
244
 
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
245
 
INSERT INTO t1 VALUES (1, 'Jochen');
246
 
select * from t1;
247
 
drop table t1;
248
 
 
249
 
CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
250
 
set autocommit=0;
251
 
INSERT INTO t1  SET _userid='marc@anyware.co.uk';
252
 
COMMIT;
253
 
SELECT * FROM t1;
254
 
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
255
 
drop table t1;
256
 
set autocommit=1;
257
 
 
258
 
#
259
 
# Test when reading on part of unique key
260
 
#
261
 
CREATE TABLE t1 (
262
 
  user_id int DEFAULT '0' NOT NULL,
263
 
  name varchar(100),
264
 
  phone varchar(100),
265
 
  ref_email varchar(100) DEFAULT '' NOT NULL,
266
 
  detail varchar(200),
267
 
  PRIMARY KEY (user_id,ref_email)
268
 
)engine=innodb;
269
 
 
270
 
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');
271
 
select * from t1 where user_id=10292;
272
 
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
273
 
select * from t1 where user_id=10292;
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
 
drop table t1;
278
 
 
279
 
#
280
 
# Test that keys are created in right order
281
 
#
282
 
 
283
 
CREATE TABLE t1 (a int not null, b int not null,c int not null,
284
 
key(a),primary key(a,b), unique(c),key(a),unique(b));
285
 
--replace_column 7 #
286
 
show index from t1;
287
 
drop table t1;
288
 
 
289
 
#
290
 
# Test of ALTER TABLE and innodb tables
291
 
#
292
 
 
293
 
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
294
 
alter table t1 engine=innodb;
295
 
insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
296
 
select * from t1;
297
 
update t1 set col2='7' where col1='4';
298
 
select * from t1;
299
 
alter table t1 add co3 int not null;
300
 
select * from t1;
301
 
update t1 set col2='9' where col1='2';
302
 
select * from t1;
303
 
drop table t1;
304
 
 
305
 
#
306
 
# INSERT INTO innodb tables
307
 
#
308
 
 
309
 
create table t1 (a int not null , b int, primary key (a)) engine = innodb;
310
 
create TEMPORARY table t2 (a int not null , b int, primary key (a)) engine = myisam;
311
 
insert into t1 VALUES (1,3) , (2,3), (3,3);
312
 
select * from t1;
313
 
insert into t2 select * from t1;
314
 
select * from t2;
315
 
delete from t1 where b = 3;
316
 
select * from t1;
317
 
insert into t1 select * from t2;
318
 
select * from t1;
319
 
select * from t2;
320
 
drop table t1,t2;
321
 
 
322
 
#
323
 
# ORDER BY on not primary key
324
 
#
325
 
 
326
 
CREATE TABLE t1 (
327
 
  user_name varchar(12),
328
 
  password text,
329
 
  subscribed char(1),
330
 
  user_id int DEFAULT '0' NOT NULL,
331
 
  quota bigint,
332
 
  weight double,
333
 
  access_date date,
334
 
  approved datetime,
335
 
  dummy_primary_key int NOT NULL auto_increment,
336
 
  PRIMARY KEY (dummy_primary_key)
337
 
) ENGINE=innodb;
338
 
INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','2000-09-07 23:06:59',1);
339
 
INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','2000-09-07 23:06:59',2);
340
 
INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','2000-09-07 23:06:59',3);
341
 
INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','2000-09-07 23:06:59',4);
342
 
INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','2000-09-07 23:06:59',5);
343
 
select  user_name, password , subscribed, user_id, quota, weight, access_date, approved, dummy_primary_key from t1 order by user_name;
344
 
drop table t1;
345
 
 
346
 
#
347
 
# Testing of tables without primary keys
348
 
#
349
 
 
350
 
CREATE TABLE t1 (
351
 
  id int NOT NULL auto_increment,
352
 
  parent_id int DEFAULT '0' NOT NULL,
353
 
  level int DEFAULT '0' NOT NULL,
354
 
  KEY (id),
355
 
  KEY parent_id (parent_id),
356
 
  KEY level (level)
357
 
) engine=innodb;
358
 
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);
359
 
INSERT INTO t1 values (179,5,2);
360
 
update t1 set parent_id=parent_id+100;
361
 
select * from t1 where parent_id=102;
362
 
update t1 set id=id+1000;
363
 
update t1 set id=1024 where id=1009; 
364
 
select * from t1;
365
 
update ignore t1 set id=id+1; # This will change all rows
366
 
select * from t1;
367
 
update ignore t1 set id=1023 where id=1010;
368
 
select * from t1 where parent_id=102;
369
 
--replace_column 9 #
370
 
explain select level from t1 where level=1;
371
 
select level,id from t1 where level=1;
372
 
select level,id,parent_id from t1 where level=1;
373
 
select level,id from t1 where level=1 order by id;
374
 
delete from t1 where level=1;
375
 
select * from t1;
376
 
drop table t1;
377
 
 
378
 
#
379
 
# Test of index only reads
380
 
#
381
 
CREATE TABLE t1 (
382
 
   sca_code char(6) NOT NULL,
383
 
   cat_code char(6) NOT NULL,
384
 
   sca_desc varchar(50),
385
 
   lan_code char(2) NOT NULL,
386
 
   sca_pic varchar(100),
387
 
   sca_sdesc varchar(50),
388
 
   sca_sch_desc varchar(16),
389
 
   PRIMARY KEY (sca_code, cat_code, lan_code),
390
 
   INDEX sca_pic (sca_pic)
391
 
) engine = innodb ;
392
 
 
393
 
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');
394
 
select count(*) from t1 where sca_code = 'PD';
395
 
select count(*) from t1 where sca_code <= 'PD';
396
 
select count(*) from t1 where sca_pic is null;
397
 
alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
398
 
select count(*) from t1 where sca_code='PD' and sca_pic is null;
399
 
select count(*) from t1 where cat_code='E';
400
 
alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
401
 
select count(*) from t1 where sca_code='PD' and sca_pic is null;
402
 
select count(*) from t1 where sca_pic >= 'n';
403
 
select sca_pic from t1 where sca_pic is null;
404
 
update t1 set sca_pic="test" where sca_pic is null;
405
 
delete from t1 where sca_code='pd';
406
 
drop table t1;
407
 
 
408
 
#
409
 
# Test of opening table twice and timestamps
410
 
#
411
 
set @a:=now();
412
 
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
413
 
insert into t1 (a) values(1),(2),(3);
414
 
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
415
 
select a from t1 natural join t1 as t2 where b >= @a order by a;
416
 
update t1 set a=5 where a=1;
417
 
select a from t1;
418
 
drop table t1;
419
 
 
420
 
#
421
 
# Test with variable length primary key
422
 
#
423
 
create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
424
 
insert into t1 values("hello",1),("world",2);
425
 
select * from t1 order by b desc;
426
 
alter table t1 engine=innodb;
427
 
--replace_column 7 #
428
 
show keys from t1;
429
 
drop table t1;
430
 
 
431
 
#
432
 
# Test of create index with NULL columns
433
 
#
434
 
create table t1 (i int, j int ) ENGINE=innodb;
435
 
insert into t1 values (1,2);
436
 
select * from t1 where i=1 and j=2;
437
 
create index ax1 on t1 (i,j);
438
 
select * from t1 where i=1 and j=2;
439
 
drop table t1;
440
 
 
441
 
#
442
 
# Test min-max optimization
443
 
#
444
 
 
445
 
CREATE TABLE t1 (
446
 
  a int NOT NULL,
447
 
  b int NOT NULL,
448
 
  UNIQUE (a, b)
449
 
) ENGINE = innodb;
450
 
 
451
 
INSERT INTO t1 VALUES (1, 1);
452
 
SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
453
 
drop table t1;
454
 
 
455
 
#
456
 
# Test INSERT DELAYED
457
 
#
458
 
 
459
 
CREATE TABLE t1 (a int NOT NULL) engine=innodb;
460
 
# Can't test this in 3.23
461
 
# INSERT DELAYED INTO t1 VALUES (1);
462
 
INSERT INTO t1 VALUES (1);
463
 
SELECT * FROM t1;
464
 
DROP TABLE t1;
465
 
 
466
 
 
467
 
#
468
 
# Crash when using many tables (Test case by Jeremy D Zawodny)
469
 
#
470
 
 
471
 
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;
472
 
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);
473
 
--replace_column 9 #
474
 
explain select * from t1 where a > 0 and a < 50;
475
 
drop table t1;
476
 
 
477
 
#
478
 
# Test prefix key
479
 
#
480
 
create table t1 (a char(20), unique (a(5))) engine=innodb;
481
 
drop table t1;
482
 
create table t1 (a char(20), index (a(5))) engine=innodb;
483
 
show create table t1;
484
 
drop table t1;
485
 
 
486
 
#
487
 
# Test using temporary table and auto_increment
488
 
#
489
 
 
490
 
create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
491
 
insert into t1 values (NULL),(NULL),(NULL);
492
 
delete from t1 where a=3;
493
 
insert into t1 values (NULL);
494
 
select * from t1;
495
 
alter table t1 add b int;
496
 
select * from t1;
497
 
drop table t1;
498
 
 
499
 
#Slashdot bug
500
 
## Heikki had nevered considered the possibility of a second key that could
501
 
## be used as a primary key for replace. This is from the table that
502
 
## generates topics and "vars"  -Brian
503
 
create table t1
504
 
 (
505
 
  id int auto_increment primary key,
506
 
  name varchar(32) not null,
507
 
  value text not null,
508
 
  uid int not null,
509
 
  unique key(name,uid)
510
 
 ) engine=innodb;
511
 
insert into t1 values (1,'one','one value',101),
512
 
 (2,'two','two value',102),(3,'three','three value',103);
513
 
replace into t1 (value,name,uid) values ('other value','two',102);
514
 
delete from t1 where uid=102;
515
 
replace into t1 (value,name,uid) values ('other value','two',102);
516
 
replace into t1 (value,name,uid) values ('other value','two',102);
517
 
select * from t1;
518
 
drop table t1;
519
 
 
520
 
#
521
 
# Test DROP DATABASE
522
 
#
523
 
 
524
 
create database mysqltest;
525
 
create table mysqltest.t1 (a int not null) engine= innodb;
526
 
insert into mysqltest.t1 values(1);
527
 
create TEMPORARY table mysqltest.t2 (a int not null) engine= myisam;
528
 
insert into mysqltest.t2 values(1);
529
 
create temporary table mysqltest.t3 (a int not null) engine= MEMORY;
530
 
insert into mysqltest.t3 values(1);
531
 
commit;
532
 
drop database mysqltest;
533
 
# Don't check error message
534
 
--error 1049
535
 
show tables from mysqltest;
536
 
 
537
 
#
538
 
# Test truncate table with and without auto_commit
539
 
#
540
 
 
541
 
set autocommit=0;
542
 
create table t1 (a int not null) engine= innodb;
543
 
insert into t1 values(1),(2);
544
 
truncate table t1;
545
 
commit;
546
 
truncate table t1;
547
 
truncate table t1;
548
 
select * from t1;
549
 
insert into t1 values(1),(2);
550
 
delete from t1;
551
 
select * from t1;
552
 
commit;
553
 
drop table t1;
554
 
set autocommit=1;
555
 
 
556
 
create table t1 (a int not null) engine= innodb;
557
 
insert into t1 values(1),(2);
558
 
truncate table t1;
559
 
insert into t1 values(1),(2);
560
 
select * from t1;
561
 
truncate table t1;
562
 
insert into t1 values(1),(2);
563
 
delete from t1;
564
 
select * from t1;
565
 
drop table t1;
566
 
 
567
 
#
568
 
# Test of how ORDER BY works when doing it on the whole table
569
 
#
570
 
 
571
 
create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
572
 
insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
573
 
--replace_column 9 #
574
 
explain select * from t1 order by a;
575
 
--replace_column 9 #
576
 
explain select * from t1 order by b;
577
 
--replace_column 9 #
578
 
explain select * from t1 order by c;
579
 
--replace_column 9 #
580
 
explain select a from t1 order by a;
581
 
--replace_column 9 #
582
 
explain select b from t1 order by b;
583
 
--replace_column 9 #
584
 
explain select a,b from t1 order by b;
585
 
--replace_column 9 #
586
 
explain select a,b from t1;
587
 
--replace_column 9 #
588
 
explain select a,b,c from t1;
589
 
drop table t1;
590
 
 
591
 
#
592
 
# Check describe
593
 
#
594
 
 
595
 
create table t1 (t int not null default 1, key (t)) engine=innodb;
596
 
desc t1;
597
 
drop table t1;
598
 
 
599
 
#
600
 
# A simple test with some isolation levels
601
 
# TODO: Make this into a test using replication to really test how
602
 
# this works.
603
 
#
604
 
 
605
 
create table t1 (id int not null auto_increment, code int not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
606
 
 
607
 
BEGIN;
608
 
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
609
 
SELECT @@tx_isolation,@@global.tx_isolation;
610
 
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
611
 
select id, code, name from t1 order by id;
612
 
COMMIT;
613
 
 
614
 
BEGIN;
615
 
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
616
 
insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
617
 
select id, code, name from t1 order by id;
618
 
COMMIT;
619
 
 
620
 
BEGIN;
621
 
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
622
 
insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
623
 
select id, code, name from t1 order by id;
624
 
COMMIT;
625
 
DROP TABLE t1;
626
 
 
627
 
#
628
 
# Testing of IFNULL
629
 
#
630
 
create table t1 (a int, b int) engine=innodb;
631
 
insert into t1 values(20,null);
632
 
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
633
 
t2.b=t3.a;
634
 
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
635
 
t2.b=t3.a order by 1;
636
 
insert into t1 values(10,null);
637
 
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
638
 
t2.b=t3.a order by 1;
639
 
drop table t1;
640
 
 
641
 
#
642
 
# Test of read_through not existing const_table
643
 
#
644
 
 
645
 
create TEMPORARY table t1 (a varchar(10) not null) engine=myisam;
646
 
create table t2 (b varchar(10) not null unique) engine=innodb;
647
 
select t1.a from t1,t2 where t1.a=t2.b;
648
 
drop table t1,t2;
649
 
create table t1 (a int not null, b int, primary key (a)) engine = innodb;
650
 
create table t2 (a int not null, b int, primary key (a)) engine = innodb;
651
 
insert into t1 values (10, 20);
652
 
insert into t2 values (10, 20);
653
 
drop table t1,t2;
654
 
 
655
 
#
656
 
# Test of range_optimizer
657
 
#
658
 
 
659
 
set autocommit=0;
660
 
 
661
 
CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
662
 
 
663
 
CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
664
 
 
665
 
CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
666
 
 
667
 
INSERT INTO t3 VALUES("my-test-1", "my-test-2");
668
 
COMMIT;
669
 
 
670
 
INSERT INTO t1 VALUES("this-key", "will disappear");
671
 
INSERT INTO t2 VALUES("this-key", "will also disappear");
672
 
DELETE FROM t3 WHERE id1="my-test-1";
673
 
 
674
 
SELECT * FROM t1;
675
 
SELECT * FROM t2;
676
 
SELECT * FROM t3;
677
 
ROLLBACK;
678
 
 
679
 
SELECT * FROM t1;
680
 
SELECT * FROM t2;
681
 
SELECT * FROM t3;
682
 
SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
683
 
COMMIT;
684
 
set autocommit=1;
685
 
DROP TABLE t1,t2,t3;
686
 
 
687
 
#
688
 
# Check update with conflicting key
689
 
#
690
 
 
691
 
CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
692
 
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
693
 
# We need the a < 1000 test here to quard against the halloween problems
694
 
UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
695
 
SELECT * from t1;
696
 
drop table t1;
697
 
 
698
 
#
699
 
# Test that MySQL priorities clustered indexes
700
 
#
701
 
create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
702
 
create table t2 (a int not null auto_increment primary key, b int);
703
 
insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
704
 
insert into t2 (a) select b from t1;
705
 
insert into t1 (b) select b from t2;
706
 
insert into t2 (a) select b from t1;
707
 
insert into t1 (a) select b from t2;
708
 
insert into t2 (a) select b from t1;
709
 
insert into t1 (a) select b from t2;
710
 
insert into t2 (a) select b from t1;
711
 
insert into t1 (a) select b from t2;
712
 
insert into t2 (a) select b from t1;
713
 
insert into t1 (a) select b from t2;
714
 
select count(*) from t1;
715
 
--replace_column 9 #
716
 
explain select * from t1 where c between 1 and 2500;
717
 
update t1 set c=a;
718
 
--replace_column 9 #
719
 
explain select * from t1 where c between 1 and 2500;
720
 
drop table t1,t2;
721
 
 
722
 
#
723
 
# Test of UPDATE ... ORDER BY
724
 
#
725
 
 
726
 
create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
727
 
 
728
 
insert into t1 (id) values (null),(null),(null),(null),(null);
729
 
update t1 set fk=69 where fk is null order by id limit 1;
730
 
SELECT * from t1;
731
 
drop table t1;
732
 
 
733
 
create table t1 (a int not null, b int not null, key (a));
734
 
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);
735
 
SET @tmp=0;
736
 
update t1 set b=(@tmp:=@tmp+1) order by a;
737
 
update t1 set b=99 where a=1 order by b asc limit 1;
738
 
update t1 set b=100 where a=1 order by b desc limit 2;
739
 
update t1 set a=a+10+b where a=1 order by b;
740
 
select * from t1 order by a,b;
741
 
drop table t1;
742
 
 
743
 
#
744
 
# test autoincrement with TRUNCATE
745
 
#
746
 
 
747
 
SET AUTOCOMMIT=1;
748
 
create table t1 (a integer auto_increment primary key) engine=innodb;
749
 
insert into t1 (a) values (NULL),(NULL);
750
 
truncate table t1;
751
 
insert into t1 (a) values (NULL),(NULL);
752
 
SELECT * from t1;
753
 
drop table t1;
754
 
 
755
 
#
756
 
# Test dictionary handling with spaceand quoting
757
 
#
758
 
 
759
 
CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
760
 
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;
761
 
#show create table t2;
762
 
drop table t2,t1;
763
 
 
764
 
#
765
 
# test for recursion depth limit
766
 
#
767
 
create table t1(
768
 
        id int primary key,
769
 
        pid int,
770
 
        index(pid),
771
 
        foreign key(pid) references t1(id) on delete cascade) engine=innodb;
772
 
insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
773
 
        (8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
774
 
delete from t1 where id=0;
775
 
delete from t1 where id=15;
776
 
delete from t1 where id=0;
777
 
 
778
 
drop table t1;
779
 
 
780
 
#
781
 
# Test timestamps
782
 
#
783
 
 
784
 
CREATE TABLE t1 (col1 int) ENGINE=InnoDB;
785
 
CREATE TABLE t2 (col1 int, stamp TIMESTAMP,INDEX stamp_idx (stamp)) ENGINE=InnoDB;
786
 
insert into t1 values (1),(2),(3);
787
 
# Note that timestamp 3 is wrong
788
 
insert into t2 values (1, 20020204110000),(2, 20020204110001),(4,20020204110002 ),(5,20020204110003);
789
 
SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
790
 
'20020204120000' GROUP BY col1;
791
 
drop table t1,t2;
792
 
 
793
 
#
794
 
# Test by Francois MASUREL
795
 
#
796
 
 
797
 
CREATE TABLE t1 (
798
 
  `id` int NOT NULL auto_increment,
799
 
  `id_object` int default '0',
800
 
  `id_version` int NOT NULL default '1',
801
 
  `label` varchar(100) NOT NULL default '',
802
 
  `description` text,
803
 
  PRIMARY KEY  (`id`),
804
 
  KEY `id_object` (`id_object`),
805
 
  KEY `id_version` (`id_version`)
806
 
) ENGINE=InnoDB;
807
 
 
808
 
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);
809
 
 
810
 
CREATE TABLE t2 (
811
 
  `id` int NOT NULL auto_increment,
812
 
  `id_version` int NOT NULL default '1',
813
 
  PRIMARY KEY  (`id`),
814
 
  KEY `id_version` (`id_version`)
815
 
) ENGINE=InnoDB;
816
 
 
817
 
INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
818
 
 
819
 
SELECT t2.id, t1.`label` FROM t2 INNER JOIN
820
 
(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl 
821
 
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
822
 
drop table t1,t2;
823
 
 
824
 
create TEMPORARY table t1 (a int, b varchar(200), c text not null)  engine=myisam;
825
 
create table t2 (a int, b varchar(200), c text not null) engine=innodb;
826
 
create table t3 (a int, b varchar(200), c text not null) engine=innodb;
827
 
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
828
 
insert t2 select * from t1;
829
 
insert t3 select * from t1;
830
 
checksum table t1, t2, t3, t4;
831
 
checksum table t1, t2, t3, t4;
832
 
checksum table t1, t2, t3, t4;
833
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
834
 
drop table t1,t2,t3;
835
 
 
836
 
#
837
 
# Test problem with refering to different fields in same table in UNION
838
 
# (Bug #2552)
839
 
#
840
 
create table t1 (id int,  name char(10) not null,  name2 char(10) not null) engine=innodb;
841
 
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
842
 
select trim(name2) from t1  union all  select trim(name) from t1 union all select trim(id) from t1;
843
 
drop table t1;
844
 
 
845
 
#
846
 
# Bug2160
847
 
#
848
 
create table t1 (a int) engine=innodb;
849
 
create table t2 like t1;
850
 
drop table t1,t2;
851
 
 
852
 
#
853
 
# Test of automaticly created foreign keys
854
 
#
855
 
 
856
 
create table t1 (id int not null, id2 int not null, unique (id,id2)) engine=innodb;
857
 
create table t2 (id int not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
858
 
show create table t1;
859
 
show create table t2;
860
 
create index id on t2 (id);
861
 
show create table t2;
862
 
create index id2 on t2 (id);
863
 
show create table t2;
864
 
drop index id2 on t2;
865
 
--error 1025,1025
866
 
drop index id on t2;
867
 
show create table t2;
868
 
drop table t2;
869
 
 
870
 
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;
871
 
show create table t2;
872
 
create unique index id on t2 (id,id2);
873
 
show create table t2;
874
 
drop table t2;
875
 
 
876
 
# Check foreign key columns created in different order than key columns
877
 
create table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
878
 
show create table t2;
879
 
drop table t2;
880
 
 
881
 
create table t2 (id int not null, id2 int not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;
882
 
show create table t2;
883
 
drop table t2;
884
 
 
885
 
create table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
886
 
show create table t2;
887
 
drop table t2;
888
 
 
889
 
create table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
890
 
show create table t2;
891
 
drop table t2;
892
 
 
893
 
create table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
894
 
show create table t2;
895
 
alter table t2 add index id_test (id), add index id_test2 (id,id2);
896
 
show create table t2;
897
 
drop table t2;
898
 
 
899
 
# Test error handling
900
 
 
901
 
# Embedded server doesn't chdir to data directory
902
 
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
903
 
--error ER_WRONG_FK_DEF
904
 
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
905
 
 
906
 
# bug#3749
907
 
 
908
 
create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
909
 
show create table t2;
910
 
drop table t2;
911
 
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;
912
 
show create table t2;
913
 
drop table t2, t1;
914
 
 
915
 
 
916
 
#
917
 
# Bug #6126: Duplicate columns in keys gives misleading error message
918
 
#
919
 
--error 1060
920
 
create table t1 (c char(10), index (c,c)) engine=innodb;
921
 
--error 1060
922
 
create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
923
 
--error 1060
924
 
create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
925
 
--error 1060
926
 
create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
927
 
create table t1 (c1 char(10), c2 char(10)) engine=innodb;
928
 
--error 1060
929
 
alter table t1 add key (c1,c1);
930
 
--error 1060
931
 
alter table t1 add key (c2,c1,c1);
932
 
--error 1060
933
 
alter table t1 add key (c1,c2,c1);
934
 
--error 1060
935
 
alter table t1 add key (c1,c1,c2);
936
 
drop table t1;
937
 
 
938
 
#
939
 
# Bug #4082: integer truncation
940
 
#
941
 
 
942
 
create table t1(a int, b int) engine=innodb;
943
 
insert into t1 values ('1111', '3333');
944
 
select distinct concat(a, b) from t1;
945
 
drop table t1;
946
 
 
947
 
#
948
 
# check null values #1
949
 
#
950
 
 
951
 
--disable_warnings
952
 
CREATE TABLE t1 (a_id int NOT NULL default '0', PRIMARY KEY  (a_id)) ENGINE=InnoDB;
953
 
INSERT INTO t1 VALUES (1),(2),(3);
954
 
CREATE TABLE t2 (b_id int NOT NULL default '0',b_a int NOT NULL default '0', PRIMARY KEY  (b_id), KEY  (b_a), 
955
 
                CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB;
956
 
--enable_warnings
957
 
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
958
 
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;
959
 
DROP TABLE t2;
960
 
DROP TABLE t1;
961
 
 
962
 
#
963
 
# Bug#11816 - Truncate table doesn't work with temporary innodb tables
964
 
# This is not an innodb bug, but we test it using innodb.
965
 
#
966
 
create temporary table t1 (a int) engine=innodb;
967
 
insert into t1 values (4711);
968
 
truncate t1;
969
 
insert into t1 values (42);
970
 
select * from t1;
971
 
drop table t1;
972
 
# Show that it works with permanent tables too.
973
 
create table t1 (a int) engine=innodb;
974
 
insert into t1 values (4711);
975
 
truncate t1;
976
 
insert into t1 values (42);
977
 
select * from t1;
978
 
drop table t1;
979
 
 
980
 
#
981
 
# Bug #13025  Server crash during filesort      
982
 
#
983
 
 
984
 
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;
985
 
insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
986
 
select * from t1 order by a,b,c,d;
987
 
explain select * from t1 order by a,b,c,d;
988
 
drop table t1;
989
 
 
990
 
#
991
 
# BUG#11039,#13218 Wrong key length in min()
992
 
#
993
 
 
994
 
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
995
 
insert into t1 values ('8', '6'), ('4', '7');
996
 
select min(a) from t1;
997
 
select min(b) from t1 where a='8';
998
 
drop table t1;
999
 
 
1000
 
# End of 4.1 tests
1001
 
 
1002
 
#
1003
 
# range optimizer problem
1004
 
#
1005
 
 
1006
 
create table t1 (x bigint not null primary key) engine=innodb;
1007
 
insert into t1(x) values (0x0ffffffffffffff0),(0x0ffffffffffffff1);
1008
 
select * from t1;
1009
 
select count(*) from t1 where x>0;
1010
 
select count(*) from t1 where x=0;
1011
 
select count(*) from t1 where x<0;
1012
 
select count(*) from t1 where x < -16;
1013
 
select count(*) from t1 where x = -16;
1014
 
explain select count(*) from t1 where x > -16;
1015
 
select count(*) from t1 where x > -16;
1016
 
select * from t1 where x > -16;
1017
 
select count(*) from t1 where x = 1152921504606846961;
1018
 
drop table t1;
1019
 
 
1020
 
 
1021
 
## Not deterministic.
1022
 
# Test for testable InnoDB status variables. This test
1023
 
# uses previous ones(pages_created, rows_deleted, ...).
1024
 
--replace_column 2 #
1025
 
show status like "Innodb_buffer_pool_pages_total";
1026
 
--replace_column 2 #
1027
 
show status like "Innodb_page_size";
1028
 
--replace_column 2 #
1029
 
show status like "Innodb_rows_deleted";
1030
 
--replace_column 2 #
1031
 
show status like "Innodb_rows_inserted";
1032
 
--replace_column 2 #
1033
 
show status like "Innodb_rows_updated";
1034
 
 
1035
 
## Test for row locks InnoDB status variables.
1036
 
--replace_column 2 #
1037
 
show status like "Innodb_row_lock_waits";
1038
 
--replace_column 2 #
1039
 
show status like "Innodb_row_lock_current_waits";
1040
 
--replace_column 2 #
1041
 
show status like "Innodb_row_lock_time";
1042
 
--replace_column 2 #
1043
 
show status like "Innodb_row_lock_time_max";
1044
 
--replace_column 2 #
1045
 
show status like "Innodb_row_lock_time_avg";
1046
 
 
1047
 
# Test for innodb_sync_spin_loops variable
1048
 
show variables like "innodb_sync_spin_loops";
1049
 
set global innodb_sync_spin_loops=1000;
1050
 
show variables like "innodb_sync_spin_loops";
1051
 
set global innodb_sync_spin_loops=0;
1052
 
show variables like "innodb_sync_spin_loops";
1053
 
set global innodb_sync_spin_loops=20;
1054
 
show variables like "innodb_sync_spin_loops";
1055
 
 
1056
 
# Test for innodb_thread_concurrency variable
1057
 
show variables like "innodb_thread_concurrency";
1058
 
set global innodb_thread_concurrency=1001;
1059
 
show variables like "innodb_thread_concurrency";
1060
 
set global innodb_thread_concurrency=0;
1061
 
show variables like "innodb_thread_concurrency";
1062
 
set global innodb_thread_concurrency=16;
1063
 
show variables like "innodb_thread_concurrency";
1064
 
 
1065
 
# Test for innodb_concurrency_tickets variable
1066
 
show variables like "innodb_concurrency_tickets";
1067
 
set global innodb_concurrency_tickets=1000;
1068
 
show variables like "innodb_concurrency_tickets";
1069
 
set global innodb_concurrency_tickets=0;
1070
 
show variables like "innodb_concurrency_tickets";
1071
 
set global innodb_concurrency_tickets=500;
1072
 
show variables like "innodb_concurrency_tickets";
1073
 
 
1074
 
# Test for innodb_thread_sleep_delay variable
1075
 
show variables like "innodb_thread_sleep_delay";
1076
 
set global innodb_thread_sleep_delay=100000;
1077
 
show variables like "innodb_thread_sleep_delay";
1078
 
set global innodb_thread_sleep_delay=0;
1079
 
show variables like "innodb_thread_sleep_delay";
1080
 
set global innodb_thread_sleep_delay=10000;
1081
 
show variables like "innodb_thread_sleep_delay";
1082
 
 
1083
 
#
1084
 
# Test varchar
1085
 
#
1086
 
 
1087
 
let $default=`select @@storage_engine`;
1088
 
set storage_engine=INNODB;
1089
 
source include/varchar.inc;
1090
 
 
1091
 
#
1092
 
# Some errors/warnings on create
1093
 
#
1094
 
 
1095
 
# Embedded server doesn't chdir to data directory
1096
 
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1097
 
create table t1 (v varchar(16383), key(v));
1098
 
drop table t1;
1099
 
create table t1 (v varchar(16383));
1100
 
show create table t1;
1101
 
drop table t1;
1102
 
create table t1 (v varchar(16383));
1103
 
show create table t1;
1104
 
drop table t1;
1105
 
 
1106
 
eval set storage_engine=$default;
1107
 
 
1108
 
# InnoDB specific varchar tests
1109
 
create table t1 (v varchar(16383)) engine=innodb;
1110
 
drop table t1;
1111
 
 
1112
 
#
1113
 
# BUG#11039 Wrong key length in min()
1114
 
#
1115
 
 
1116
 
create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
1117
 
insert into t1 values ('8', '6'), ('4', '7');
1118
 
select min(a) from t1;
1119
 
select min(b) from t1 where a='8';
1120
 
drop table t1;
1121
 
 
1122
 
#
1123
 
# Bug #11080 & #11005  Multi-row REPLACE fails on a duplicate key error
1124
 
#
1125
 
 
1126
 
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY  (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
1127
 
insert into t1 (b) values (1);
1128
 
replace into t1 (b) values (2), (1), (3);
1129
 
select * from t1;
1130
 
truncate table t1;
1131
 
insert into t1 (b) values (1);
1132
 
replace into t1 (b) values (2);
1133
 
replace into t1 (b) values (1);
1134
 
replace into t1 (b) values (3);
1135
 
select * from t1;
1136
 
drop table t1;
1137
 
 
1138
 
create table t1 (rowid int not null auto_increment, val int not null,primary
1139
 
key (rowid), unique(val)) engine=innodb;
1140
 
replace into t1 (val) values ('1'),('2');
1141
 
replace into t1 (val) values ('1'),('2');
1142
 
--error ER_DUP_ENTRY
1143
 
insert into t1 (val) values ('1'),('2');
1144
 
select * from t1;
1145
 
drop table t1;
1146
 
 
1147
 
#
1148
 
# Test that update does not change internal auto-increment value
1149
 
#
1150
 
 
1151
 
create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
1152
 
insert into t1 (val) values (1);
1153
 
update t1 set a=2 where a=1;
1154
 
# We should get the following error because InnoDB does not update the counter
1155
 
--error ER_DUP_ENTRY
1156
 
insert into t1 (val) values (1);
1157
 
select * from t1;
1158
 
drop table t1;
1159
 
#
1160
 
# Bug #10465
1161
 
#
1162
 
 
1163
 
--disable_warnings
1164
 
CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
1165
 
--enable_warnings
1166
 
INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
1167
 
SELECT GRADE  FROM t1 WHERE GRADE > 160 AND GRADE < 300;
1168
 
SELECT GRADE  FROM t1 WHERE GRADE= 151;
1169
 
DROP TABLE t1;
1170
 
 
1171
 
#
1172
 
# Test that the slow TRUNCATE implementation resets autoincrement columns
1173
 
# (bug #11946)
1174
 
#
1175
 
 
1176
 
CREATE TABLE t1 (
1177
 
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
1178
 
) ENGINE=InnoDB;
1179
 
 
1180
 
CREATE TABLE t2 (
1181
 
id INTEGER NOT NULL,
1182
 
FOREIGN KEY (id) REFERENCES t1 (id)
1183
 
) ENGINE=InnoDB;
1184
 
 
1185
 
INSERT INTO t1 (id) VALUES (NULL);
1186
 
SELECT * FROM t1;
1187
 
TRUNCATE t1;
1188
 
INSERT INTO t1 (id) VALUES (NULL);
1189
 
SELECT * FROM t1;
1190
 
 
1191
 
# continued from above; test that doing a slow TRUNCATE on a table with 0
1192
 
# rows resets autoincrement columns
1193
 
DELETE FROM t1;
1194
 
TRUNCATE t1;
1195
 
INSERT INTO t1 (id) VALUES (NULL);
1196
 
SELECT * FROM t1;
1197
 
DROP TABLE t2, t1;
1198
 
 
1199
 
# Test that foreign keys in temporary tables are not accepted (bug #12084)
1200
 
CREATE TABLE t1
1201
 
(
1202
 
 id INT PRIMARY KEY
1203
 
) ENGINE=InnoDB;
1204
 
 
1205
 
--error 1005,1005
1206
 
CREATE TEMPORARY TABLE t2
1207
 
(
1208
 
 id INT NOT NULL PRIMARY KEY,
1209
 
 b INT,
1210
 
 FOREIGN KEY (b) REFERENCES test.t1(id)
1211
 
) ENGINE=InnoDB;
1212
 
DROP TABLE t1;
1213
 
 
1214
 
#
1215
 
# Test that index column max sizes are honored (bug #13315)
1216
 
#
1217
 
 
1218
 
# prefix index
1219
 
create table t1 (col1 varchar(2000), index (col1(767)))
1220
 
 engine = innodb;
1221
 
 
1222
 
# normal indexes
1223
 
create table t2 (col1 char(255), index (col1))
1224
 
 engine = innodb;
1225
 
create table t4 (col1 varchar(767), index (col1))
1226
 
 engine = innodb;
1227
 
create table t5 (col1 varchar(190) primary key)
1228
 
 engine = innodb;
1229
 
create table t6 (col1 varbinary(254) primary key)
1230
 
 engine = innodb;
1231
 
create table t7 (col1 text, index(col1(767)))
1232
 
 engine = innodb;
1233
 
create table t8 (col1 blob, index(col1(767)))
1234
 
 engine = innodb;
1235
 
 
1236
 
# multi-column indexes are allowed to be longer
1237
 
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
1238
 
 engine = innodb;
1239
 
 
1240
 
show create table t9;
1241
 
 
1242
 
drop table t1, t2, t4, t5, t6, t7, t8, t9;
1243
 
 
1244
 
# these should have their index length trimmed
1245
 
create table t1 (col1 varchar(768), index(col1))
1246
 
 engine = innodb;
1247
 
create table t2 (col1 varbinary(768), index(col1))
1248
 
 engine = innodb;
1249
 
create table t3 (col1 text, index(col1(768)))
1250
 
 engine = innodb;
1251
 
create table t4 (col1 blob, index(col1(768)))
1252
 
 engine = innodb;
1253
 
 
1254
 
show create table t1;
1255
 
 
1256
 
drop table t1, t2, t3, t4;
1257
 
 
1258
 
# these should be refused
1259
 
--error 1071
1260
 
create table t1 (col1 varchar(768) primary key)
1261
 
 engine = innodb;
1262
 
--error 1071
1263
 
create table t2 (col1 varbinary(768) primary key)
1264
 
 engine = innodb;
1265
 
--error 1071
1266
 
create table t3 (col1 text, primary key(col1(768)))
1267
 
 engine = innodb;
1268
 
--error 1071
1269
 
create table t4 (col1 blob, primary key(col1(768)))
1270
 
 engine = innodb;
1271
 
 
1272
 
#
1273
 
# Test improved foreign key error messages (bug #3443)
1274
 
#
1275
 
 
1276
 
CREATE TABLE t1
1277
 
(
1278
 
 id INT PRIMARY KEY
1279
 
) ENGINE=InnoDB;
1280
 
 
1281
 
CREATE TABLE t2
1282
 
(
1283
 
 v INT,
1284
 
 CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
1285
 
) ENGINE=InnoDB;
1286
 
 
1287
 
--error 1452
1288
 
INSERT INTO t2 VALUES(2);
1289
 
 
1290
 
INSERT INTO t1 VALUES(1);
1291
 
INSERT INTO t2 VALUES(1);
1292
 
 
1293
 
--error 1451
1294
 
DELETE FROM t1 WHERE id = 1;
1295
 
 
1296
 
--error 1217
1297
 
DROP TABLE t1;
1298
 
 
1299
 
SET FOREIGN_KEY_CHECKS=0;
1300
 
DROP TABLE t1;
1301
 
SET FOREIGN_KEY_CHECKS=1;
1302
 
 
1303
 
--error 1452
1304
 
INSERT INTO t2 VALUES(3);
1305
 
 
1306
 
DROP TABLE t2;
1307
 
#
1308
 
# Test that checksum table uses a consistent read Bug #12669
1309
 
#
1310
 
connect (a,localhost,root,,);
1311
 
connect (b,localhost,root,,);
1312
 
connection a;
1313
 
create table t1(a int not null) engine=innodb;
1314
 
insert into t1 values (1),(2);
1315
 
set autocommit=0;
1316
 
checksum table t1;
1317
 
connection b;
1318
 
insert into t1 values(3);
1319
 
connection a;
1320
 
#
1321
 
# Here checksum should not see insert
1322
 
#
1323
 
checksum table t1;
1324
 
connection a;
1325
 
commit;
1326
 
checksum table t1;
1327
 
commit;
1328
 
drop table t1;
1329
 
#
1330
 
# autocommit = 1
1331
 
#
1332
 
connection a;
1333
 
create table t1(a int not null) engine=innodb;
1334
 
insert into t1 values (1),(2);
1335
 
set autocommit=1;
1336
 
checksum table t1;
1337
 
connection b;
1338
 
set autocommit=1;
1339
 
insert into t1 values(3);
1340
 
connection a;
1341
 
#
1342
 
# Here checksum sees insert
1343
 
#
1344
 
checksum table t1;
1345
 
drop table t1;
1346
 
 
1347
 
connection default;
1348
 
disconnect a;
1349
 
disconnect b;
1350
 
 
1351
 
# tests for bugs #9802 and #13778
1352
 
 
1353
 
# test that FKs between invalid types are not accepted
1354
 
 
1355
 
set foreign_key_checks=0;
1356
 
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
1357
 
# Embedded server doesn't chdir to data directory
1358
 
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1359
 
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
1360
 
set foreign_key_checks=1;
1361
 
drop table t2;
1362
 
 
1363
 
# test that invalid datatype conversions with ALTER are not allowed
1364
 
 
1365
 
set foreign_key_checks=0;
1366
 
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
1367
 
create table t1(a varchar(10) primary key) engine = innodb;
1368
 
alter table t1 modify column a int;
1369
 
set foreign_key_checks=1;
1370
 
drop table t2,t1;
1371
 
 
1372
 
# test that foreign key errors are reported correctly (Bug #15550)
1373
 
 
1374
 
create table t1(a int primary key) row_format=redundant engine=innodb;
1375
 
create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
1376
 
create table t3(a int primary key) row_format=compact engine=innodb;
1377
 
create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
1378
 
 
1379
 
insert into t1 values(1);
1380
 
insert into t3 values(1);
1381
 
insert into t2 values(2);
1382
 
insert into t4 values(2);
1383
 
insert into t2 values(1);
1384
 
insert into t4 values(1);
1385
 
update t1 set a=2;
1386
 
update t2 set a=2;
1387
 
update t3 set a=2;
1388
 
update t4 set a=2;
1389
 
truncate t1;
1390
 
truncate t3;
1391
 
truncate t2;
1392
 
truncate t4;
1393
 
truncate t1;
1394
 
truncate t3;
1395
 
 
1396
 
drop table t4,t3,t2,t1;
1397
 
 
1398
 
 
1399
 
#
1400
 
# Test that we can create a large (>1K) key
1401
 
#
1402
 
create table t1 (a varchar(255),
1403
 
                 b varchar(255),
1404
 
                 c varchar(255),
1405
 
                 d varchar(255),
1406
 
                 key (a,b,c,d)) engine=innodb;
1407
 
drop table t1;
1408
 
--error ER_TOO_LONG_KEY
1409
 
create table t1 (a varchar(255),
1410
 
                 b varchar(255),
1411
 
                 c varchar(255),
1412
 
                 d varchar(255),
1413
 
                 e varchar(255),
1414
 
                 key (a,b,c,d,e)) engine=innodb;
1415
 
 
1416
 
 
1417
 
# test the padding of BINARY types and collations (Bug #14189)
1418
 
 
1419
 
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
1420
 
create table t3 (s1 varchar(2) ,primary key (s1)) engine=innodb;
1421
 
create table t4 (s1 char(2) ,primary key (s1)) engine=innodb;
1422
 
 
1423
 
insert into t1 values (0x41),(0x4120),(0x4100);
1424
 
insert into t3 values (0x41),(0x4120),(0x4100);
1425
 
insert into t3 values (0x41),(0x4100);
1426
 
insert into t4 values (0x41),(0x4120),(0x4100);
1427
 
insert into t4 values (0x41),(0x4100);
1428
 
select hex(s1) from t1;
1429
 
select hex(s1) from t3;
1430
 
select hex(s1) from t4;
1431
 
drop table t1,t3,t4;
1432
 
 
1433
 
create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
1434
 
create table t2 (s1 varbinary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
1435
 
 
1436
 
insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
1437
 
insert into t2 values(0x42);
1438
 
insert into t2 values(0x41);
1439
 
select hex(s1) from t2;
1440
 
update t1 set s1=0x123456 where a=2;
1441
 
select hex(s1) from t2;
1442
 
update t1 set s1=0x12 where a=1;
1443
 
update t1 set s1=0x12345678 where a=1;
1444
 
update t1 set s1=0x123457 where a=1;
1445
 
update t1 set s1=0x1220 where a=1;
1446
 
select hex(s1) from t2;
1447
 
update t1 set s1=0x1200 where a=1;
1448
 
select hex(s1) from t2;
1449
 
update t1 set s1=0x4200 where a=1;
1450
 
select hex(s1) from t2;
1451
 
delete from t1 where a=1;
1452
 
update t2 set s1=0x4120;
1453
 
delete from t1;
1454
 
delete from t1 where a!=3;
1455
 
select a,hex(s1) from t1;
1456
 
select hex(s1) from t2;
1457
 
 
1458
 
drop table t2,t1;
1459
 
 
1460
 
create table t1 (a int primary key,s1 varchar(2) not null unique) engine=innodb;
1461
 
create table t2 (s1 char(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
1462
 
 
1463
 
insert into t1 values(1,0x4100),(2,0x41);
1464
 
insert into t2 values(0x41);
1465
 
select hex(s1) from t2;
1466
 
update t1 set s1=0x1234 where a=1;
1467
 
select hex(s1) from t2;
1468
 
update t1 set s1=0x12 where a=2;
1469
 
select hex(s1) from t2;
1470
 
delete from t1 where a=1;
1471
 
delete from t1 where a=2;
1472
 
select a,hex(s1) from t1;
1473
 
select hex(s1) from t2;
1474
 
 
1475
 
drop table t2,t1;
1476
 
# Ensure that <tablename>_ibfk_0 is not mistreated as a
1477
 
# generated foreign key identifier.  (Bug #16387)
1478
 
 
1479
 
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
1480
 
CREATE TABLE t2(a INT) ENGINE=InnoDB;
1481
 
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
1482
 
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
1483
 
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
1484
 
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
1485
 
SHOW CREATE TABLE t2;
1486
 
DROP TABLE t2,t1;
1487
 
 
1488
 
#
1489
 
# Test that cascading updates leading to duplicate keys give the correct
1490
 
# error message (bug #9680)
1491
 
#
1492
 
 
1493
 
CREATE TABLE t1 (
1494
 
  field1 varchar(8) NOT NULL DEFAULT '',
1495
 
  field2 varchar(8) NOT NULL DEFAULT '',
1496
 
  PRIMARY KEY  (field1, field2)
1497
 
) ENGINE=InnoDB;
1498
 
 
1499
 
CREATE TABLE t2 (
1500
 
  field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
1501
 
  FOREIGN KEY (field1) REFERENCES t1 (field1)
1502
 
    ON DELETE CASCADE ON UPDATE CASCADE
1503
 
) ENGINE=InnoDB;
1504
 
 
1505
 
INSERT INTO t1 VALUES ('old', 'somevalu');
1506
 
INSERT INTO t1 VALUES ('other', 'anyvalue');
1507
 
 
1508
 
INSERT INTO t2 VALUES ('old');
1509
 
INSERT INTO t2 VALUES ('other');
1510
 
 
1511
 
--error ER_FOREIGN_DUPLICATE_KEY
1512
 
UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
1513
 
 
1514
 
DROP TABLE t2;
1515
 
DROP TABLE t1;
1516
 
 
1517
 
#
1518
 
# Bug#18477 - MySQL/InnoDB Ignoring Foreign Keys in ALTER TABLE
1519
 
#
1520
 
create table t1 (
1521
 
  c1 bigint not null,
1522
 
  c2 bigint not null,
1523
 
  primary key (c1),
1524
 
  unique  key (c2)
1525
 
) engine=innodb;
1526
 
#
1527
 
create table t2 (
1528
 
  c1 bigint not null,
1529
 
  primary key (c1)
1530
 
) engine=innodb;
1531
 
#
1532
 
alter table t1 add constraint c2_fk foreign key (c2)
1533
 
  references t2(c1) on delete cascade;
1534
 
show create table t1;
1535
 
#
1536
 
alter table t1 drop foreign key c2_fk;
1537
 
show create table t1;
1538
 
#
1539
 
drop table t1, t2;
1540
 
 
1541
 
#
1542
 
# Bug #14360: problem with intervals
1543
 
#
1544
 
 
1545
 
create table t1(a date) engine=innodb;
1546
 
create table t2(a date, key(a)) engine=innodb;
1547
 
insert into t1 values('2005-10-01');
1548
 
insert into t2 values('2005-10-01');
1549
 
select * from t1, t2
1550
 
  where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
1551
 
drop table t1, t2;
1552
 
 
1553
 
create table t1 (id int not null, f_id int not null, f int not null,
1554
 
primary key(f_id, id)) engine=innodb;
1555
 
create table t2 (id int not null,s_id int not null,s varchar(200),
1556
 
primary key(id)) engine=innodb;
1557
 
INSERT INTO t1 VALUES (8, 1, 3);
1558
 
INSERT INTO t1 VALUES (1, 2, 1);
1559
 
INSERT INTO t2 VALUES (1, 0, '');
1560
 
INSERT INTO t2 VALUES (8, 1, '');
1561
 
commit;
1562
 
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
1563
 
where mm.id is null lock in share mode;
1564
 
drop table t1,t2;
1565
 
 
1566
 
#
1567
 
# Test case where X-locks on unused rows should be released in a
1568
 
# update (because READ COMMITTED isolation level)
1569
 
#
1570
 
 
1571
 
connect (a,localhost,root,,);
1572
 
connect (b,localhost,root,,);
1573
 
connection a;
1574
 
create table t1(a int not null, b int, primary key(a)) engine=innodb;
1575
 
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
1576
 
commit;
1577
 
set autocommit = 0; 
1578
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1579
 
update t1 set b = 5 where b = 1;
1580
 
connection b;
1581
 
set autocommit = 0;
1582
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1583
 
#
1584
 
# X-lock to record (7,3) should be released in a update 
1585
 
#
1586
 
select * from t1 where a = 7 and b = 3 for update;
1587
 
connection a;
1588
 
commit;
1589
 
connection b;
1590
 
commit;
1591
 
drop table t1;
1592
 
connection default;
1593
 
disconnect a;
1594
 
disconnect b;
1595
 
 
1596
 
#
1597
 
# Test case where no locks should be released (because we are not
1598
 
# using READ COMMITTED isolation level)
1599
 
#
1600
 
 
1601
 
connect (a,localhost,root,,);
1602
 
connect (b,localhost,root,,);
1603
 
connection a;
1604
 
create table t1(a int not null, b int, primary key(a)) engine=innodb;
1605
 
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
1606
 
commit;
1607
 
set autocommit = 0; 
1608
 
select * from t1 lock in share mode;
1609
 
update t1 set b = 5 where b = 1;
1610
 
connection b;
1611
 
set autocommit = 0;
1612
 
#
1613
 
# S-lock to records (2,2),(4,2), and (6,2) should not be released in a update
1614
 
#
1615
 
--error 1205
1616
 
select * from t1 where a = 2 and b = 2 for update;
1617
 
#
1618
 
# X-lock to record (1,1),(3,1),(5,1) should not be released in a update
1619
 
#
1620
 
--error 1205
1621
 
connection a;
1622
 
commit;
1623
 
connection b;
1624
 
commit;
1625
 
connection default;
1626
 
disconnect a;
1627
 
disconnect b;
1628
 
drop table t1;
1629
 
 
1630
 
#
1631
 
# Consistent read should be used in following selects
1632
 
#
1633
 
# 1) INSERT INTO ... SELECT
1634
 
# 2) UPDATE ... = ( SELECT ...)
1635
 
# 3) CREATE ... SELECT
1636
 
 
1637
 
connect (a,localhost,root,,);
1638
 
connect (b,localhost,root,,);
1639
 
connection a;
1640
 
create table t1(a int not null, b int, primary key(a)) engine=innodb;
1641
 
insert into t1 values (1,2),(5,3),(4,2);
1642
 
create table t2(d int not null, e int, primary key(d)) engine=innodb;
1643
 
insert into t2 values (8,6),(12,1),(3,1);
1644
 
commit;
1645
 
set autocommit = 0;
1646
 
select * from t2 for update;
1647
 
connection b;
1648
 
set autocommit = 0;
1649
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1650
 
insert into t1 select * from t2;
1651
 
update t1 set b = (select e from t2 where a = d);
1652
 
create table t3(d int not null, e int, primary key(d)) engine=innodb
1653
 
select * from t2;
1654
 
commit;
1655
 
connection a;
1656
 
commit;
1657
 
connection default;
1658
 
disconnect a;
1659
 
disconnect b;
1660
 
drop table t1, t2, t3;
1661
 
 
1662
 
#
1663
 
# Consistent read should not be used if 
1664
 
#
1665
 
# (a) isolation level is serializable OR
1666
 
# (b) select ... lock in share mode OR
1667
 
# (c) select ... for update
1668
 
#
1669
 
# in following queries:
1670
 
#
1671
 
# 1) INSERT INTO ... SELECT
1672
 
# 2) UPDATE ... = ( SELECT ...)
1673
 
# 3) CREATE ... SELECT
1674
 
 
1675
 
connect (a,localhost,root,,);
1676
 
connect (b,localhost,root,,);
1677
 
connect (c,localhost,root,,);
1678
 
connect (d,localhost,root,,);
1679
 
connect (e,localhost,root,,);
1680
 
connect (f,localhost,root,,);
1681
 
connect (g,localhost,root,,);
1682
 
connect (h,localhost,root,,);
1683
 
connect (i,localhost,root,,);
1684
 
connect (j,localhost,root,,);
1685
 
connection a;
1686
 
create table t1(a int not null, b int, primary key(a)) engine=innodb;
1687
 
insert into t1 values (1,2),(5,3),(4,2);
1688
 
create table t2(a int not null, b int, primary key(a)) engine=innodb;
1689
 
insert into t2 values (8,6),(12,1),(3,1);
1690
 
create table t3(d int not null, b int, primary key(d)) engine=innodb;
1691
 
insert into t3 values (8,6),(12,1),(3,1);
1692
 
create table t5(a int not null, b int, primary key(a)) engine=innodb;
1693
 
insert into t5 values (1,2),(5,3),(4,2);
1694
 
create table t6(d int not null, e int, primary key(d)) engine=innodb;
1695
 
insert into t6 values (8,6),(12,1),(3,1);
1696
 
create table t8(a int not null, b int, primary key(a)) engine=innodb;
1697
 
insert into t8 values (1,2),(5,3),(4,2);
1698
 
create table t9(d int not null, e int, primary key(d)) engine=innodb;
1699
 
insert into t9 values (8,6),(12,1),(3,1);
1700
 
commit;
1701
 
set autocommit = 0;
1702
 
select * from t2 for update;
1703
 
connection b;
1704
 
set autocommit = 0;
1705
 
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
1706
 
--send
1707
 
insert into t1 select * from t2;
1708
 
connection c;
1709
 
set autocommit = 0;
1710
 
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
1711
 
--send
1712
 
update t3 set b = (select b from t2 where a = d);
1713
 
connection d;
1714
 
set autocommit = 0;
1715
 
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
1716
 
--send
1717
 
create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
1718
 
connection e;
1719
 
set autocommit = 0;
1720
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1721
 
--send
1722
 
insert into t5 (select * from t2 lock in share mode);
1723
 
connection f;
1724
 
set autocommit = 0;
1725
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1726
 
--send
1727
 
update t6 set e = (select b from t2 where a = d lock in share mode);
1728
 
connection g;
1729
 
set autocommit = 0;
1730
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1731
 
--send
1732
 
create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
1733
 
connection h;
1734
 
set autocommit = 0;
1735
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1736
 
--send
1737
 
insert into t8 (select * from t2 for update);
1738
 
connection i;
1739
 
set autocommit = 0;
1740
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1741
 
--send
1742
 
update t9 set e = (select b from t2 where a = d for update);
1743
 
connection j;
1744
 
set autocommit = 0;
1745
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1746
 
--send
1747
 
create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
1748
 
 
1749
 
connection b;
1750
 
--error 1205
1751
 
reap;
1752
 
 
1753
 
connection c;
1754
 
--error 1205
1755
 
reap;
1756
 
 
1757
 
connection d;
1758
 
--error 1205
1759
 
reap;
1760
 
 
1761
 
connection e;
1762
 
--error 1205
1763
 
reap;
1764
 
 
1765
 
connection f;
1766
 
--error 1205
1767
 
reap;
1768
 
 
1769
 
connection g;
1770
 
--error 1205
1771
 
reap;
1772
 
 
1773
 
connection h;
1774
 
--error 1205
1775
 
reap;
1776
 
 
1777
 
connection i;
1778
 
--error 1205
1779
 
reap;
1780
 
 
1781
 
connection j;
1782
 
--error 1205
1783
 
reap;
1784
 
 
1785
 
connection a;
1786
 
commit;
1787
 
 
1788
 
connection default;
1789
 
disconnect a;
1790
 
disconnect b;
1791
 
disconnect c;
1792
 
disconnect d;
1793
 
disconnect e;
1794
 
disconnect f;
1795
 
disconnect g;
1796
 
disconnect h;
1797
 
disconnect i;
1798
 
disconnect j;
1799
 
drop table t1, t2, t3, t5, t6, t8, t9;
1800
 
 
1801
 
# bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID"
1802
 
--error 1005
1803
 
CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
1804
 
 
1805
 
#
1806
 
# Bug #17152: Wrong result with BINARY comparison on aliased column
1807
 
#
1808
 
 
1809
 
CREATE TABLE t1 (
1810
 
   a BIGINT NOT NULL,
1811
 
    PRIMARY KEY  (a)
1812
 
 ) ENGINE=INNODB;
1813
 
 
1814
 
CREATE TABLE t2 (
1815
 
  a BIGINT NOT NULL,
1816
 
  b VARCHAR(128) NOT NULL,
1817
 
  c TEXT NOT NULL,
1818
 
  PRIMARY KEY  (a,b),
1819
 
  KEY idx_t2_b_c (b,c(200)),
1820
 
  CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a) 
1821
 
   ON DELETE CASCADE
1822
 
 ) ENGINE=INNODB;
1823
 
 
1824
 
INSERT INTO t1 VALUES (1);
1825
 
INSERT INTO t2 VALUES (1, 'bar', 'vbar');
1826
 
INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
1827
 
INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
1828
 
INSERT INTO t2 VALUES (1, 'customer_over', '1');
1829
 
 
1830
 
SELECT * FROM t2 WHERE b = 'customer_over';
1831
 
SELECT * FROM t2 WHERE BINARY b = 'customer_over';
1832
 
SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
1833
 
/* Bang: Empty result set, above was expected: */
1834
 
SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
1835
 
SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
1836
 
 
1837
 
drop table t2, t1;
1838
 
 
1839
 
#
1840
 
# Test optimize on table with open transaction
1841
 
#
1842
 
 
1843
 
CREATE TABLE t1 ( a int ) ENGINE=innodb;
1844
 
BEGIN;
1845
 
INSERT INTO t1 VALUES (1);
1846
 
ALTER TABLE t1 ENGINE=innodb;
1847
 
DROP TABLE t1;
1848
 
 
1849
 
#
1850
 
# Bug #24741 (existing cascade clauses disappear when adding foreign keys)
1851
 
#
1852
 
 
1853
 
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
1854
 
 
1855
 
CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
1856
 
  CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
1857
 
  ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
1858
 
 
1859
 
ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
1860
 
DELETE CASCADE ON UPDATE CASCADE;
1861
 
 
1862
 
SHOW CREATE TABLE t2;
1863
 
DROP TABLE t2, t1;
1864
 
 
1865
 
#
1866
 
# Bug #25927: Prevent ALTER TABLE ... MODIFY ... NOT NULL on columns
1867
 
# for which there is a foreign key constraint ON ... SET NULL.
1868
 
#
1869
 
 
1870
 
CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
1871
 
CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
1872
 
INSERT INTO t1 VALUES (1);
1873
 
INSERT INTO t2 VALUES (1);
1874
 
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
1875
 
# mysqltest first does replace_regex, then replace_result
1876
 
--replace_regex /'[^']*test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
1877
 
# Embedded server doesn't chdir to data directory
1878
 
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1879
 
--error 1025
1880
 
ALTER TABLE t2 MODIFY a INT NOT NULL;
1881
 
DELETE FROM t1;
1882
 
DROP TABLE t2,t1;
1883
 
 
1884
 
#
1885
 
# Bug #26835: table corruption after delete+insert
1886
 
#
1887
 
 
1888
 
CREATE TABLE t1 (a VARCHAR(5) COLLATE utf8_unicode_ci PRIMARY KEY)
1889
 
ENGINE=InnoDB;
1890
 
INSERT INTO t1 VALUES (0xEFBCA4EFBCA4EFBCA4);
1891
 
DELETE FROM t1;
1892
 
INSERT INTO t1 VALUES ('DDD');
1893
 
SELECT * FROM t1;
1894
 
DROP TABLE t1;
1895
 
 
1896
 
#
1897
 
# Bug #23313 (AUTO_INCREMENT=# not reported back for InnoDB tables)
1898
 
# Bug #21404 (AUTO_INCREMENT value reset when Adding FKEY (or ALTER?))
1899
 
#
1900
 
 
1901
 
CREATE TABLE t1 (id int PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB
1902
 
AUTO_INCREMENT=42;
1903
 
 
1904
 
INSERT INTO t1 VALUES (NULL),(347),(NULL);
1905
 
SELECT * FROM t1;
1906
 
 
1907
 
SHOW CREATE TABLE t1;
1908
 
 
1909
 
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
1910
 
INSERT INTO t2 VALUES(42),(347),(348);
1911
 
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
1912
 
SHOW CREATE TABLE t1;
1913
 
 
1914
 
DROP TABLE t1,t2;
1915
 
 
1916
 
#
1917
 
# Bug #31860 InnoDB assumes AUTOINC values can only be positive.
1918
 
#
1919
 
DROP TABLE IF EXISTS t1;
1920
 
CREATE TABLE t1(
1921
 
        id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
1922
 
        ) ENGINE=InnoDB;
1923
 
INSERT INTO t1 VALUES(-10);
1924
 
SELECT * FROM t1;
1925
 
#
1926
 
# NOTE: The server really needs to be restarted at this point
1927
 
# for the test to be useful.  
1928
 
#
1929
 
# Without the fix InnoDB would trip over an assertion here.
1930
 
INSERT INTO t1 VALUES(NULL);
1931
 
# The next value should be 1 and not -9 or a -ve number
1932
 
SELECT * FROM t1;
1933
 
DROP TABLE t1;
1934
 
 
1935
 
#######################################################################
1936
 
#                                                                     #
1937
 
# Please, DO NOT TOUCH this file as well as the innodb.result file.   #
1938
 
# These files are to be modified ONLY BY INNOBASE guys.               #
1939
 
#                                                                     #
1940
 
# Use innodb_mysql.[test|result] files instead.                       #
1941
 
#                                                                     #
1942
 
# If nevertheless you need to make some changes here, please, forward #
1943
 
# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com     #
1944
 
# (otherwise your changes may be erased).                             #
1945
 
#                                                                     #
1946
 
#######################################################################