~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/include/mix1.inc

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 (
38
 
  c_id int not null default '0',
39
 
  org_id int default null,
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 (
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,
59
 
  activedate timestamp null default null,
60
 
  expiredate timestamp null default null,
61
 
  state int default null,
62
 
  sla_set int default null,
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.
112
 
SELECT STRAIGHT_JOIN t1.b, t1.a FROM t1, t3, t2 WHERE
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
117
 
SELECT STRAIGHT_JOIN t1.b, t1.a FROM t1, t3, t2 WHERE
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)
155
 
  ENGINE=INNODB;
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)
163
 
  ENGINE=INNODB;
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)
171
 
  ENGINE=INNODB;
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
 
  a3 time DEFAULT NULL,
186
 
  a4 blob,
187
 
  a5 char(175) DEFAULT NULL,
188
 
  a6 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
189
 
  a7 blob,
190
 
  INDEX idx (a6,a7(239),a5)
191
 
) ENGINE=InnoDB;
192
 
 
193
 
EXPLAIN SELECT a4 FROM t1 WHERE
194
 
a6=NULL AND
195
 
a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
196
 
 
197
 
EXPLAIN SELECT t1.a4 FROM t1, t1 t WHERE
198
 
t.a6=t.a6 AND t1.a6=NULL AND
199
 
t1.a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
200
 
 
201
 
DROP TABLE t1;
202
 
 
203
 
#
204
 
# Bug #12882    min/max inconsistent on empty table
205
 
#
206
 
 
207
 
--disable_warnings
208
 
eval create table t1m (a int) engine = $other_engine_type;
209
 
create table t1i (a int);
210
 
eval create table t2m (a int) engine = $other_engine_type;
211
 
create table t2i (a int);
212
 
--enable_warnings
213
 
insert into t2m values (5);
214
 
insert into t2i values (5);
215
 
 
216
 
select 1, min(a) from t1i where a=99;
217
 
select 1, min(a) from t1i where 1=99;
218
 
select 1, min(1) from t1i where a=99;
219
 
select 1, min(1) from t1i where 1=99;
220
 
 
221
 
select 1, max(a) from t1i where a=99;
222
 
select 1, max(a) from t1i where 1=99;
223
 
select 1, max(1) from t1i where a=99;
224
 
select 1, max(1) from t1i where 1=99;
225
 
 
226
 
# mixed $engine_type/$other_engine_type test
227
 
explain select count(*), min(7), max(7) from t1m, t1i;
228
 
select count(*), min(7), max(7) from t1m, t1i;
229
 
 
230
 
explain select count(*), min(7), max(7) from t1m, t2i;
231
 
select count(*), min(7), max(7) from t1m, t2i;
232
 
 
233
 
explain select count(*), min(7), max(7) from t2m, t1i;
234
 
select count(*), min(7), max(7) from t2m, t1i;
235
 
 
236
 
drop table t1m, t1i, t2m, t2i;
237
 
 
238
 
#
239
 
# Bug #12882: primary key implcitly included in every innodb index
240
 
# (was part of group_min_max.test)
241
 
#
242
 
 
243
 
eval create table t1 (
244
 
  a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
245
 
) ENGINE = $other_engine_type;
246
 
 
247
 
insert into t1 (a1, a2, b, c, d) values
248
 
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
249
 
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
250
 
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
251
 
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
252
 
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
253
 
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
254
 
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
255
 
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
256
 
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
257
 
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
258
 
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
259
 
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
260
 
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
261
 
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
262
 
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
263
 
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
264
 
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
265
 
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
266
 
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
267
 
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
268
 
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
269
 
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
270
 
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
271
 
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
272
 
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
273
 
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
274
 
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
275
 
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
276
 
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
277
 
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
278
 
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
279
 
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
280
 
--disable_warnings
281
 
create table t4 (
282
 
  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 ' '
283
 
);
284
 
--enable_warnings
285
 
insert into t4 (a1, a2, b, c, d, dummy) select * from t1;
286
 
 
287
 
create index idx12672_0 on t4 (a1);
288
 
create index idx12672_1 on t4 (a1,a2,b,c);
289
 
create index idx12672_2 on t4 (a1,a2,b);
290
 
analyze table t4;
291
 
 
292
 
select distinct a1 from t4 where pk_col not in (1,2,3,4);
293
 
 
294
 
drop table t1,t4;
295
 
 
296
 
 
297
 
#
298
 
# BUG#18819: DELETE IGNORE hangs on foreign key parent delete
299
 
#
300
 
# The bug itself does not relate to InnoDB, but we have to use foreign
301
 
# keys to reproduce it.
302
 
#
303
 
--disable_warnings
304
 
DROP TABLE IF EXISTS t2, t1;
305
 
--enable_warnings
306
 
 
307
 
CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE= InnoDB;
308
 
CREATE TABLE t2 (
309
 
  i INT NOT NULL,
310
 
  FOREIGN KEY (i) REFERENCES t1 (i) ON DELETE NO ACTION
311
 
) ENGINE= InnoDB;
312
 
 
313
 
INSERT INTO t1 VALUES (1);
314
 
INSERT INTO t2 VALUES (1);
315
 
 
316
 
DELETE IGNORE FROM t1 WHERE i = 1;
317
 
 
318
 
