~drizzle-trunk/drizzle/development

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