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