SELECT * FROM t1, t2;
319
 
 
320
 
DROP TABLE t2, t1;
321
 
 
322
 
 
323
 
--echo End of 4.1 tests.
324
 
 
325
 
 
326
 
#
327
 
# Bug #6142: a problem with the empty innodb table
328
 
# (was part of group_min_max.test)
329
 
#
330
 
 
331
 
--disable_warnings
332
 
create table t1 (
333
 
  a varchar(30), b varchar(30), primary key(a), key(b)
334
 
);
335
 
--enable_warnings
336
 
select distinct a from t1;
337
 
drop table t1;
338
 
 
339
 
#
340
 
# Bug #9798: group by with rollup
341
 
# (was part of group_min_max.test)
342
 
#
343
 
 
344
 
--disable_warnings
345
 
create table t1(a int, key(a));
346
 
--enable_warnings
347
 
insert into t1 values(1);
348
 
select a, count(a) from t1 group by a with rollup;
349
 
drop table t1;
350
 
 
351
 
#
352
 
# Bug #13293 Wrongly used index results in endless loop.
353
 
# (was part of group_min_max.test)
354
 
#
355
 
create table t1 (f1 int, f2 char(1), primary key(f1,f2));
356
 
insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
357
 
alter table t1 drop primary key, add primary key (f2, f1);
358
 
explain select distinct f1 a, f1 b from t1;
359
 
explain select distinct f1, f2 from t1;
360
 
drop table t1;
361
 
 
362
 
#
363
 
# Test for bug #17164: ORed FALSE blocked conversion of outer join into join
364
 
#
365
 
 
366
 
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, name varchar(20),
367
 
                 INDEX (name));
368
 
CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, fkey int);
369
 
# CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, fkey int,
370
 
#                  FOREIGN KEY (fkey) REFERENCES t2(id));
371
 
if ($test_foreign_keys)
372
 
{
373
 
   ALTER TABLE t2 ADD FOREIGN KEY (fkey) REFERENCES t2(id);
374
 
}
375
 
INSERT INTO t1 VALUES (1,'A1'),(2,'A2'),(3,'B');
376
 
INSERT INTO t2 VALUES (1,1),(2,2),(3,2),(4,3),(5,3);
377
 
 
378
 
EXPLAIN
379
 
SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
380
 
  WHERE t1.name LIKE 'A%';
381
 
 
382
 
EXPLAIN
383
 
SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
384
 
  WHERE t1.name LIKE 'A%' OR FALSE;
385
 
 
386
 
DROP TABLE t1,t2;
387
 
 
388
 
#
389
 
# Bug#26159: crash for a loose scan of a table that has been emptied 
390
 
#
391
 
 
392
 
CREATE TABLE t1 (
393
 
  id int NOT NULL,
394
 
  name varchar(20) NOT NULL,
395
 
  dept varchar(20) NOT NULL,
396
 
  age int NOT NULL,
397
 
  PRIMARY KEY (id),
398
 
  INDEX (name,dept)
399
 
) ENGINE=InnoDB;
400
 
INSERT INTO t1(id, dept, age, name) VALUES
401
 
  (3987, 'cs1', 10, 'rs1'), (3988, 'cs2', 20, 'rs1'), (3995, 'cs3', 10, 'rs2'),
402
 
  (3996, 'cs4', 20, 'rs2'), (4003, 'cs5', 10, 'rs3'), (4004, 'cs6', 20, 'rs3'),
403
 
  (4011, 'cs7', 10, 'rs4'), (4012, 'cs8', 20, 'rs4'), (4019, 'cs9', 10, 'rs5'),
404
 
  (4020, 'cs10', 20, 'rs5'),(4027, 'cs11', 10, 'rs6'),(4028, 'cs12', 20, 'rs6');
405
 
 
406
 
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
407
 
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
408
 
DELETE FROM t1;
409
 
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
410
 
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
411
 
 
412
 
DROP TABLE t1;
413
 
 
414
 
--source include/innodb_rollback_on_timeout.inc
415
 
 
416
 
#
417
 
# Bug #27210: INNODB ON DUPLICATE KEY UPDATE
418
 
#
419
 
 
420
 
connect (con1,localhost,root,,);
421
 
connection con1;
422
 
drop table if exists `test`;
423
 
CREATE TABLE `test` (`test1` varchar(3) NOT NULL,
424
 
  `test2` varchar(4) NOT NULL,PRIMARY KEY  (`test1`))
425
 
  ENGINE=InnoDB;
426
 
INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '5678');
427
 
disconnect con1;
428
 
connect (con2,localhost,root,,);
429
 
connection con2;
430
 
select * from test;
431
 
INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '1234')
432
 
  ON DUPLICATE KEY UPDATE `test2` = '1234';
433
 
select * from test;
434
 
flush tables;
435
 
select * from test;
436
 
disconnect con2;
437
 
connection default;
438
 
drop table test;
439
 
 
440
 
--source include/innodb_rollback_on_timeout.inc
441
 
 
442
 
#
443
 
# Bug #27650: INSERT fails after multi-row INSERT of the form:
444
 
# INSERT INTO t (id...) VALUES (NULL...) ON DUPLICATE KEY UPDATE id=VALUES(id)
445
 
