~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
# include/mix1.inc
2
#
3
# The variables
4
#     $engine_type       -- storage engine to be tested
5
#     $other_engine_type -- storage engine <> $engine_type
6
#                           $other_engine_type must point to an all
7
#                           time available storage engine
8
#                              2006-08 MySQL 5.1 MyISAM and MEMORY only
9
#    $test_foreign_keys -- 0, skip foreign key tests
10
#                       -- 1, do not skip foreign key tests
11
# have to be set before sourcing this script.
12
#
13
# Note: The comments/expectations refer to InnoDB.
14
#       They might be not valid for other storage engines.
15
#
16
# Last update:
17
# 2006-08-15 ML refactoring of t/innodb_mysql.test
18
#               - shift main code of t/innodb_mysql.test to include/mix1.inc
19
#               - replace hardcoded assignment of storage engine by
20
#                 use of $engine_type and $other_engine_type variables
21
#               - remove redundant replay testcase of
22
#                 Bug#12882 min/max inconsistent on empty table
23
#               - corrected analyze table t1; to analyze table t4;
24
#                 Much older versions of this test show that the table
25
#                 where just some indexes have been created must be used.
26
#
27
28
eval SET SESSION STORAGE_ENGINE = $engine_type;
29
30
--disable_warnings
31
drop table if exists t1,t2,t3,t1m,t1i,t2m,t2i,t4;
32
--enable_warnings
33
34
35
# BUG#16798: Uninitialized row buffer reads in ref-or-null optimizer
36
# (repeatable only w/innodb).
37
create table t1 (
520.1.16 by Brian Aker
More test updates (one ulong fix)
38
  c_id int not null default '0',
39
  org_id int default null,
1 by brian
clean slate
40
  unique key contacts$c_id (c_id),
41
  key contacts$org_id (org_id)
42
);
43
insert into t1 values
44
  (2,null),(120,null),(141,null),(218,7), (128,1),
45
  (151,2),(234,2),(236,2),(243,2),(255,2),(259,2),(232,3),(235,3),(238,3),
46
  (246,3),(253,3),(269,3),(285,3),(291,3),(293,3),(131,4),(230,4),(231,4);
47
48
create table t2 (
520.1.16 by Brian Aker
More test updates (one ulong fix)
49
  slai_id int not null default '0',
50
  owner_tbl int default null,
51
  owner_id int default null,
52
  sla_id int default null,
53
  inc_web int default null,
54
  inc_email int default null,
55
  inc_chat int default null,
56
  inc_csr int default null,
57
  inc_total int default null,
58
  time_billed int default null,
1 by brian
clean slate
59
  activedate timestamp null default null,
60
  expiredate timestamp null default null,
520.1.16 by Brian Aker
More test updates (one ulong fix)
61
  state int default null,
62
  sla_set int default null,
1 by brian
clean slate
63
  unique key t2$slai_id (slai_id),
64
  key t2$owner_id (owner_id),
65
  key t2$sla_id (sla_id)
66
);
67
insert into t2(slai_id, owner_tbl, owner_id, sla_id) values
68
  (1,3,1,1), (3,3,10,2), (4,3,3,6), (5,3,2,5), (6,3,8,3), (7,3,9,7),
69
  (8,3,6,8), (9,3,4,9), (10,3,5,10), (11,3,11,11), (12,3,7,12);
70
71
flush tables;
72
select si.slai_id
73
from t1 c join t2 si on
74
  ((si.owner_tbl = 3 and si.owner_id = c.org_id) or
75
   ( si.owner_tbl = 2 and si.owner_id = c.c_id))
76
where
77
  c.c_id = 218 and expiredate is null;
78
79
select * from t1 where org_id is null;
80
select si.slai_id
81
from t1 c join t2 si on
82
  ((si.owner_tbl = 3 and si.owner_id = c.org_id) or
83
   ( si.owner_tbl = 2 and si.owner_id = c.c_id))
84
where
85
  c.c_id = 218 and expiredate is null;
86
87
drop table t1, t2;
88
89
#
90
# Bug#17212: results not sorted correctly by ORDER BY when using index
91
# (repeatable only w/innodb because of index props)
92
#
93
CREATE TABLE t1 (a int, b int, KEY b (b));
94
CREATE TABLE t2 (a int, b int, PRIMARY KEY  (a,b));
95
CREATE TABLE t3 (a int, b int, c int, PRIMARY KEY  (a),
96
  UNIQUE KEY b (b,c), KEY a (a,b,c));
97
98
INSERT INTO t1 VALUES (1, 1);
99
INSERT INTO t1 SELECT a + 1, b + 1 FROM t1;
100
INSERT INTO t1 SELECT a + 2, b + 2 FROM t1;
101
102
INSERT INTO t2 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
103
INSERT INTO t2 SELECT a + 1, b FROM t2;
104
DELETE FROM t2 WHERE a = 1 AND b < 2;
105
106
INSERT INTO t3 VALUES (1,1,1),(2,1,2);
107
INSERT INTO t3 SELECT a + 2, a + 2, 3 FROM t3;
108
INSERT INTO t3 SELECT a + 4, a + 4, 3 FROM t3;
109
110
# demonstrate a problem when a must-use-sort table flag
111
# (sort_by_table=1) is being neglected.
520.1.16 by Brian Aker
More test updates (one ulong fix)
112
SELECT STRAIGHT_JOIN t1.b, t1.a FROM t1, t3, t2 WHERE
1 by brian
clean slate
113
  t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