#
446
 
 
447
 
create table t1(
448
 
id int auto_increment,
449
 
c char(1) not null,
450
 
counter int not null default 1,
451
 
primary key (id),
452
 
unique key (c)
453
 
) engine=innodb;
454
 
 
455
 
insert into t1 (id, c) values
456
 
(NULL, 'a'),
457
 
(NULL, 'a')
458
 
on duplicate key update id = values(id), counter = counter + 1;
459
 
 
460
 
select * from t1;
461
 
 
462
 
insert into t1 (id, c) values
463
 
(NULL, 'b')
464
 
on duplicate key update id = values(id), counter = counter + 1;
465
 
 
466
 
select * from t1;
467
 
 
468
 
truncate table t1;
469
 
 
470
 
insert into t1 (id, c) values (NULL, 'a');
471
 
 
472
 
select * from t1;
473
 
 
474
 
insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
475
 
on duplicate key update id = values(id), c = values(c), counter = counter + 1;
476
 
 
477
 
select * from t1;
478
 
 
479
 
insert into t1 (id, c) values (NULL, 'a')
480
 
on duplicate key update id = values(id), c = values(c), counter = counter + 1;
481
 
 
482
 
select * from t1;
483
 
 
484
 
drop table t1;
485
 
 
486
 
# Test needs to be rewritten to not use divide by zero
487
 
##
488
 
## Bug #28189: optimizer erroniously prefers ref access to range access 
489
 
##             for an InnoDB table
490
 
##
491
 
#
492
 
#CREATE TABLE t1(
493
 
#  id int AUTO_INCREMENT PRIMARY KEY,
494
 
#  stat_id int NOT NULL,
495
 
#  acct_id int DEFAULT NULL,
496
 
#  INDEX idx1 (stat_id, acct_id),
497
 
#  INDEX idx2 (acct_id)
498
 
#) ENGINE=MyISAM;
499
 
#
500
 
#CREATE TABLE t2(
501
 
#  id int AUTO_INCREMENT PRIMARY KEY,
502
 
#  stat_id int NOT NULL,
503
 
#  acct_id int DEFAULT NULL,
504
 
#  INDEX idx1 (stat_id, acct_id),
505
 
#  INDEX idx2 (acct_id)
506
 
#) ENGINE=InnoDB;
507
 
#
508
 
#INSERT INTO t1(stat_id,acct_id) VALUES
509
 
#  (1,759), (2,831), (3,785), (4,854), (1,921),
510
 
#  (1,553), (2,589), (3,743), (2,827), (2,545),
511
 
#  (4,779), (4,783), (1,597), (1,785), (4,832),
512
 
#  (1,741), (1,833), (3,788), (2,973), (1,907);
513
 
#
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
 
#INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
525
 
#UPDATE t1 SET acct_id=785 
526
 
#  WHERE MOD(stat_id,2)=0 AND MOD(id,stat_id)=MOD(acct_id,stat_id);
527
 
#OPTIMIZE TABLE t1;
528
 
#
529
 
#SELECT COUNT(*) FROM t1;
530
 
#SELECT COUNT(*) FROM t1 WHERE acct_id=785;
531
 
#
532
 
#EXPLAIN SELECT COUNT(*) FROM t1 WHERE stat_id IN (1,3) AND acct_id=785; 
533
 
#
534
 
#INSERT INTO t2 SELECT * FROM t1;
535
 
#OPTIMIZE TABLE t2;
536
 
#
537
 
#EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
538
 
#
539
 
#DROP TABLE t1,t2; 
540
 
#
541
 
#
542
 
# Bug #28652: assert when alter innodb table operation
543
 
#
544
 
create table t1(a int) engine=innodb;
545
 
alter table t1 comment '123';
546
 
show create table t1;
547
 
drop table t1;
548
 
 
549
 
#
550
 
# Bug #25866: Getting "#HY000 Can't find record in..." on and INSERT
551
 
#
552
 
CREATE TABLE t1 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
553
 
INSERT INTO t1 VALUES ('uk'),('bg');
554
 
SELECT * FROM t1 WHERE a = 'uk';
555
 
DELETE FROM t1 WHERE a = 'uk';
556
 
SELECT * FROM t1 WHERE a = 'uk';
557
 
UPDATE t1 SET a = 'us' WHERE a = 'uk';
558
 
SELECT * FROM t1 WHERE a = 'uk';
559
 
 
560
 
CREATE TABLE t2 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
561
 
INSERT INTO t2 VALUES ('uk'),('bg');
562
 
SELECT * FROM t2 WHERE a = 'uk';
563
 
DELETE FROM t2 WHERE a = 'uk';
564
 
SELECT * FROM t2 WHERE a = 'uk';
565
 
INSERT INTO t2 VALUES ('uk');
566
 
UPDATE t2 SET a = 'us' WHERE a = 'uk';
567
 
SELECT * FROM t2 WHERE a = 'uk';
568
 
 
569
 
CREATE TABLE t3 (a CHAR(2), KEY (a)) ENGINE = MyISAM;
570
 
INSERT INTO t3 VALUES ('uk'),('bg');
571
 
SELECT * FROM t3 WHERE a = 'uk';
572
 
DELETE FROM t3 WHERE a = 'uk';
573
 
SELECT * FROM t3 WHERE a = 'uk';
574
 
INSERT INTO t3 VALUES ('uk');
575
 
UPDATE t3 SET a = 'us' WHERE a = 'uk';
576
 
SELECT * FROM t3 WHERE a = 'uk';
577
 
 
578
 
DROP TABLE t1,t2,t3;
579
 
 
580
 
#
581
 
# Test bug when trying to drop data file which no InnoDB directory entry
582
 
#
583
 
 
584
 
create table t1 (a int) engine=innodb;
585
 
copy_file $MYSQLTEST_VARDIR/master-data/test/t1.frm $MYSQLTEST_VARDIR/master-data/test/bug29807.frm;
586
 
--error 1146
587
 
select * from bug29807;
588
 
drop table t1;
589
 
--error 1051
590
 
drop table bug29807;
591
 
create table bug29807 (a int);
592
 
drop table bug29807;
593
 
 
594
 
 
595
 
#
596
 
# Bug #29154: LOCK TABLES is not atomic when >1 InnoDB tables are locked
597
 
#
598
 
 
599
 
CREATE TABLE t1 (a INT) ENGINE=InnoDB; 
600
 
CREATE TABLE t2 (a INT) ENGINE=InnoDB; 
601
 
 
602
 
CONNECT (c1,localhost,root,,);
603
 
CONNECT (c2,localhost,root,,);
604
 
 
605
 
--echo switch to connection c1
606
 
CONNECTION c1;
607
 
SET AUTOCOMMIT=0;
608
 
INSERT INTO t2 VALUES (1);
609
 
 
610
 
--echo switch to connection c2
611
 
CONNECTION c2;
612
 
SET AUTOCOMMIT=0;
613
 
--error ER_LOCK_WAIT_TIMEOUT
614
 
LOCK TABLES t1 READ, t2 READ;
615
 
 
616
 
--echo switch to connection c1
617
 
CONNECTION c1;
618
 
COMMIT;
619
 
INSERT INTO t1 VALUES (1);
620
 
 
621
 
--echo switch to connection default
622
 
CONNECTION default;
623
 
SET AUTOCOMMIT=default;
624
 
DISCONNECT c1;
625
 
DISCONNECT c2;
626
 
DROP TABLE t1,t2;
627
 
 
628
 
#
629
 
# Bug #25798: a query with forced index merge returns wrong result 
630
 
#
631
 
 
632
 
CREATE TABLE t1 (
633
 
  id int NOT NULL auto_increment PRIMARY KEY,
634
 
  b int NOT NULL,
635
 
  c datetime NOT NULL,
636
 
  INDEX idx_b(b),
637
 
  INDEX idx_c(c)
638
 
) ENGINE=InnoDB;
639
 
 
640
 
CREATE TABLE t2 (
641
 
  b int NOT NULL auto_increment PRIMARY KEY,
642
 
  c datetime NOT NULL
643
 
) ENGINE= MyISAM;
644
 
 
645
 
INSERT INTO t2(c) VALUES ('2007-01-01');
646
 
INSERT INTO t2(c) SELECT c FROM t2;
647
 
INSERT INTO t2(c) SELECT c FROM t2;
648
 
INSERT INTO t2(c) SELECT c FROM t2;
649
 
INSERT INTO t2(c) SELECT c FROM t2;
650
 
INSERT INTO t2(c) SELECT c FROM t2;
651
 
INSERT INTO t2(c) SELECT c FROM t2;
652
 
INSERT INTO t2(c) SELECT c FROM t2;
653
 
INSERT INTO t2(c) SELECT c FROM t2;
654
 
INSERT INTO t2(c) SELECT c FROM t2;
655
 
INSERT INTO t2(c) SELECT c FROM t2;
656
 
 
657
 
INSERT INTO t1(b,c) SELECT b,c FROM t2;
658
 
UPDATE t2 SET c='2007-01-02';
659
 
INSERT INTO t1(b,c) SELECT b,c FROM t2;
660
 
UPDATE t2 SET c='2007-01-03';
661
 
INSERT INTO t1(b,c) SELECT b,c FROM t2;
662
 
 
663
 
set @@sort_buffer_size=8192;
664
 
 
665
 
SELECT COUNT(*) FROM t1;
666
 
 
667
 
--replace_column 9 #
668
 
EXPLAIN 
669
 
SELECT COUNT(*) FROM t1 
670
 
  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
671
 
SELECT COUNT(*) FROM t1 
672
 
  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
673
 
 
674
 
--replace_column 9 #
675
 
EXPLAIN 
676
 
SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c) 
677
 
  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
678
 
SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
679
 
  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
680
 
 
681
 
set @@sort_buffer_size=default;
682
 
 
683
 
DROP TABLE t1,t2;
684
 
 
685
 
# Test of behaviour with CREATE ... SELECT
686
 
#
687
 
 
688
 
CREATE TABLE t1 (a int, b int);
689
 
insert into t1 values (1,1),(1,2);
690
 
--error ER_DUP_ENTRY
691
 
CREATE TABLE t2 (primary key (a)) select * from t1;
692
 
# This should give warning
693
 
drop table if exists t2;
694
 
--error ER_DUP_ENTRY
695
 
CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
696
 
# This should give warning
697
 
drop table if exists t2;
698
 
CREATE TABLE t2 (a int, b int, primary key (a));
699
 
BEGIN;
700
 
INSERT INTO t2 values(100,100);
701
 
--error ER_DUP_ENTRY
702
 
CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
703
 
SELECT * from t2;
704
 
ROLLBACK;
705
 
SELECT * from t2;
706
 
TRUNCATE table t2;
707
 
--error ER_DUP_ENTRY
708
 
INSERT INTO t2 select * from t1;
709
 
SELECT * from t2;
710
 
drop table t2;
711
 
 
712
 
CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
713
 
BEGIN;
714
 
INSERT INTO t2 values(100,100);
715
 
--error ER_DUP_ENTRY
716
 
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
717
 
SELECT * from t2;
718
 
COMMIT;
719
 
BEGIN;
720
 
INSERT INTO t2 values(101,101);
721
 
--error ER_DUP_ENTRY
722
 
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
723
 
SELECT * from t2;
724
 
ROLLBACK;
725
 
SELECT * from t2;
726
 
TRUNCATE table t2;
727
 
--error ER_DUP_ENTRY
728
 
INSERT INTO t2 select * from t1;
729
 
SELECT * from t2;
730
 
drop table t1,t2;
731
 
 
732
 
#
733
 
# Bug#17530: Incorrect key truncation on table creation caused server crash.
734
 
#
735
 
create table t1(f1 varchar(800) not null, key(f1));
736
 
insert into t1 values('aaa');
737
 
drop table t1;
738
 
 
739
 
 
740
 
#
741
 
# Bug#22781: SQL_BIG_RESULT fails to influence sort plan
742
 
#
743
 
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
744
 
 
745
 
INSERT INTO t1 VALUES (    1 , 1              , 1);
746
 
INSERT INTO t1 SELECT  a + 1 , MOD(a + 1 , 20), 1 FROM t1;
747
 
INSERT INTO t1 SELECT  a + 2 , MOD(a + 2 , 20), 1 FROM t1;
748
 
INSERT INTO t1 SELECT  a + 4 , MOD(a + 4 , 20), 1 FROM t1;
749
 
INSERT INTO t1 SELECT  a + 8 , MOD(a + 8 , 20), 1 FROM t1;
750
 
INSERT INTO t1 SELECT  a + 16, MOD(a + 16, 20), 1 FROM t1;
751
 
INSERT INTO t1 SELECT  a + 32, MOD(a + 32, 20), 1 FROM t1;
752
 
INSERT INTO t1 SELECT  a + 64, MOD(a + 64, 20), 1 FROM t1;
753
 
 
754
 
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
755
 
EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
756
 
DROP TABLE t1;
757
 
 
758
 
--source include/innodb_rollback_on_timeout.inc
759
 
 
760
 
#
761
 
# Bug#27296 Assertion in ALTER TABLE SET DEFAULT in Linux Debug build
762
 
# (possible deadlock).
763
 
#
764
 
# The bug is applicable only to a transactoinal table.
765
 
# Cover with tests behavior that no longer causes an
766
 
# assertion.
767
 
#
768
 
--disable_warnings
769
 
drop table if exists t1;
770
 
--enable_warnings
771
 
create table t1 (a int) engine=innodb;
772
 
alter table t1 alter a set default 1;
773
 
drop table t1;
774
 
 
775
 
--echo
776
 
--echo Bug#24918 drop table and lock / inconsistent between 
777
 
--echo perm and temp tables
778
 
--echo
779
 
--echo Check transactional tables under LOCK TABLES
780
 
--echo
781
 
--disable_warnings
782
 
drop table if exists t24918, t24918_tmp, t24918_trans, t24918_trans_tmp, 
783
 
t24918_access;
784
 
--enable_warnings
785
 
create table t24918_access (id int);
786
 
create table t24918 (id int) engine=myisam;
787
 
create temporary table t24918_tmp (id int) engine=myisam;
788
 
create table t24918_trans (id int) engine=innodb;
789
 
create temporary table t24918_trans_tmp (id int) engine=innodb;
790
 
 
791
 
lock table t24918 write, t24918_tmp write, t24918_trans write, t24918_trans_tmp write;
792
 
drop table t24918;
793
 
--error ER_TABLE_NOT_LOCKED
794
 
select * from t24918_access;
795
 
drop table t24918_trans;
796
 
--error ER_TABLE_NOT_LOCKED
797
 
select * from t24918_access;
798
 
drop table t24918_trans_tmp;
799
 
--error ER_TABLE_NOT_LOCKED
800
 
select * from t24918_access;
801
 
drop table t24918_tmp;
802
 
--error ER_TABLE_NOT_LOCKED
803
 
select * from t24918_access;
804
 
unlock tables;
805
 
 
806
 
drop table t24918_access;
807
 
#
808
 
# Bug #28591: MySQL need not sort the records in case of ORDER BY
809
 
# primary_key on InnoDB table
810
 
#
811
 
 
812
 
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB;
813
 
INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
814
 
INSERT INTO t1 SELECT a + 8, 2 FROM t1;
815
 
INSERT INTO t1 SELECT a + 16, 1 FROM t1;
816
 