114
  ORDER BY t1.b LIMIT 2;
115
116
# demonstrate the problem described in the bug report
520.1.16 by Brian Aker
More test updates (one ulong fix)
117
SELECT STRAIGHT_JOIN t1.b, t1.a FROM t1, t3, t2 WHERE
1 by brian
clean slate
118
  t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
119
  ORDER BY t1.b LIMIT 5;
120
DROP TABLE t1, t2, t3;
121
122
123
# BUG#21077 (The testcase is not deterministic so correct execution doesn't
124
# prove anything) For proof one should track if sequence of ha_innodb::* func
125
# calls is correct.
126
CREATE TABLE `t1` (`id1` INT) ;
127
INSERT INTO `t1` (`id1`) VALUES (1),(5),(2);
128
129
CREATE TABLE `t2` (
130
  `id1` INT,
131
  `id2` INT NOT NULL,
132
  `id3` INT,
133
  `id4` INT NOT NULL,
134
  UNIQUE (`id2`,`id4`),
135
  KEY (`id1`)
136
);
137
138
INSERT INTO `t2`(`id1`,`id2`,`id3`,`id4`) VALUES
139
(1,1,1,0),
140
(1,1,2,1),
141
(5,1,2,2),
142
(6,1,2,3),
143
(1,2,2,2),
144
(1,2,1,1);
145
146
SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = 1 AND `id3` = 2);
147
DROP TABLE t1, t2;
148
149
#
150
# Bug #13191: INSERT...ON DUPLICATE KEY UPDATE of UTF-8 string fields
151
# used in partial unique indices.
152
#
153
154
CREATE TABLE t1(c1 TEXT, UNIQUE (c1(1)), cnt INT DEFAULT 1)
520.1.16 by Brian Aker
More test updates (one ulong fix)
155
  ENGINE=INNODB;