query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a;
817
 
SELECT * FROM t1 WHERE b=2 ORDER BY a;
818
 
query_vertical EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
819
 
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
820
 
query_vertical EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
821
 
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
822
 
 
823
 
CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c))
824
 
  ENGINE=InnoDB;
825
 
INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1);
826
 
INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2;
827
 
INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2;
828
 
 
829
 
query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
830
 
SELECT * FROM t2 WHERE b=1 ORDER BY a;
831
 
query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
832
 
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
833
 
query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
834
 
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
835
 
query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
836
 
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
837
 
 
838
 
DROP TABLE t1,t2;
839
 
 
840
 
 
841
 
#
842
 
# Bug #28125: ERROR 2013 when adding index.
843
 
#
844
 
create table t1(a text) engine=innodb;
845
 
insert into t1 values('aaa');
846
 
alter table t1 add index(a(1024));
847
 
show create table t1;
848
 
drop table t1;
849
 
 
850
 
#
851
 
# Bug #28570: handler::index_read() is called with different find_flag when 
852
 
# ORDER BY is used
853
 
#
854
 
 
855
 
CREATE TABLE t1 (
856
 
  a INT,
857
 
  b INT,
858
 
  KEY (b)
859
 
) ENGINE=InnoDB;
860
 
 
861
 
INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
862
 
 
863
 
START TRANSACTION;
864
 
SELECT * FROM t1 WHERE b=20 FOR UPDATE;
865
 
 
866
 
--connect (conn2, localhost, root,,test)
867
 
 
868
 
# This statement gives a "failed: 1205: Lock wait timeout exceeded; try 
869
 
# restarting transaction" message when the bug is present.
870
 
START TRANSACTION;
871
 
SELECT * FROM t1 WHERE b=10 ORDER BY A FOR UPDATE;
872
 
ROLLBACK;
873
 
 
874
 
--disconnect conn2
875
 
--connection default
876
 
 
877
 
ROLLBACK;
878
 
DROP TABLE t1;
879
 
 
880
 
#
881
 
# Bug#30596: GROUP BY optimization gives wrong result order
882
 
#  
883
 
CREATE TABLE t1(
884
 
  a INT, 
885
 
  b INT NOT NULL, 
886
 
  c INT NOT NULL, 
887
 
  d INT, 
888
 
  UNIQUE KEY (c,b)
889
 
) engine=innodb;
890
 
 
891
 
INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
892
 
 
893
 
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
894
 
SELECT c,b,d FROM t1 GROUP BY c,b,d;
895
 
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
896
 
SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
897
 
EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
898
 
SELECT c,b,d FROM t1 ORDER BY c,b,d;
899
 
 
900
 
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
901
 
SELECT c,b,d FROM t1 GROUP BY c,b;
902
 
EXPLAIN SELECT c,b   FROM t1 GROUP BY c,b;
903
 
SELECT c,b   FROM t1 GROUP BY c,b;
904
 
 
905
 
DROP TABLE t1;
906
 
 
907
 
#
908
 
# Bug #31001: ORDER BY DESC in InnoDB not working
909
 
#
910
 
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
911
 
INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
912
 
 
913
 
#The two queries below should produce different results, but they don't.
914
 
query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
915
 
SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
916
 
query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
917
 
SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
918
 
 
919
 
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
920
 
SELECT * FROM t1 ORDER BY b ASC, a ASC;
921
 
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
922
 
SELECT * FROM t1 ORDER BY b DESC, a DESC;
923
 
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
924
 
SELECT * FROM t1 ORDER BY b ASC, a DESC;
925
 
query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
926
 
SELECT * FROM t1 ORDER BY b DESC, a ASC;
927
 
 
928
 
DROP TABLE t1;
929
 
 
930
 
###########################################################################
931
 
 
932
 
--echo
933
 
--echo #
934
 
--echo # Bug#27610: ALTER TABLE ROW_FORMAT=... does not rebuild the table.
935
 
--echo #
936
 
 
937
 
--echo
938
 
--echo # - prepare;
939
 
--echo
940
 
 
941
 
--disable_warnings
942
 
DROP TABLE IF EXISTS t1;
943
 
--enable_warnings
944
 
 
945
 
--echo
946
 
 
947
 
CREATE TABLE t1(c INT)
948
 
  ENGINE = InnoDB
949
 
  ROW_FORMAT = COMPACT;
950
 
 
951
 
--echo
952
 
--echo # - initial check;
953
 
--echo
954
 
 
955
 
SELECT table_schema, table_name, row_format
956
 
FROM INFORMATION_SCHEMA.TABLES
957
 
WHERE table_schema = DATABASE() AND table_name = 't1';
958
 
 
959
 
--echo
960
 
--echo # - change ROW_FORMAT and check;
961
 
--echo
962
 
 
963
 
ALTER TABLE t1 ROW_FORMAT = REDUNDANT;
964
 
 
965
 
--echo
966
 
 
967
 
SELECT table_schema, table_name, row_format
968
 
FROM INFORMATION_SCHEMA.TABLES
969
 
WHERE table_schema = DATABASE() AND table_name = 't1';
970
 
 
971
 
--echo
972
 
--echo # - that's it, cleanup.
973
 