1 by brian
clean slate
156
INSERT INTO t1 (c1) VALUES ('1a');
157
SELECT * FROM t1;
158
INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
159
SELECT * FROM t1;
160
DROP TABLE t1;
161
162
CREATE TABLE t1(c1 VARCHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
520.1.16 by Brian Aker
More test updates (one ulong fix)
163
  ENGINE=INNODB;
1 by brian
clean slate
164
INSERT INTO t1 (c1) VALUES ('1a');
165
SELECT * FROM t1;
166
INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
167
SELECT * FROM t1;
168
DROP TABLE t1;
169
170
CREATE TABLE t1(c1 CHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
520.1.16 by Brian Aker
More test updates (one ulong fix)
171
  ENGINE=INNODB;
1 by brian
clean slate
172
INSERT INTO t1 (c1) VALUES ('1a');
173
SELECT * FROM t1;
174
INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
175
SELECT * FROM t1;
176
DROP TABLE t1;
177
178
#
179
# Bug #28272: EXPLAIN for SELECT from an empty InnoDB table
180
#
181
182
CREATE TABLE t1 (
183
  a1 decimal(10,0) DEFAULT NULL,
184
  a2 blob,
185
  a4 blob,
186
  a5 char(175) DEFAULT NULL,
907.1.7 by Jay Pipes
Merged in remove-timezone work
187
  a6 timestamp NOT NULL DEFAULT NOW(),
520.1.16 by Brian Aker
More test updates (one ulong fix)
188
  a7 blob,
1 by brian
clean slate
189
  INDEX idx (a6,a7(239),a5)
190
) ENGINE=InnoDB;
191
192
EXPLAIN SELECT a4 FROM t1 WHERE
193
a6=NULL AND
194
a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
195
196
EXPLAIN SELECT t1.a4 FROM t1, t1 t WHERE
197
t.a6=t.a6 AND t1.a6=NULL AND
198
t1.a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
199
200
DROP TABLE t1;
201
202
#
203
# Bug #12882  	min/max inconsistent on empty table
204
#
205
206
--disable_warnings
1106.3.1 by Brian Aker
Heap is now tmp only table
207
eval create temporary table t1m (a int) engine = $other_engine_type;
1 by brian
clean slate
208
create table t1i (a int);
1106.3.1 by Brian Aker
Heap is now tmp only table
209
eval create temporary table t2m (a int) engine = $other_engine_type;
1 by brian
clean slate
210
create table t2i (a int);
211
--enable_warnings
212
insert into t2m values (5);
213
insert into t2i values (5);
214
215
select 1, min(a) from t1i where a=99;
216
select 1, min(a) from t1i where 1=99;
217
select 1, min(1) from t1i where a=99;
218
select 1, min(1) from t1i where 1=99;
219
220
select 1, max(a) from t1i where a=99;
221
select 1, max(a) from t1i where 1=99;
222
select 1, max(1) from t1i where a=99;
223
select 1, max(1) from t1i where 1=99;
224
225
# mixed $engine_type/$other_engine_type test
226
explain select count(*), min(7), max(7) from t1m, t1i;
227
select count(*), min(7), max(7) from t1m, t1i;
228
229
explain select count(*), min(7), max(7) from t1m, t2i;
230
select count(*), min(7), max(7) from t1m, t2i;
231
232
explain select count(*), min(7), max(7) from t2m, t1i;
233
select count(*), min(7), max(7) from t2m, t1i;
234
235
drop table t1m, t1i, t2m, t2i;
236
237
#
238
# Bug #12882: primary key implcitly included in every innodb index
239
# (was part of group_min_max.test)
240
#
241
1106.3.1 by Brian Aker
Heap is now tmp only table
242
eval create TEMPORARY table t1 (
1 by brian
clean slate
243
  a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
244
) ENGINE = $other_engine_type;
245
246
insert into t1 (a1, a2, b, c, d) values
247
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
248
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
249
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
250
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
251
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
252
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
253
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
254
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
255
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
256
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
257
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
258
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
259
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
260
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
261
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
262
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
263
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
264
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
265
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
266
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
267
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
268
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
269
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
270
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
271
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
272
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
273
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
274
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
275
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
276
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
277
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
278
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
279
--disable_warnings
280
create table t4 (
281
  pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
282
);
283
--enable_warnings
284
insert into t4 (a1, a2, b, c, d, dummy) select * from t1;
285
286
create index idx12672_0 on t4 (a1);
287
create index idx12672_1 on t4 (a1,a2,b,c);
288
create index idx12672_2 on t4 (a1,a2,b);
289
analyze table t4;
290
291
select distinct a1 from t4 where pk_col not in (1,2,3,4);
292
293
drop table t1,t4;
294
295
296
#
297
# BUG#18819: DELETE IGNORE hangs on foreign key parent delete
298
#
299
# The bug itself does not relate to InnoDB, but we have to use foreign
300
# keys to reproduce it.
301
#
302
--disable_warnings
303
DROP TABLE IF EXISTS t2, t1;
304
--enable_warnings
305
306
CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE= InnoDB;
307
CREATE TABLE t2 (
308
  i INT NOT NULL,
309
  FOREIGN KEY (i) REFERENCES t1 (i) ON DELETE NO ACTION
310
) ENGINE= InnoDB;
311
312
INSERT INTO t1 VALUES (1);
313
INSERT INTO t2 VALUES (1);
314
315
DELETE IGNORE FROM t1 WHERE i = 1;
316
317
SELECT * FROM t1, t2;
318
319
DROP TABLE t2, t1;
320
321
322
--echo End of 4.1 tests.
323
324
325
#
326
# Bug #6142: a problem with the empty innodb table
327
# (was part of group_min_max.test)
328
#
329
330
--disable_warnings
331
create table t1 (
332
  a varchar(30), b varchar(30), primary key(a), key(b)
333
);
334
--enable_warnings
335
select distinct a from t1;
336
drop table t1;
337
338
#
339
# Bug #9798: group by with rollup
340
# (was part of group_min_max.test)
341
#
342
343
--disable_warnings
344
create table t1(a int, key(a));
345
--enable_warnings
346
insert into t1 values(1);
347
select a, count(a) from t1 group by a with rollup;
348
drop table t1;
349
350
#
351
# Bug #13293 Wrongly used index results in endless loop.
352
# (was part of group_min_max.test)
353
#
354
create table t1 (f1 int, f2 char(1), primary key(f1,f2));
355
insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
356
alter table t1 drop primary key, add primary key (f2, f1);
357
explain select distinct f1 a, f1 b from t1;
358
explain select distinct f1, f2 from t1;
359
drop table t1;
360
361
#
362
# Test for bug #17164: ORed FALSE blocked conversion of outer join into join
363
#
364
520.1.16 by Brian Aker
More test updates (one ulong fix)
365
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, name varchar(20),
1 by brian
clean slate
366
                 INDEX (name));
520.1.16 by Brian Aker
More test updates (one ulong fix)
367
CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, fkey int);
368
# CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, fkey int,
1 by brian
clean slate
369
#                  FOREIGN KEY (fkey) REFERENCES t2(id));
370
if ($test_foreign_keys)
371
{
372
   ALTER TABLE t2 ADD FOREIGN KEY (fkey) REFERENCES t2(id);
373
}
374
INSERT INTO t1 VALUES (1,'A1'),(2,'A2'),(3,'B');
375
INSERT INTO t2 VALUES (1,1),(2,2),(3,2),(4,3),(5,3);
376
377
EXPLAIN
378
SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
379
  WHERE t1.name LIKE 'A%';
380
381
EXPLAIN
382
SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
383
  WHERE t1.name LIKE 'A%' OR FALSE;
384
385
DROP TABLE t1,t2;
386
387
#
388
# Bug#26159: crash for a loose scan of a table that has been emptied 
389
#
390
391
CREATE TABLE t1 (
392
  id int NOT NULL,
393
  name varchar(20) NOT NULL,
394
  dept varchar(20) NOT NULL,
520.1.16 by Brian Aker
More test updates (one ulong fix)
395
  age int NOT NULL,
1 by brian
clean slate
396
  PRIMARY KEY (id),
397
  INDEX (name,dept)
398
) ENGINE=InnoDB;
399
INSERT INTO t1(id, dept, age, name) VALUES
400
  (3987, 'cs1', 10, 'rs1'), (3988, 'cs2', 20, 'rs1'), (3995, 'cs3', 10, 'rs2'),
401
  (3996, 'cs4', 20, 'rs2'), (4003, 'cs5', 10, 'rs3'), (4004, 'cs6', 20, 'rs3'),
402
  (4011, 'cs7', 10, 'rs4'), (4012, 'cs8', 20, 'rs4'), (4019, 'cs9', 10, 'rs5'),
403
  (4020, 'cs10', 20, 'rs5'),(4027, 'cs11', 10, 'rs6'),(4028, 'cs12', 20, 'rs6');
404
405
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
406
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
407
DELETE FROM t1;
408
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
409
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
410
411
DROP TABLE t1;
412
413
--source include/innodb_rollback_on_timeout.inc
414
415
#
416
# Bug #27210: INNODB ON DUPLICATE KEY UPDATE
417
#
418
419
connect (con1,localhost,root,,);
420
connection con1;
421
drop table if exists `test`;
422
CREATE TABLE `test` (`test1` varchar(3) NOT NULL,
423
  `test2` varchar(4) NOT NULL,PRIMARY KEY  (`test1`))
520.1.16 by Brian Aker
More test updates (one ulong fix)
424
  ENGINE=InnoDB;
1 by brian
clean slate
425
INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '5678');
426
disconnect con1;
427
connect (con2,localhost,root,,);
428
connection con2;
429
select * from test;
430
INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '1234')
431
  ON DUPLICATE KEY UPDATE `test2` = '1234';