--echo
974
 
 
975
 
DROP TABLE t1;
976
 
 
977
 
###########################################################################
978
 
 
979
 
#
980
 
# Bug #31137: Assertion failed: primary_key_no == -1 || primary_key_no == 0
981
 
#
982
 
create table t1(a char(10) not null, unique key aa(a(1)),
983
 
                b char(4) not null, unique key bb(b(4))) engine=innodb;
984
 
desc t1;
985
 
show create table t1;
986
 
drop table t1;
987
 
 
988
 
#
989
 
# Bug #32815: query with ORDER BY and a possible ref_or_null access
990
 
#
991
 
 
992
 
CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB;
993
 
INSERT INTO t1 VALUES 
994
 
  (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2); 
995
 
 
996
 
EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
997
 
SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
998
 
 
999
 
DROP TABLE t1;
1000
 
 
1001
 
#
1002
 
# Bug #34223: Assertion failed: (optp->var_type & 127) == 8,
1003
 
#             file .\my_getopt.c, line 830
1004
 
#
1005
 
 
1006
 
set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
1007
 
set global innodb_autoextend_increment=8;
1008
 
set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
1009
 
 
1010
 
set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
1011
 
set global innodb_commit_concurrency=0;
1012
 
set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
1013
 
 
1014
 
--echo End of 5.0 tests
1015
 
 
1016
 
# Fix for BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY
1017
 
# UPDATE": if the row is updated, it's like a regular UPDATE:
1018
 
# LAST_INSERT_ID() is not affected.
1019
 
CREATE TABLE `t2` (
1020
 
  `k` int NOT NULL auto_increment,
1021
 
  `a` int default NULL,
1022
 
  `c` int default NULL,
1023
 
  PRIMARY KEY  (`k`),
1024
 
  UNIQUE KEY `idx_1` (`a`)
1025
 
);
1026
 
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1027
 
ifnull( c,
1028
 
0 ) + 1;
1029
 
insert into t2 ( a ) values ( 7 ) on duplicate key update c =
1030
 
ifnull( c,
1031
 
0 ) + 1;
1032
 
select last_insert_id();
1033
 
select * from t2;
1034
 
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1035
 
ifnull( c,
1036
 
0 ) + 1;
1037
 
select last_insert_id();
1038
 
# test again when last_insert_id() is 0 initially
1039
 
select last_insert_id(0);
1040
 
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1041
 
ifnull( c,
1042
 
0 ) + 1;
1043
 
select last_insert_id();
1044
 
select * from t2;
1045
 
 
1046
 
# Test of LAST_INSERT_ID() when autogenerated will fail:
1047
 
# last_insert_id() should not change
1048
 
insert ignore into t2 values (null,6,1),(10,8,1);
1049
 
select last_insert_id();
1050
 
# First and second autogenerated will fail, last_insert_id() should
1051
 
# point to third
1052
 
insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
1053
 
select last_insert_id();
1054
 
select * from t2;
1055
 
 
1056
 
# Test of the workaround which enables people to know the id of the
1057
 
# updated row in INSERT ON DUPLICATE KEY UPDATE, by using
1058
 
# LAST_INSERT_ID(autoinc_col) in the UPDATE clause.
1059
 
 
1060
 
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1061
 
ifnull( c,
1062
 
0 ) + 1, k=last_insert_id(k);
1063
 
select last_insert_id();
1064
 
select * from t2;
1065
 
 
1066
 
drop table t2;
1067
 
 
1068
 
 
1069
 
#
1070
 
# Tests for bug #28415 "Some ALTER TABLE statements no longer work
1071
 
# under LOCK TABLES" and some aspects of fast ALTER TABLE behaviour
1072
 
# for transactional tables.
1073
 
#
1074
 
--disable_warnings
1075
 
drop table if exists t1, t2;
1076
 
--enable_warnings
1077
 
create table t1 (i int);
1078
 
alter table t1 modify i int default 1;
1079
 
alter table t1 modify i int default 2, rename t2;
1080
 
lock table t2 write;
1081
 
alter table t2 modify i int default 3;
1082
 
unlock tables;
1083
 
lock table t2 write;
1084
 
alter table t2 modify i int default 4, rename t1;
1085
 
unlock tables;
1086
 
drop table t1;
1087
 
 
1088
 
 
1089
 
1090
 
# Some more tests for ALTER TABLE and LOCK TABLES for transactional tables.
1091
 
#
1092
 
# Table which is altered under LOCK TABLES should stay in list of locked
1093
 
# tables and be available after alter takes place unless ALTER contains
1094
 
# RENAME clause. We should see the new definition of table, of course.
1095
 
# Before 5.1 this behavior was inconsistent across the platforms and
1096
 
# different engines. See also tests in alter_table.test
1097
 
#
1098
 
--disable_warnings
1099
 
drop table if exists t1;
1100
 
--enable_warnings
1101
 
create table t1 (i int);
1102
 
insert into t1 values ();
1103
 
lock table t1 write;
1104
 
# Example of so-called 'fast' ALTER TABLE
1105
 
alter table t1 modify i int default 1;
1106
 
insert into t1 values ();
1107
 
select * from t1;
1108
 
# And now full-blown ALTER TABLE
1109
 
alter table t1 change i c char(10) default "Two";
1110
 
insert into t1 values ();
1111
 
select * from t1;
1112
 
unlock tables;
1113
 
select * from t1;
1114
 
drop tables t1;
1115
 
 
1116
 
#
1117
 
# Bug#29310: An InnoDB table was updated when the data wasn't actually changed.
1118
 
#
1119
 
create table t1(f1 varchar(5) unique, f2 timestamp NOT NULL DEFAULT
1120
 
  CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
1121
 
insert into t1(f1) values(1);
1122
 
--replace_column 1 #
1123
 
select @a:=f2 from t1;
1124
 
--sleep 5
1125
 
update t1 set f1=1;
1126
 
--replace_column 1 #
1127
 
select @b:=f2 from t1;
1128
 
select if(@a=@b,"ok","wrong");
1129
 
--sleep 5
1130
 
insert into t1(f1) values (1) on duplicate key update f1="1";
1131
 
--replace_column 1 #
1132
 
select @b:=f2 from t1;
1133
 
select if(@a=@b,"ok","wrong");
1134
 
--sleep 5
1135
 
insert into t1(f1) select f1 from t1 on duplicate key update f1="1";
1136
 
--replace_column 1 #
1137
 
select @b:=f2 from t1;
1138
 
select if(@a=@b,"ok","wrong");
1139
 
drop table t1;
1140
 
 
1141
 
# Bug#30747 Create table with identical constraint names behaves incorrectly
1142
 
#
1143
 
 
1144
 
if ($test_foreign_keys)
1145
 
{
1146
 
  CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b)) engine=innodb;
1147
 
  --error ER_WRONG_FK_DEF
1148
 
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1149
 
                  CONSTRAINT c2 FOREIGN KEY f2 (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
1150
 
  --error ER_WRONG_FK_DEF
1151
 
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1152
 
                  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
1153
 
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1154
 
                  CONSTRAINT c1 FOREIGN KEY c2 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
1155
 
                  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
1156
 
  ALTER TABLE t2 DROP FOREIGN KEY c2;
1157
 
  DROP TABLE t2;
1158
 
  --error ER_WRONG_FK_DEF
1159
 
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1160
 
                  FOREIGN KEY (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
1161
 
  --error ER_WRONG_FK_DEF
1162
 
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1163
 
                  FOREIGN KEY f1 (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
1164
 
  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1165
 
                  CONSTRAINT c1 FOREIGN KEY f1 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
1166
 
                  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
1167
 
                  FOREIGN KEY f3 (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
1168
 
                  FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
1169
 
  SHOW CREATE TABLE t2;
1170
 
  DROP TABLE t2;
1171
 
  DROP TABLE t1;
1172
 
}
1173
 
 
1174
 
#
1175
 
# Bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB and 
1176
 
#             auto_increment keys
1177
 
#
1178
 
create table t1 (a int auto_increment primary key) engine=innodb;
1179
 
--error 1105
1180
 
alter table t1 order by a;
1181
 
drop table t1;
1182
 
 
1183
 
#
1184
 
# Bug #33697: ORDER BY primary key DESC vs. ref access + filesort
1185
 
# (reproduced only with InnoDB tables)
1186
 
#
1187
 
 
1188
 
CREATE TABLE t1
1189
 
  (vid integer NOT NULL,
1190
 
   tid integer NOT NULL,
1191
 
   idx integer NOT NULL,
1192
 
   name varchar(128) NOT NULL,
1193
 
   type varchar(128) NULL,
1194
 
   PRIMARY KEY(idx, vid, tid),
1195
 
   UNIQUE(vid, tid, name)
1196
 
) ENGINE=InnoDB;
1197
 
 
1198
 
INSERT INTO t1 VALUES
1199
 
  (1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL),
1200
 
  (5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL),
1201
 
  (4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL),
1202
 
  (4,1,3,'pk',NULL),(5,1,3,'c2',NULL),
1203
 
  (2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL);
1204
 
 
1205
 
EXPLAIN SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
1206
 
 
1207
 
SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
1208
 
 
1209
 
DROP TABLE t1;
1210
 
 
1211
 
#
1212
 
# Bug#21704: Renaming column does not update FK definition.
1213
 
#
1214
 
 
1215
 
--disable_warnings
1216
 
DROP TABLE IF EXISTS t1;
1217
 
DROP TABLE IF EXISTS t2;
1218
 
--enable_warnings
1219
 
 
1220
 
CREATE TABLE t1(id INT PRIMARY KEY)
1221
 
  ENGINE=innodb;
1222
 
 
1223
 
CREATE TABLE t2(
1224
 
  t1_id INT PRIMARY KEY,
1225
 
  CONSTRAINT fk1 FOREIGN KEY (t1_id) REFERENCES t1(id))
1226
 
  ENGINE=innodb;
1227
 
 
1228
 
--echo
1229
 
 
1230
 
--disable_result_log
1231
 
--error ER_ERROR_ON_RENAME
1232
 
ALTER TABLE t1 CHANGE id id2 INT;
1233
 
--enable_result_log
1234
 
 
1235
 
--echo
1236
 
 
1237
 
DROP TABLE t2;
1238
 
DROP TABLE t1;
1239
 
 
1240
 
--echo End of 5.1 tests