432
select * from test;
433
flush tables;
434
select * from test;
435
disconnect con2;
436
connection default;
437
drop table test;
438
439
--source include/innodb_rollback_on_timeout.inc
440
441
#
442
# Bug #27650: INSERT fails after multi-row INSERT of the form:
443
# INSERT INTO t (id...) VALUES (NULL...) ON DUPLICATE KEY UPDATE id=VALUES(id)
444
#
445
446
create table t1(
447
id int auto_increment,
448
c char(1) not null,
449
counter int not null default 1,
450
primary key (id),
451
unique key (c)
452
) engine=innodb;
453
454
insert into t1 (id, c) values
455
(NULL, 'a'),
456
(NULL, 'a')
457
on duplicate key update id = values(id), counter = counter + 1;
458
459
select * from t1;
460
461
insert into t1 (id, c) values
462
(NULL, 'b')
463
on duplicate key update id = values(id), counter = counter + 1;
464
465
select * from t1;
466
467
truncate table t1;
468
469
insert into t1 (id, c) values (NULL, 'a');
470
471
select * from t1;
472
473
insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
474
on duplicate key update id = values(id), c = values(c), counter = counter + 1;
475
476
select * from t1;
477
478
insert into t1 (id, c) values (NULL, 'a')
479
on duplicate key update id = values(id), c = values(c), counter = counter + 1;
480
481
select * from t1;
482
483
drop table t1;
484
520.1.16 by Brian Aker
More test updates (one ulong fix)
485
# Test needs to be rewritten to not use divide by zero
486
##
487
## Bug #28189: optimizer erroniously prefers ref access to range access 
488
##             for an InnoDB table
489
##
490
#
491
#CREATE TABLE t1(
492
#  id int AUTO_INCREMENT PRIMARY KEY,
493
#  stat_id int NOT NULL,
494
#  acct_id int DEFAULT NULL,
495
#  INDEX idx1 (stat_id, acct_id),
496
#  INDEX idx2 (acct_id)
497
#) ENGINE=MyISAM;
498
#
499
#CREATE TABLE t2(
500
#  id int AUTO_INCREMENT PRIMARY KEY,
501
#  stat_id int NOT NULL,
502
#  acct_id int DEFAULT NULL,
503
#  INDEX idx1 (stat_id, acct_id),
504
#  INDEX idx2 (acct_id)
505
#) ENGINE=InnoDB;
506
#
507
#INSERT INTO t1(stat_id,acct_id) VALUES
508
#  (1,759), (2,831), (3,785), (4,854), (1,921),
509
#  (1,553), (2,589), (3,743), (2,827), (2,545),
510
#  (4,779), (4,783), (1,597), (1,785), (4,832),
511
#  (1,741), (1,833), (3,788), (2,973), (1,907);
512
#
513
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
514
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
515
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
516
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
517
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
518
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
519
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
520
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
521
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
522
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
523
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
524
#UPDATE t1 SET acct_id=785 
525
#  WHERE MOD(stat_id,2)=0 AND MOD(id,stat_id)=MOD(acct_id,stat_id);
526
#OPTIMIZE TABLE t1;
527
#
528
#SELECT COUNT(*) FROM t1;
529
#SELECT COUNT(*) FROM t1 WHERE acct_id=785;
530
#
531
#EXPLAIN SELECT COUNT(*) FROM t1 WHERE stat_id IN (1,3) AND acct_id=785; 
532
#
533
#INSERT INTO t2 SELECT * FROM t1;
534
#OPTIMIZE TABLE t2;
535
#
536
#EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
537
#
538
#DROP TABLE t1,t2; 
539
#
1 by brian
clean slate
540
#
541
# Bug #28652: assert when alter innodb table operation
542
#
543
create table t1(a int) engine=innodb;
1245.3.4 by Stewart Smith
make the equals of KEY=VALUE required for CREATE TABLE options
544
alter table t1 comment='123';
1 by brian
clean slate
545
show create table t1;
546
drop table t1;
547
548
#
549
# Bug #25866: Getting "#HY000 Can't find record in..." on and INSERT
550
#
520.1.16 by Brian Aker
More test updates (one ulong fix)
551
CREATE TABLE t1 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
1 by brian
clean slate
552
INSERT INTO t1 VALUES ('uk'),('bg');
553
SELECT * FROM t1 WHERE a = 'uk';
554
DELETE FROM t1 WHERE a = 'uk';
555
SELECT * FROM t1 WHERE a = 'uk';
556
UPDATE t1 SET a = 'us' WHERE a = 'uk';
557
SELECT * FROM t1 WHERE a = 'uk';
558
559
CREATE TABLE t2 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
560
INSERT INTO t2 VALUES ('uk'),('bg');
561
SELECT * FROM t2 WHERE a = 'uk';
562
DELETE FROM t2 WHERE a = 'uk';
563
SELECT * FROM t2 WHERE a = 'uk';
564
INSERT INTO t2 VALUES ('uk');
565
UPDATE t2 SET a = 'us' WHERE a = 'uk';
566
SELECT * FROM t2 WHERE a = 'uk';
567
1063.9.3 by Brian Aker
Partial fix for tests for tmp
568
CREATE TEMPORARY TABLE t3 (a CHAR(2), KEY (a)) ENGINE = MyISAM;
1 by brian
clean slate
569
INSERT INTO t3 VALUES ('uk'),('bg');
570
SELECT * FROM t3 WHERE a = 'uk';
571
DELETE FROM t3 WHERE a = 'uk';
572
SELECT * FROM t3 WHERE a = 'uk';
573
INSERT INTO t3 VALUES ('uk');
574
UPDATE t3 SET a = 'us' WHERE a = 'uk';
575
SELECT * FROM t3 WHERE a = 'uk';
576
577
DROP TABLE t1,t2,t3;
578
579
#
580
# Bug #25798: a query with forced index merge returns wrong result 
581
#
582
583
CREATE TABLE t1 (
584
  id int NOT NULL auto_increment PRIMARY KEY,
585
  b int NOT NULL,
586
  c datetime NOT NULL,
587
  INDEX idx_b(b),
588
  INDEX idx_c(c)
589
) ENGINE=InnoDB;
590
591
CREATE TABLE t2 (
592
  b int NOT NULL auto_increment PRIMARY KEY,
593
  c datetime NOT NULL
1063.9.3 by Brian Aker
Partial fix for tests for tmp
594
) ENGINE= InnoDB;
1 by brian
clean slate
595
596
INSERT INTO t2(c) VALUES ('2007-01-01');
597
INSERT INTO t2(c) SELECT c FROM t2;
598
INSERT INTO t2(c) SELECT c FROM t2;
599
INSERT INTO t2(c) SELECT c FROM t2;
600
INSERT INTO t2(c) SELECT c FROM t2;
601
INSERT INTO t2(c) SELECT c FROM t2;
602
INSERT INTO t2(c) SELECT c FROM t2;
603
INSERT INTO t2(c) SELECT c FROM t2;
604
INSERT INTO t2(c) SELECT c FROM t2;
605
INSERT INTO t2(c) SELECT c FROM t2;
606
INSERT INTO t2(c) SELECT c FROM t2;
607
608
INSERT INTO t1(b,c) SELECT b,c FROM t2;
609
UPDATE t2 SET c='2007-01-02';
610
INSERT INTO t1(b,c) SELECT b,c FROM t2;
611
UPDATE t2 SET c='2007-01-03';
612
INSERT INTO t1(b,c) SELECT b,c FROM t2;
613
614
set @@sort_buffer_size=8192;
615
616
SELECT COUNT(*) FROM t1;
617
618
--replace_column 9 #
619
EXPLAIN 
620
SELECT COUNT(*) FROM t1 
621
  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
622
SELECT COUNT(*) FROM t1 
623
  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
624
625
--replace_column 9 #
626
EXPLAIN 
627
SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c) 
628
  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
629
SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
630
  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
631
632
set @@sort_buffer_size=default;
633
634
DROP TABLE t1,t2;
635
636
# Test of behaviour with CREATE ... SELECT
637
#
638
639
CREATE TABLE t1 (a int, b int);
640
insert into t1 values (1,1),(1,2);
641
--error ER_DUP_ENTRY
642
CREATE TABLE t2 (primary key (a)) select * from t1;
643
# This should give warning
644
drop table if exists t2;
645
--error ER_DUP_ENTRY
646
CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
647
# This should give warning
648
drop table if exists t2;
649
CREATE TABLE t2 (a int, b int, primary key (a));
650
BEGIN;
651
INSERT INTO t2 values(100,100);
652
--error ER_DUP_ENTRY
653
CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
654
SELECT * from t2;
655
ROLLBACK;
656
SELECT * from t2;
657
TRUNCATE table t2;
658
--error ER_DUP_ENTRY
659
INSERT INTO t2 select * from t1;
660
SELECT * from t2;
661
drop table t2;
662
663
CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
664
BEGIN;
665
INSERT INTO t2 values(100,100);
666
--error ER_DUP_ENTRY
667
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
668
SELECT * from t2;
669
COMMIT;
670
BEGIN;
671
INSERT INTO t2 values(101,101);
672
--error ER_DUP_ENTRY
673
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
674
SELECT * from t2;
675
ROLLBACK;
676
SELECT * from t2;
677
TRUNCATE table t2;
678
--error ER_DUP_ENTRY
679
INSERT INTO t2 select * from t1;
680
SELECT * from t2;
681
drop table t1,t2;
682
683
#
684
# Bug#17530: Incorrect key truncation on table creation caused server crash.
685
#
520.1.16 by Brian Aker
More test updates (one ulong fix)
686
create table t1(f1 varchar(800) not null, key(f1));
1 by brian
clean slate
687
insert into t1 values('aaa');
688
drop table t1;
689
690
691
#
692
# Bug#22781: SQL_BIG_RESULT fails to influence sort plan
693
#
694
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
695
696
INSERT INTO t1 VALUES (    1 , 1              , 1);
697
INSERT INTO t1 SELECT  a + 1 , MOD(a + 1 , 20), 1 FROM t1;
698
INSERT INTO t1 SELECT  a + 2 , MOD(a + 2 , 20), 1 FROM t1;
699
INSERT INTO t1 SELECT  a + 4 , MOD(a + 4 , 20), 1 FROM t1;
700
INSERT INTO t1 SELECT  a + 8 , MOD(a + 8 , 20), 1 FROM t1;
701
INSERT INTO t1 SELECT  a + 16, MOD(a + 16, 20), 1 FROM t1;
702
INSERT INTO t1 SELECT  a + 32, MOD(a + 32, 20), 1 FROM t1;
703
INSERT INTO t1 SELECT  a + 64, MOD(a + 64, 20), 1 FROM t1;
704
705
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
706
EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
707
DROP TABLE t1;
708
709
--source include/innodb_rollback_on_timeout.inc
710
711
#
712
# Bug #28591: MySQL need not sort the records in case of ORDER BY
713
# primary_key on InnoDB table
714
#
715
716
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB;
717
INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
718
INSERT INTO t1 SELECT a + 8, 2 FROM t1;
719
INSERT INTO t1 SELECT a + 16, 1 FROM t1;
720
query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a;
721
SELECT * FROM t1 WHERE b=2 ORDER BY a;
722
query_vertical EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
723
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
724
query_vertical EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
725
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
726
727
CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c))
728
  ENGINE=InnoDB;
729
INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1);
730
INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2;
731
INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2;
732
733
query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
734
SELECT * FROM t2 WHERE b=1 ORDER BY a;
735
query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
736
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
737
query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
738
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
739
query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
740
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
741
742
DROP TABLE t1,t2;
743
744
745
#
746
# Bug #28125: ERROR 2013 when adding index.
747
#
520.1.16 by Brian Aker
More test updates (one ulong fix)
748
create table t1(a text) engine=innodb;
1 by brian
clean slate
749
insert into t1 values('aaa');
750
alter table t1 add index(a(1024));
751
show create table t1;
752
drop table t1;
753
754
#
755
# Bug #28570: handler::index_read() is called with different find_flag when 
756
# ORDER BY is used
757
#
758
759
CREATE TABLE t1 (
760
  a INT,
761
  b INT,
762
  KEY (b)
763
) ENGINE=InnoDB;
764
765
INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
766
767
START TRANSACTION;
768
SELECT * FROM t1 WHERE b=20 FOR UPDATE;
769
770
--connect (conn2, localhost, root,,test)
771
772
# This statement gives a "failed: 1205: Lock wait timeout exceeded; try 
773
# restarting transaction" message when the bug is present.
774
START TRANSACTION;
775
SELECT * FROM t1 WHERE b=10 ORDER BY A FOR UPDATE;
776
ROLLBACK;
777
778
--disconnect conn2
779
--connection default
780
781
ROLLBACK;
782
DROP TABLE t1;
783
784
#
785
# Bug#30596: GROUP BY optimization gives wrong result order
786
#  
787
CREATE TABLE t1(
788
  a INT, 
789
  b INT NOT NULL, 
790
  c INT NOT NULL, 
791
  d INT, 
792
  UNIQUE KEY (c,b)
793
) engine=innodb;
794
795
INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
796
797
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
798
SELECT c,b,d FROM t1 GROUP BY c,b,d;
799
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
800
SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
801
EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
802
SELECT c,b,d FROM t1 ORDER BY c,b,d;
803
804
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
805
SELECT c,b,d FROM t1 GROUP BY c,b;
806
EXPLAIN SELECT c,b   FROM t1 GROUP BY c,b;
807
SELECT c,b   FROM t1 GROUP BY c,b;
808
809
DROP TABLE t1;
810
811
#
812
# Bug #31001: ORDER BY DESC in InnoDB not working
813
#
814
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
815
INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
816
817
#The two queries below should produce different results, but they don't.
818
query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
819
SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
820
query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
821
SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
822
823
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
824
SELECT * FROM t1 ORDER BY b ASC, a ASC;
825
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
826
SELECT * FROM t1 ORDER BY b DESC, a DESC;
827
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
828
SELECT * FROM t1 ORDER BY b ASC, a DESC;
829
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
830
SELECT * FROM t1 ORDER BY b DESC, a ASC;
831
832
DROP TABLE t1;
833
834
###########################################################################
835
836
--echo
837
--echo #
838
--echo # Bug#27610: ALTER TABLE ROW_FORMAT=... does not rebuild the table.
839
--echo #
840
841
--echo
842
--echo # - prepare;
843
--echo
844
845
--disable_warnings
846
DROP TABLE IF EXISTS t1;
847
--enable_warnings
848
849
--echo
850
851
CREATE TABLE t1(c INT)
852
  ENGINE = InnoDB
853
  ROW_FORMAT = COMPACT;
854
855
--echo
856
--echo # - initial check;
857
--echo
858
859
SELECT table_schema, table_name, row_format
1273.13.41 by Brian Aker
Updating from additional schemas added.
860
FROM data_dictionary.TABLES
1 by brian
clean slate
861
WHERE table_schema = DATABASE() AND table_name = 't1';
862
863
--echo
864
--echo # - change ROW_FORMAT and check;
865
--echo
866
867
ALTER TABLE t1 ROW_FORMAT = REDUNDANT;
868
869
--echo
870
871
SELECT table_schema, table_name, row_format
1273.13.41 by Brian Aker
Updating from additional schemas added.
872
FROM data_dictionary.TABLES
1 by brian
clean slate
873
WHERE table_schema = DATABASE() AND table_name = 't1';
874
875
--echo
876
--echo # - that's it, cleanup.
877
--echo
878
879
DROP TABLE t1;
880
881
###########################################################################
882
883
#
884
# Bug #31137: Assertion failed: primary_key_no == -1 || primary_key_no == 0
885
#
886
create table t1(a char(10) not null, unique key aa(a(1)),
887
                b char(4) not null, unique key bb(b(4))) engine=innodb;
888
desc t1;
889
show create table t1;
890
drop table t1;
891
892
#
893
# Bug #32815: query with ORDER BY and a possible ref_or_null access
894
#
895
896
CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB;
897
INSERT INTO t1 VALUES 
898
  (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2); 
899
900
EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
901
SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
902
903
DROP TABLE t1;
904
905
#
906
# Bug #34223: Assertion failed: (optp->var_type & 127) == 8,
907
#             file .\my_getopt.c, line 830
908
#
909
910
set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
911
set global innodb_autoextend_increment=8;
912
set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
913
914
set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
915
set global innodb_commit_concurrency=0;
916
set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
917
918
--echo End of 5.0 tests
919
920
# Fix for BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY
921
# UPDATE": if the row is updated, it's like a regular UPDATE:
922
# LAST_INSERT_ID() is not affected.
923
CREATE TABLE `t2` (
520.1.16 by Brian Aker
More test updates (one ulong fix)
924
  `k` int NOT NULL auto_increment,
925
  `a` int default NULL,
926
  `c` int default NULL,
1 by brian
clean slate
927
  PRIMARY KEY  (`k`),
928
  UNIQUE KEY `idx_1` (`a`)
929
);
930
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
931
ifnull( c,
932
0 ) + 1;
933
insert into t2 ( a ) values ( 7 ) on duplicate key update c =
934
ifnull( c,
935
0 ) + 1;
936
select last_insert_id();
937
select * from t2;
938
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
939
ifnull( c,
940
0 ) + 1;
941
select last_insert_id();
942
# test again when last_insert_id() is 0 initially
943
select last_insert_id(0);
944
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
945
ifnull( c,
946
0 ) + 1;
947
select last_insert_id();
948
select * from t2;
949
950
# Test of LAST_INSERT_ID() when autogenerated will fail:
951
# last_insert_id() should not change
952
insert ignore into t2 values (null,6,1),(10,8,1);
953
select last_insert_id();
954
# First and second autogenerated will fail, last_insert_id() should
955
# point to third
956
insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
957
select last_insert_id();
958
select * from t2;
959
960
# Test of the workaround which enables people to know the id of the
961
# updated row in INSERT ON DUPLICATE KEY UPDATE, by using
962
# LAST_INSERT_ID(autoinc_col) in the UPDATE clause.
963
964
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
965
ifnull( c,
966
0 ) + 1, k=last_insert_id(k);
967
select last_insert_id();
968
select * from t2;
969
970
drop table t2;
971
972
973
#
974
# Bug#29310: An InnoDB table was updated when the data wasn't actually changed.
975
#
976
create table t1(f1 varchar(5) unique, f2 timestamp NOT NULL DEFAULT
977
  CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
978
insert into t1(f1) values(1);
979
--replace_column 1 #
980
select @a:=f2 from t1;
981
update t1 set f1=1;
982
--replace_column 1 #
983
select @b:=f2 from t1;
984
select if(@a=@b,"ok","wrong");
985
insert into t1(f1) values (1) on duplicate key update f1="1";
986
--replace_column 1 #
987
select @b:=f2 from t1;
988
select if(@a=@b,"ok","wrong");
989
insert into t1(f1) select f1 from t1 on duplicate key update f1="1";
990
--replace_column 1 #
991
select @b:=f2 from t1;
992
select if(@a=@b,"ok","wrong");
993
drop table t1;
994
995
# Bug#30747 Create table with identical constraint names behaves incorrectly
996
#
997
998
if ($test_foreign_keys)
999
{
1000
  CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b)) engine=innodb;
1001
  --error ER_WRONG_FK_DEF
1002
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1003
                  CONSTRAINT c2 FOREIGN KEY f2 (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
1004
  --error ER_WRONG_FK_DEF
1005
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1006
                  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
1007
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1008
                  CONSTRAINT c1 FOREIGN KEY c2 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
1009
                  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
1010
  ALTER TABLE t2 DROP FOREIGN KEY c2;
1011
  DROP TABLE t2;
1012
  --error ER_WRONG_FK_DEF
1013
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1014
                  FOREIGN KEY (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
1015
  --error ER_WRONG_FK_DEF
1016
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1017
                  FOREIGN KEY f1 (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
1018
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1019
                  CONSTRAINT c1 FOREIGN KEY f1 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
1020
                  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
1021
                  FOREIGN KEY f3 (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
1022
                  FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
1023
  SHOW CREATE TABLE t2;
1024
  DROP TABLE t2;
1025
  DROP TABLE t1;
1026
}
1027
1028
#
1029
# Bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB and 
1030
#             auto_increment keys
1031
#
1032
create table t1 (a int auto_increment primary key) engine=innodb;
520.1.16 by Brian Aker
More test updates (one ulong fix)
1033
--error 1105
1 by brian
clean slate
1034
alter table t1 order by a;
1035
drop table t1;
1036
1037
#
1038
# Bug #33697: ORDER BY primary key DESC vs. ref access + filesort
1039
# (reproduced only with InnoDB tables)
1040
#
1041
1042
CREATE TABLE t1
1043
  (vid integer NOT NULL,
1044
   tid integer NOT NULL,
1045
   idx integer NOT NULL,
1046
   name varchar(128) NOT NULL,
1047
   type varchar(128) NULL,
1048
   PRIMARY KEY(idx, vid, tid),
1049
   UNIQUE(vid, tid, name)
1050
) ENGINE=InnoDB;
1051
1052
INSERT INTO t1 VALUES
1053
  (1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL),
1054
  (5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL),
1055
  (4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL),
1056
  (4,1,3,'pk',NULL),(5,1,3,'c2',NULL),
1057
  (2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL);
1058
1059
EXPLAIN SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
1060
1061
SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
1062
1063
DROP TABLE t1;
1064
1065
#
1066
# Bug#21704: Renaming column does not update FK definition.
1067
#
1068
1069
--disable_warnings
1070
DROP TABLE IF EXISTS t1;
1071
DROP TABLE IF EXISTS t2;
1072
--enable_warnings
1073
1074
CREATE TABLE t1(id INT PRIMARY KEY)
1075
  ENGINE=innodb;
1076
1077
CREATE TABLE t2(
1078
  t1_id INT PRIMARY KEY,
1079
  CONSTRAINT fk1 FOREIGN KEY (t1_id) REFERENCES t1(id))
1080
  ENGINE=innodb;
1081
1082
--echo
1083
1084
--disable_result_log
1085
--error ER_ERROR_ON_RENAME
1086
ALTER TABLE t1 CHANGE id id2 INT;
1087
--enable_result_log
1088
1089
--echo
1090
1091
DROP TABLE t2;
1092
DROP TABLE t1;
1093
1094
--echo End of 5.1 tests