MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mix1.inc
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 DEFAULT_STORAGE_ENGINE = $engine_type;
29 eval SET SESSION DEFAULT_TMP_STORAGE_ENGINE = $engine_type;
30 
31 --disable_warnings
32 drop table if exists t1,t2,t3,t1m,t1i,t2m,t2i,t4;
33 drop procedure if exists p1;
34 --enable_warnings
35 
36 
37 # BUG#16798: Uninitialized row buffer reads in ref-or-null optimizer
38 # (repeatable only w/innodb).
39 create table t1 (
40  c_id int(11) not null default '0',
41  org_id int(11) default null,
42  unique key contacts$c_id (c_id),
43  key contacts$org_id (org_id)
44 );
45 insert into t1 values
46  (2,null),(120,null),(141,null),(218,7), (128,1),
47  (151,2),(234,2),(236,2),(243,2),(255,2),(259,2),(232,3),(235,3),(238,3),
48  (246,3),(253,3),(269,3),(285,3),(291,3),(293,3),(131,4),(230,4),(231,4);
49 
50 create table t2 (
51  slai_id int(11) not null default '0',
52  owner_tbl int(11) default null,
53  owner_id int(11) default null,
54  sla_id int(11) default null,
55  inc_web int(11) default null,
56  inc_email int(11) default null,
57  inc_chat int(11) default null,
58  inc_csr int(11) default null,
59  inc_total int(11) default null,
60  time_billed int(11) default null,
61  activedate timestamp null default null,
62  expiredate timestamp null default null,
63  state int(11) default null,
64  sla_set int(11) default null,
65  unique key t2$slai_id (slai_id),
66  key t2$owner_id (owner_id),
67  key t2$sla_id (sla_id)
68 );
69 insert into t2(slai_id, owner_tbl, owner_id, sla_id) values
70  (1,3,1,1), (3,3,10,2), (4,3,3,6), (5,3,2,5), (6,3,8,3), (7,3,9,7),
71  (8,3,6,8), (9,3,4,9), (10,3,5,10), (11,3,11,11), (12,3,7,12);
72 
73 flush tables;
74 select si.slai_id
75 from t1 c join t2 si on
76  ((si.owner_tbl = 3 and si.owner_id = c.org_id) or
77  ( si.owner_tbl = 2 and si.owner_id = c.c_id))
78 where
79  c.c_id = 218 and expiredate is null;
80 
81 select * from t1 where org_id is null;
82 select si.slai_id
83 from t1 c join t2 si on
84  ((si.owner_tbl = 3 and si.owner_id = c.org_id) or
85  ( si.owner_tbl = 2 and si.owner_id = c.c_id))
86 where
87  c.c_id = 218 and expiredate is null;
88 
89 drop table t1, t2;
90 
91 #
92 # Bug#17212: results not sorted correctly by ORDER BY when using index
93 # (repeatable only w/innodb because of index props)
94 #
95 CREATE TABLE t1 (a int, b int, KEY b (b));
96 CREATE TABLE t2 (a int, b int, PRIMARY KEY (a,b));
97 CREATE TABLE t3 (a int, b int, c int, PRIMARY KEY (a),
98  UNIQUE KEY b (b,c), KEY a (a,b,c));
99 
100 INSERT INTO t1 VALUES (1, 1);
101 INSERT INTO t1 SELECT a + 1, b + 1 FROM t1;
102 INSERT INTO t1 SELECT a + 2, b + 2 FROM t1;
103 
104 INSERT INTO t2 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
105 INSERT INTO t2 SELECT a + 1, b FROM t2;
106 DELETE FROM t2 WHERE a = 1 AND b < 2;
107 
108 INSERT INTO t3 VALUES (1,1,1),(2,1,2);
109 INSERT INTO t3 SELECT a + 2, a + 2, 3 FROM t3;
110 INSERT INTO t3 SELECT a + 4, a + 4, 3 FROM t3;
111 
112 # demonstrate a problem when a must-use-sort table flag
113 # (sort_by_table=1) is being neglected.
114 SELECT STRAIGHT_JOIN SQL_NO_CACHE t1.b, t1.a FROM t1, t3, t2 WHERE
115  t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
116  ORDER BY t1.b LIMIT 2;
117 
118 # demonstrate the problem described in the bug report
119 SELECT STRAIGHT_JOIN SQL_NO_CACHE t1.b, t1.a FROM t1, t3, t2 WHERE
120  t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
121  ORDER BY t1.b LIMIT 5;
122 DROP TABLE t1, t2, t3;
123 
124 
125 # BUG#21077 (The testcase is not deterministic so correct execution doesn't
126 # prove anything) For proof one should track if sequence of ha_innodb::* func
127 # calls is correct.
128 CREATE TABLE `t1` (`id1` INT) ;
129 INSERT INTO `t1` (`id1`) VALUES (1),(5),(2);
130 
131 CREATE TABLE `t2` (
132  `id1` INT,
133  `id2` INT NOT NULL,
134  `id3` INT,
135  `id4` INT NOT NULL,
136  UNIQUE (`id2`,`id4`),
137  KEY (`id1`)
138 );
139 
140 INSERT INTO `t2`(`id1`,`id2`,`id3`,`id4`) VALUES
141 (1,1,1,0),
142 (1,1,2,1),
143 (5,1,2,2),
144 (6,1,2,3),
145 (1,2,2,2),
146 (1,2,1,1);
147 
148 SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = 1 AND `id3` = 2);
149 DROP TABLE t1, t2;
150 
151 #
152 # Bug #22728 - Handler_rollback value is growing
153 #
154 
155 let $before= `show status like 'Handler_rollback'`;
156 create table t1 (c1 int) engine=innodb;
157 connect (con1,localhost,root,,);
158 connect (con2,localhost,root,,);
159 connection con2;
160 handler t1 open;
161 handler t1 read first;
162 disconnect con2;
163 connection con1;
164 let $after= `show status like 'Handler_rollback'`;
165 # Compare the before and after value, it should be equal
166 --disable_query_log
167 eval select STRCMP("$before", "$after") as "Before and after comparison";
168 --enable_query_log
169 connection default;
170 drop table t1;
171 disconnect con1;
172 
173 #
174 # Bug #13191: INSERT...ON DUPLICATE KEY UPDATE of UTF-8 string fields
175 # used in partial unique indices.
176 #
177 
178 CREATE TABLE t1(c1 TEXT, UNIQUE (c1(1)), cnt INT DEFAULT 1)
179  ENGINE=INNODB CHARACTER SET UTF8;
180 INSERT INTO t1 (c1) VALUES ('1a');
181 SELECT * FROM t1;
182 INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
183 SELECT * FROM t1;
184 DROP TABLE t1;
185 
186 CREATE TABLE t1(c1 VARCHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
187  ENGINE=INNODB CHARACTER SET UTF8;
188 INSERT INTO t1 (c1) VALUES ('1a');
189 SELECT * FROM t1;
190 INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
191 SELECT * FROM t1;
192 DROP TABLE t1;
193 
194 CREATE TABLE t1(c1 CHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
195  ENGINE=INNODB CHARACTER SET UTF8;
196 INSERT INTO t1 (c1) VALUES ('1a');
197 SELECT * FROM t1;
198 INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
199 SELECT * FROM t1;
200 DROP TABLE t1;
201 
202 #
203 # Bug #28272: EXPLAIN for SELECT from an empty InnoDB table
204 #
205 
206 CREATE TABLE t1 (
207  a1 decimal(10,0) DEFAULT NULL,
208  a2 blob,
209  a3 time DEFAULT NULL,
210  a4 blob,
211  a5 char(175) DEFAULT NULL,
212  a6 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
213  a7 tinyblob,
214  INDEX idx (a6,a7(239),a5)
215 ) ENGINE=InnoDB;
216 
217 EXPLAIN SELECT a4 FROM t1 WHERE
218 a6=NULL AND
219 a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
220 
221 EXPLAIN SELECT t1.a4 FROM t1, t1 t WHERE
222 t.a6=t.a6 AND t1.a6=NULL AND
223 t1.a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
224 
225 DROP TABLE t1;
226 
227 #
228 # Bug #12882 min/max inconsistent on empty table
229 #
230 
231 --disable_warnings
232 eval create table t1m (a int) engine = $other_engine_type;
233 create table t1i (a int);
234 eval create table t2m (a int) engine = $other_engine_type;
235 create table t2i (a int);
236 --enable_warnings
237 insert into t2m values (5);
238 insert into t2i values (5);
239 
240 -- disable_query_log
241 -- disable_result_log
242 analyze table t1i;
243 analyze table t1m;
244 analyze table t2i;
245 analyze table t2m;
246 -- enable_result_log
247 -- enable_query_log
248 
249 # test with $engine_type
250 select min(a) from t1i;
251 select min(7) from t1i;
252 select min(7) from DUAL;
253 explain select min(7) from t2i join t1i;
254 select min(7) from t2i join t1i;
255 
256 select max(a) from t1i;
257 select max(7) from t1i;
258 select max(7) from DUAL;
259 explain select max(7) from t2i join t1i;
260 select max(7) from t2i join t1i;
261 
262 select 1, min(a) from t1i where a=99;
263 select 1, min(a) from t1i where 1=99;
264 select 1, min(1) from t1i where a=99;
265 select 1, min(1) from t1i where 1=99;
266 
267 select 1, max(a) from t1i where a=99;
268 select 1, max(a) from t1i where 1=99;
269 select 1, max(1) from t1i where a=99;
270 select 1, max(1) from t1i where 1=99;
271 
272 # mixed $engine_type/$other_engine_type test
273 explain select count(*), min(7), max(7) from t1m, t1i;
274 select count(*), min(7), max(7) from t1m, t1i;
275 
276 explain select count(*), min(7), max(7) from t1m, t2i;
277 select count(*), min(7), max(7) from t1m, t2i;
278 
279 explain select count(*), min(7), max(7) from t2m, t1i;
280 select count(*), min(7), max(7) from t2m, t1i;
281 
282 drop table t1m, t1i, t2m, t2i;
283 
284 #
285 # Bug #12882: primary key implcitly included in every innodb index
286 # (was part of group_min_max.test)
287 #
288 
289 eval create table t1 (
290  a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
291 ) ENGINE = $other_engine_type;
292 
293 insert into t1 (a1, a2, b, c, d) values
294 ('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
295 ('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
296 ('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
297 ('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
298 ('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
299 ('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
300 ('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
301 ('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
302 ('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
303 ('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
304 ('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
305 ('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
306 ('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
307 ('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
308 ('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
309 ('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
310 ('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
311 ('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
312 ('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
313 ('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
314 ('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
315 ('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
316 ('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
317 ('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
318 ('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
319 ('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
320 ('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
321 ('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
322 ('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
323 ('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
324 ('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
325 ('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
326 --disable_warnings
327 create table t4 (
328  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 ' '
329 );
330 --enable_warnings
331 insert into t4 (a1, a2, b, c, d, dummy) select * from t1;
332 
333 create index idx12672_0 on t4 (a1);
334 create index idx12672_1 on t4 (a1,a2,b,c);
335 create index idx12672_2 on t4 (a1,a2,b);
336 analyze table t4;
337 
338 select distinct a1 from t4 where pk_col not in (1,2,3,4);
339 
340 drop table t1,t4;
341 
342 
343 #
344 # BUG#18819: DELETE IGNORE hangs on foreign key parent delete
345 #
346 # The bug itself does not relate to InnoDB, but we have to use foreign
347 # keys to reproduce it.
348 #
349 --disable_warnings
350 DROP TABLE IF EXISTS t2, t1;
351 --enable_warnings
352 
353 CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE= InnoDB;
354 CREATE TABLE t2 (
355  i INT NOT NULL,
356  FOREIGN KEY (i) REFERENCES t1 (i) ON DELETE NO ACTION
357 ) ENGINE= InnoDB;
358 
359 INSERT INTO t1 VALUES (1);
360 INSERT INTO t2 VALUES (1);
361 
362 DELETE IGNORE FROM t1 WHERE i = 1;
363 
364 SELECT * FROM t1, t2;
365 
366 DROP TABLE t2, t1;
367 
368 
369 --echo End of 4.1 tests.
370 
371 
372 #
373 # Bug #6142: a problem with the empty innodb table
374 # (was part of group_min_max.test)
375 #
376 
377 --disable_warnings
378 create table t1 (
379  a varchar(30), b varchar(30), primary key(a), key(b)
380 );
381 --enable_warnings
382 select distinct a from t1;
383 drop table t1;
384 
385 #
386 # Bug #9798: group by with rollup
387 # (was part of group_min_max.test)
388 #
389 
390 --disable_warnings
391 create table t1(a int, key(a));
392 --enable_warnings
393 insert into t1 values(1);
394 select a, count(a) from t1 group by a with rollup;
395 drop table t1;
396 
397 #
398 # Bug #13293 Wrongly used index results in endless loop.
399 # (was part of group_min_max.test)
400 #
401 create table t1 (f1 int, f2 char(1), primary key(f1,f2)) stats_persistent=0;
402 insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
403 alter table t1 drop primary key, add primary key (f2, f1);
404 explain select distinct f1 a, f1 b from t1;
405 explain select distinct f1, f2 from t1;
406 drop table t1;
407 
408 #
409 # Test for bug #17164: ORed FALSE blocked conversion of outer join into join
410 #
411 
412 CREATE TABLE t1 (id int(11) NOT NULL PRIMARY KEY, name varchar(20),
413  INDEX (name));
414 CREATE TABLE t2 (id int(11) NOT NULL PRIMARY KEY, fkey int(11));
415 # CREATE TABLE t2 (id int(11) NOT NULL PRIMARY KEY, fkey int(11),
416 # FOREIGN KEY (fkey) REFERENCES t2(id));
417 if ($test_foreign_keys)
418 {
419  ALTER TABLE t2 ADD FOREIGN KEY (fkey) REFERENCES t2(id);
420 }
421 INSERT INTO t1 VALUES (1,'A1'),(2,'A2'),(3,'B');
422 INSERT INTO t2 VALUES (1,1),(2,2),(3,2),(4,3),(5,3);
423 
424 -- disable_query_log
425 -- disable_result_log
426 ANALYZE TABLE t1;
427 ANALYZE TABLE t2;
428 -- enable_result_log
429 -- enable_query_log
430 
431 EXPLAIN
432 SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
433  WHERE t1.name LIKE 'A%';
434 
435 EXPLAIN
436 SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
437  WHERE t1.name LIKE 'A%' OR FALSE;
438 
439 DROP TABLE t1,t2;
440 
441 #
442 # Bug#26159: crash for a loose scan of a table that has been emptied
443 #
444 
445 CREATE TABLE t1 (
446  id int NOT NULL,
447  name varchar(20) NOT NULL,
448  dept varchar(20) NOT NULL,
449  age tinyint(3) unsigned NOT NULL,
450  PRIMARY KEY (id),
451  INDEX (name,dept)
452 ) ENGINE=InnoDB STATS_PERSISTENT=0;
453 INSERT INTO t1(id, dept, age, name) VALUES
454  (3987, 'cs1', 10, 'rs1'), (3988, 'cs2', 20, 'rs1'), (3995, 'cs3', 10, 'rs2'),
455  (3996, 'cs4', 20, 'rs2'), (4003, 'cs5', 10, 'rs3'), (4004, 'cs6', 20, 'rs3'),
456  (4011, 'cs7', 10, 'rs4'), (4012, 'cs8', 20, 'rs4'), (4019, 'cs9', 10, 'rs5'),
457  (4020, 'cs10', 20, 'rs5'),(4027, 'cs11', 10, 'rs6'),(4028, 'cs12', 20, 'rs6');
458 
459 EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
460 SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
461 DELETE FROM t1;
462 --echo # Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
463 --replace_column 9 #
464 EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
465 SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
466 
467 DROP TABLE t1;
468 
469 --source include/innodb_rollback_on_timeout.inc
470 
471 #
472 # Bug #27210: INNODB ON DUPLICATE KEY UPDATE
473 #
474 
475 set @save_qcache_size=@@global.query_cache_size;
476 set @save_qcache_type=@@global.query_cache_type;
477 set global query_cache_size=10*1024*1024;
478 set global query_cache_type=1;
479 connect (con1,localhost,root,,);
480 connection con1;
481 drop table if exists `test`;
482 CREATE TABLE `test` (`test1` varchar(3) NOT NULL,
483  `test2` varchar(4) NOT NULL,PRIMARY KEY (`test1`))
484  ENGINE=InnoDB DEFAULT CHARSET=latin1;
485 INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '5678');
486 disconnect con1;
487 connect (con2,localhost,root,,);
488 connection con2;
489 select * from test;
490 INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '1234')
491  ON DUPLICATE KEY UPDATE `test2` = '1234';
492 select * from test;
493 flush tables;
494 select * from test;
495 disconnect con2;
496 connection default;
497 drop table test;
498 set global query_cache_type=@save_qcache_type;
499 set global query_cache_size=@save_qcache_size;
500 
501 --source include/innodb_rollback_on_timeout.inc
502 
503 #
504 # Bug #27650: INSERT fails after multi-row INSERT of the form:
505 # INSERT INTO t (id...) VALUES (NULL...) ON DUPLICATE KEY UPDATE id=VALUES(id)
506 #
507 
508 create table t1(
509 id int auto_increment,
510 c char(1) not null,
511 counter int not null default 1,
512 primary key (id),
513 unique key (c)
514 ) engine=innodb;
515 
516 insert into t1 (id, c) values
517 (NULL, 'a'),
518 (NULL, 'a')
519 on duplicate key update id = values(id), counter = counter + 1;
520 
521 select * from t1;
522 
523 insert into t1 (id, c) values
524 (NULL, 'b')
525 on duplicate key update id = values(id), counter = counter + 1;
526 
527 select * from t1;
528 
529 truncate table t1;
530 
531 insert into t1 (id, c) values (NULL, 'a');
532 
533 select * from t1;
534 
535 insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
536 on duplicate key update id = values(id), c = values(c), counter = counter + 1;
537 
538 select * from t1;
539 
540 insert into t1 (id, c) values (NULL, 'a')
541 on duplicate key update id = values(id), c = values(c), counter = counter + 1;
542 
543 select * from t1;
544 
545 drop table t1;
546 
547 #
548 # Bug #28189: optimizer erroniously prefers ref access to range access
549 # for an InnoDB table
550 #
551 
552 CREATE TABLE t1(
553  id int AUTO_INCREMENT PRIMARY KEY,
554  stat_id int NOT NULL,
555  acct_id int DEFAULT NULL,
556  INDEX idx1 (stat_id, acct_id),
557  INDEX idx2 (acct_id)
558 ) ENGINE=MyISAM;
559 
560 CREATE TABLE t2(
561  id int AUTO_INCREMENT PRIMARY KEY,
562  stat_id int NOT NULL,
563  acct_id int DEFAULT NULL,
564  INDEX idx1 (stat_id, acct_id),
565  INDEX idx2 (acct_id)
566 ) ENGINE=InnoDB STATS_PERSISTENT=0;
567 
568 INSERT INTO t1(stat_id,acct_id) VALUES
569  (1,759), (2,831), (3,785), (4,854), (1,921),
570  (1,553), (2,589), (3,743), (2,827), (2,545),
571  (4,779), (4,783), (1,597), (1,785), (4,832),
572  (1,741), (1,833), (3,788), (2,973), (1,907);
573 
574 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
575 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
576 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
577 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
578 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
579 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
580 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
581 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
582 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
583 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
584 INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
585 UPDATE t1 SET acct_id=785
586  WHERE MOD(stat_id,2)=0 AND MOD(id,stat_id)=MOD(acct_id,stat_id);
587 OPTIMIZE TABLE t1;
588 
589 SELECT COUNT(*) FROM t1;
590 SELECT COUNT(*) FROM t1 WHERE acct_id=785;
591 
592 -- disable_query_log
593 -- disable_result_log
594 ANALYZE TABLE t1;
595 -- enable_result_log
596 -- enable_query_log
597 
598 EXPLAIN SELECT COUNT(*) FROM t1 WHERE stat_id IN (1,3) AND acct_id=785;
599 
600 INSERT INTO t2 SELECT * FROM t1;
601 OPTIMIZE TABLE t2;
602 
603 -- disable_query_log
604 -- disable_result_log
605 ANALYZE TABLE t2;
606 -- enable_result_log
607 -- enable_query_log
608 
609 EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
610 
611 DROP TABLE t1,t2;
612 
613 #
614 # Bug #28652: assert when alter innodb table operation
615 #
616 create table t1(a int) engine=innodb;
617 alter table t1 comment '123';
618 show create table t1;
619 drop table t1;
620 
621 #
622 # Bug #25866: Getting "#HY000 Can't find record in..." on and INSERT
623 #
624 CREATE TABLE t1 (a CHAR(2), KEY (a)) ENGINE = InnoDB DEFAULT CHARSET=UTF8;
625 INSERT INTO t1 VALUES ('uk'),('bg');
626 SELECT * FROM t1 WHERE a = 'uk';
627 DELETE FROM t1 WHERE a = 'uk';
628 SELECT * FROM t1 WHERE a = 'uk';
629 UPDATE t1 SET a = 'us' WHERE a = 'uk';
630 SELECT * FROM t1 WHERE a = 'uk';
631 
632 CREATE TABLE t2 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
633 INSERT INTO t2 VALUES ('uk'),('bg');
634 SELECT * FROM t2 WHERE a = 'uk';
635 DELETE FROM t2 WHERE a = 'uk';
636 SELECT * FROM t2 WHERE a = 'uk';
637 INSERT INTO t2 VALUES ('uk');
638 UPDATE t2 SET a = 'us' WHERE a = 'uk';
639 SELECT * FROM t2 WHERE a = 'uk';
640 
641 CREATE TABLE t3 (a CHAR(2), KEY (a)) ENGINE = MyISAM;
642 INSERT INTO t3 VALUES ('uk'),('bg');
643 SELECT * FROM t3 WHERE a = 'uk';
644 DELETE FROM t3 WHERE a = 'uk';
645 SELECT * FROM t3 WHERE a = 'uk';
646 INSERT INTO t3 VALUES ('uk');
647 UPDATE t3 SET a = 'us' WHERE a = 'uk';
648 SELECT * FROM t3 WHERE a = 'uk';
649 
650 DROP TABLE t1,t2,t3;
651 
652 #
653 # Test bug when trying to drop data file which no InnoDB directory entry
654 #
655 
656 create table t1 (a int) engine=innodb;
657 let $MYSQLD_DATADIR= `select @@datadir`;
658 copy_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/bug29807.frm;
659 --error 1146
660 select * from bug29807;
661 drop table t1;
662 --error 1051
663 drop table bug29807;
664 create table bug29807 (a int);
665 drop table bug29807;
666 --disable_query_log
667 call mtr.add_suppression("InnoDB: Error: table .test...bug29807. does not exist in the InnoDB internal");
668 call mtr.add_suppression("InnoDB: Cannot open table test/bug29807 from");
669 --enable_query_log
670 
671 
672 #
673 # Bug #29154: LOCK TABLES is not atomic when >1 InnoDB tables are locked
674 #
675 
676 CREATE TABLE t1 (a INT) ENGINE=InnoDB;
677 CREATE TABLE t2 (a INT) ENGINE=InnoDB;
678 
679 CONNECT (c1,localhost,root,,);
680 CONNECT (c2,localhost,root,,);
681 
682 --echo switch to connection c1
683 CONNECTION c1;
684 SET AUTOCOMMIT=0;
685 INSERT INTO t2 VALUES (1);
686 
687 --echo switch to connection c2
688 CONNECTION c2;
689 SET AUTOCOMMIT=0;
690 --error ER_LOCK_WAIT_TIMEOUT
691 LOCK TABLES t1 READ, t2 READ;
692 
693 --echo switch to connection c1
694 CONNECTION c1;
695 COMMIT;
696 INSERT INTO t1 VALUES (1);
697 
698 --echo switch to connection default
699 CONNECTION default;
700 SET AUTOCOMMIT=default;
701 DISCONNECT c1;
702 DISCONNECT c2;
703 DROP TABLE t1,t2;
704 
705 #
706 # Bug #25798: a query with forced index merge returns wrong result
707 #
708 
709 CREATE TABLE t1 (
710  id int NOT NULL auto_increment PRIMARY KEY,
711  b int NOT NULL,
712  c datetime NOT NULL,
713  INDEX idx_b(b),
714  INDEX idx_c(c)
715 ) ENGINE=InnoDB;
716 
717 CREATE TABLE t2 (
718  b int NOT NULL auto_increment PRIMARY KEY,
719  c datetime NOT NULL
720 ) ENGINE= MyISAM;
721 
722 INSERT INTO t2(c) VALUES ('2007-01-01');
723 INSERT INTO t2(c) SELECT c FROM t2;
724 INSERT INTO t2(c) SELECT c FROM t2;
725 INSERT INTO t2(c) SELECT c FROM t2;
726 INSERT INTO t2(c) SELECT c FROM t2;
727 INSERT INTO t2(c) SELECT c FROM t2;
728 INSERT INTO t2(c) SELECT c FROM t2;
729 INSERT INTO t2(c) SELECT c FROM t2;
730 INSERT INTO t2(c) SELECT c FROM t2;
731 INSERT INTO t2(c) SELECT c FROM t2;
732 INSERT INTO t2(c) SELECT c FROM t2;
733 
734 INSERT INTO t1(b,c) SELECT b,c FROM t2;
735 UPDATE t2 SET c='2007-01-02';
736 INSERT INTO t1(b,c) SELECT b,c FROM t2;
737 UPDATE t2 SET c='2007-01-03';
738 INSERT INTO t1(b,c) SELECT b,c FROM t2;
739 
740 -- disable_query_log
741 -- disable_result_log
742 ANALYZE TABLE t1;
743 ANALYZE TABLE t2;
744 -- enable_result_log
745 -- enable_query_log
746 
747 set @@sort_buffer_size=8192;
748 
749 SELECT COUNT(*) FROM t1;
750 
751 --replace_column 9 #
752 EXPLAIN
753 SELECT COUNT(*) FROM t1
754  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
755 SELECT COUNT(*) FROM t1
756  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
757 
758 --replace_column 9 #
759 EXPLAIN
760 SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
761  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
762 SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
763  WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
764 
765 set @@sort_buffer_size=default;
766 
767 DROP TABLE t1,t2;
768 
769 # Test of behaviour with CREATE ... SELECT
770 #
771 
772 CREATE TABLE t1 (a int, b int);
773 insert into t1 values (1,1),(1,2);
774 --error ER_DUP_ENTRY
775 CREATE TABLE t2 (primary key (a)) select * from t1;
776 # This should give warning
777 drop table if exists t2;
778 --error ER_DUP_ENTRY
779 CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
780 # This should give warning
781 drop table if exists t2;
782 CREATE TABLE t2 (a int, b int, primary key (a));
783 BEGIN;
784 INSERT INTO t2 values(100,100);
785 CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
786 SELECT * from t2;
787 ROLLBACK;
788 SELECT * from t2;
789 TRUNCATE table t2;
790 --error ER_DUP_ENTRY
791 INSERT INTO t2 select * from t1;
792 SELECT * from t2;
793 drop table t2;
794 
795 CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
796 BEGIN;
797 INSERT INTO t2 values(100,100);
798 CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
799 SELECT * from t2;
800 COMMIT;
801 BEGIN;
802 INSERT INTO t2 values(101,101);
803 CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
804 SELECT * from t2;
805 ROLLBACK;
806 SELECT * from t2;
807 TRUNCATE table t2;
808 --error ER_DUP_ENTRY
809 INSERT INTO t2 select * from t1;
810 SELECT * from t2;
811 drop table t1,t2;
812 
813 #
814 # Bug#17530: Incorrect key truncation on table creation caused server crash.
815 #
816 create table t1(f1 varchar(800) binary not null, key(f1))
817  character set utf8 collate utf8_general_ci;
818 insert into t1 values('aaa');
819 drop table t1;
820 
821 
822 #
823 # Bug#22781: SQL_BIG_RESULT fails to influence sort plan
824 #
825 CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
826 
827 INSERT INTO t1 VALUES ( 1 , 1 , 1);
828 INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1;
829 INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1;
830 INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1;
831 INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1;
832 INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1;
833 INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
834 INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
835 
836 -- disable_query_log
837 -- disable_result_log
838 ANALYZE TABLE t1;
839 -- enable_result_log
840 -- enable_query_log
841 
842 EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
843 EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
844 DROP TABLE t1;
845 
846 --source include/innodb_rollback_on_timeout.inc
847 
848 #
849 # Bug#27296 Assertion in ALTER TABLE SET DEFAULT in Linux Debug build
850 # (possible deadlock).
851 #
852 # The bug is applicable only to a transactoinal table.
853 # Cover with tests behavior that no longer causes an
854 # assertion.
855 #
856 --disable_warnings
857 drop table if exists t1;
858 --enable_warnings
859 create table t1 (a int) engine=innodb;
860 alter table t1 alter a set default 1;
861 drop table t1;
862 
863 --echo
864 --echo Bug#24918 drop table and lock / inconsistent between
865 --echo perm and temp tables
866 --echo
867 --echo Check transactional tables under LOCK TABLES
868 --echo
869 --disable_warnings
870 drop table if exists t24918, t24918_tmp, t24918_trans, t24918_trans_tmp,
871 t24918_access;
872 --enable_warnings
873 create table t24918_access (id int);
874 create table t24918 (id int) engine=myisam;
875 create temporary table t24918_tmp (id int) engine=myisam;
876 create table t24918_trans (id int) engine=innodb;
877 create temporary table t24918_trans_tmp (id int) engine=innodb;
878 
879 lock table t24918 write, t24918_tmp write, t24918_trans write, t24918_trans_tmp write;
880 drop table t24918;
881 --error ER_TABLE_NOT_LOCKED
882 select * from t24918_access;
883 drop table t24918_trans;
884 --error ER_TABLE_NOT_LOCKED
885 select * from t24918_access;
886 drop table t24918_trans_tmp;
887 --error ER_TABLE_NOT_LOCKED
888 select * from t24918_access;
889 drop table t24918_tmp;
890 --error ER_TABLE_NOT_LOCKED
891 select * from t24918_access;
892 unlock tables;
893 
894 drop table t24918_access;
895 #
896 # Bug #28591: MySQL need not sort the records in case of ORDER BY
897 # primary_key on InnoDB table
898 #
899 
900 CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB;
901 INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
902 INSERT INTO t1 SELECT a + 8, 2 FROM t1;
903 INSERT INTO t1 SELECT a + 16, 1 FROM t1;
904 -- disable_query_log
905 -- disable_result_log
906 ANALYZE TABLE t1;
907 -- enable_result_log
908 -- enable_query_log
909 query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a;
910 SELECT * FROM t1 WHERE b=2 ORDER BY a;
911 query_vertical EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
912 SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
913 query_vertical EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
914 SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
915 
916 CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c))
917  ENGINE=InnoDB;
918 INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1);
919 INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2;
920 INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2;
921 
922 -- disable_query_log
923 -- disable_result_log
924 ANALYZE TABLE t2;
925 -- enable_result_log
926 -- enable_query_log
927 
928 query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
929 SELECT * FROM t2 WHERE b=1 ORDER BY a;
930 query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
931 SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
932 query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
933 SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
934 query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
935 SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
936 
937 DROP TABLE t1,t2;
938 
939 
940 #
941 # Bug #29644: alter table hangs if records locked in share mode by long
942 # running transaction
943 #
944 
945 CREATE TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB;
946 
947 INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
948 INSERT INTO t1 SELECT a + 8 FROM t1;
949 INSERT INTO t1 SELECT a + 16 FROM t1;
950 
951 DELIMITER |;
952 CREATE PROCEDURE p1 ()
953 BEGIN
954  DECLARE i INT DEFAULT 50;
955  DECLARE cnt INT;
956  # Continue even in the presence of ER_LOCK_DEADLOCK.
957  DECLARE CONTINUE HANDLER FOR 1213 BEGIN END;
958  START TRANSACTION;
959  ALTER TABLE t1 ENGINE=InnoDB;
960  COMMIT;
961  START TRANSACTION;
962  WHILE (i > 0) DO
963  SET i = i - 1;
964  SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE;
965  END WHILE;
966  COMMIT;
967 END;|
968 
969 DELIMITER ;|
970 
971 CONNECT (con1,localhost,root,,);
972 CONNECT (con2,localhost,root,,);
973 
974 CONNECTION con1;
975 SEND CALL p1();
976 CONNECTION con2;
977 SEND CALL p1();
978 CONNECTION default;
979 CALL p1();
980 
981 CONNECTION con1;
982 REAP;
983 CONNECTION con2;
984 REAP;
985 CONNECTION default;
986 DISCONNECT con1;
987 DISCONNECT con2;
988 
989 DROP PROCEDURE p1;
990 DROP TABLE t1;
991 
992 #
993 # Bug #28125: ERROR 2013 when adding index.
994 #
995 create table t1(a text) engine=innodb default charset=utf8;
996 insert into t1 values('aaa');
997 alter table t1 add index(a(1024));
998 show create table t1;
999 drop table t1;
1000 
1001 #
1002 # Bug #28570: handler::index_read() is called with different find_flag when
1003 # ORDER BY is used
1004 #
1005 
1006 CREATE TABLE t1 (
1007  a INT,
1008  b INT,
1009  KEY (b)
1010 ) ENGINE=InnoDB;
1011 
1012 INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
1013 
1014 START TRANSACTION;
1015 SELECT * FROM t1 WHERE b=20 FOR UPDATE;
1016 
1017 --connect (conn2, localhost, root,,test)
1018 
1019 # This statement gives a "failed: 1205: Lock wait timeout exceeded; try
1020 # restarting transaction" message when the bug is present.
1021 START TRANSACTION;
1022 SELECT * FROM t1 WHERE b=10 ORDER BY A FOR UPDATE;
1023 ROLLBACK;
1024 
1025 --disconnect conn2
1026 --connection default
1027 
1028 ROLLBACK;
1029 DROP TABLE t1;
1030 
1031 #
1032 # Bug#30596: GROUP BY optimization gives wrong result order
1033 #
1034 CREATE TABLE t1(
1035  a INT,
1036  b INT NOT NULL,
1037  c INT NOT NULL,
1038  d INT,
1039  UNIQUE KEY (c,b)
1040 ) engine=innodb;
1041 
1042 INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
1043 
1044 -- disable_query_log
1045 -- disable_result_log
1046 ANALYZE TABLE t1;
1047 -- enable_result_log
1048 -- enable_query_log
1049 
1050 EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
1051 SELECT c,b,d FROM t1 GROUP BY c,b,d;
1052 EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
1053 SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
1054 EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
1055 SELECT c,b,d FROM t1 ORDER BY c,b,d;
1056 
1057 EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
1058 SELECT c,b,d FROM t1 GROUP BY c,b;
1059 EXPLAIN SELECT c,b FROM t1 GROUP BY c,b;
1060 SELECT c,b FROM t1 GROUP BY c,b;
1061 
1062 DROP TABLE t1;
1063 
1064 #
1065 # Bug #31001: ORDER BY DESC in InnoDB not working
1066 #
1067 CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
1068 INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
1069 
1070 -- disable_query_log
1071 -- disable_result_log
1072 ANALYZE TABLE t1;
1073 -- enable_result_log
1074 -- enable_query_log
1075 
1076 #The two queries below should produce different results, but they don't.
1077 query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
1078 SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
1079 query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
1080 SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
1081 
1082 query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
1083 SELECT * FROM t1 ORDER BY b ASC, a ASC;
1084 query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
1085 SELECT * FROM t1 ORDER BY b DESC, a DESC;
1086 query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
1087 SELECT * FROM t1 ORDER BY b ASC, a DESC;
1088 query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
1089 SELECT * FROM t1 ORDER BY b DESC, a ASC;
1090 
1091 DROP TABLE t1;
1092 
1093 ###########################################################################
1094 
1095 --echo
1096 --echo #
1097 --echo # Bug#27610: ALTER TABLE ROW_FORMAT=... does not rebuild the table.
1098 --echo #
1099 
1100 --echo
1101 --echo # - prepare;
1102 --echo
1103 
1104 --disable_warnings
1105 DROP TABLE IF EXISTS t1;
1106 --enable_warnings
1107 
1108 --echo
1109 
1110 CREATE TABLE t1(c INT)
1111  ENGINE = InnoDB
1112  ROW_FORMAT = COMPACT;
1113 
1114 --echo
1115 --echo # - initial check;
1116 --echo
1117 
1118 SELECT table_schema, table_name, row_format
1119 FROM INFORMATION_SCHEMA.TABLES
1120 WHERE table_schema = DATABASE() AND table_name = 't1';
1121 
1122 --echo
1123 --echo # - change ROW_FORMAT and check;
1124 --echo
1125 
1126 ALTER TABLE t1 ROW_FORMAT = REDUNDANT;
1127 
1128 --echo
1129 
1130 SELECT table_schema, table_name, row_format
1131 FROM INFORMATION_SCHEMA.TABLES
1132 WHERE table_schema = DATABASE() AND table_name = 't1';
1133 
1134 --echo
1135 --echo # - that's it, cleanup.
1136 --echo
1137 
1138 DROP TABLE t1;
1139 
1140 ###########################################################################
1141 
1142 #
1143 # Bug #31137: Assertion failed: primary_key_no == -1 || primary_key_no == 0
1144 #
1145 create table t1(a char(10) not null, unique key aa(a(1)),
1146  b char(4) not null, unique key bb(b(4))) engine=innodb;
1147 desc t1;
1148 show create table t1;
1149 drop table t1;
1150 
1151 #
1152 # Bug #32815: query with ORDER BY and a possible ref_or_null access
1153 #
1154 
1155 CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB;
1156 INSERT INTO t1 VALUES
1157  (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2);
1158 
1159 -- disable_query_log
1160 -- disable_result_log
1161 ANALYZE TABLE t1;
1162 -- enable_result_log
1163 -- enable_query_log
1164 
1165 EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
1166 SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
1167 
1168 DROP TABLE t1;
1169 
1170 #
1171 # Bug #34223: Assertion failed: (optp->var_type & 127) == 8,
1172 # file .\my_getopt.c, line 830
1173 #
1174 
1175 set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
1176 set global innodb_autoextend_increment=8;
1177 set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
1178 
1179 set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
1180 set global innodb_commit_concurrency=0;
1181 set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
1182 
1183 #
1184 # Bug #37830: ORDER BY ASC/DESC - no difference
1185 #
1186 
1187 CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
1188  ENGINE=InnoDB;
1189 
1190 INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
1191 INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
1192 
1193 -- disable_query_log
1194 -- disable_result_log
1195 ANALYZE TABLE t1;
1196 -- enable_result_log
1197 -- enable_query_log
1198 
1199 # should be range access
1200 EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
1201 
1202 # should produce '8 7 6 5 4' for a
1203 SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
1204 
1205 DROP TABLE t1;
1206 
1207 #
1208 # Bug#37284 Crash in Field_string::type()
1209 #
1210 --disable_warnings
1211 DROP TABLE IF EXISTS t1;
1212 --enable_warnings
1213 CREATE TABLE t1 (a char(50)) ENGINE=InnoDB;
1214 CREATE INDEX i1 on t1 (a(3));
1215 SELECT * FROM t1 WHERE a = 'abcde';
1216 DROP TABLE t1;
1217 
1218 
1219 --echo #
1220 --echo # BUG #26288: savepoint are not deleted on comit, if the transaction
1221 --echo # was otherwise empty
1222 --echo #
1223 BEGIN;
1224 SAVEPOINT s1;
1225 COMMIT;
1226 --error 1305
1227 RELEASE SAVEPOINT s1;
1228 
1229 BEGIN;
1230 SAVEPOINT s2;
1231 COMMIT;
1232 --error 1305
1233 ROLLBACK TO SAVEPOINT s2;
1234 
1235 BEGIN;
1236 SAVEPOINT s3;
1237 ROLLBACK;
1238 --error 1305
1239 RELEASE SAVEPOINT s3;
1240 
1241 BEGIN;
1242 SAVEPOINT s4;
1243 ROLLBACK;
1244 --error 1305
1245 ROLLBACK TO SAVEPOINT s4;
1246 
1247 #
1248 # Bug#39793 Foreign keys not constructed when column has a '#' in a comment or default value
1249 #
1250 
1251 #This statement should be written on a single line for proper testing
1252 CREATE TABLE t1 (f1 INTEGER PRIMARY KEY COMMENT 'My ID#', f2 INTEGER DEFAULT NULL, f3 CHAR(10) DEFAULT 'My ID#', CONSTRAINT f2_ref FOREIGN KEY (f2) REFERENCES t1 (f1)) ENGINE=INNODB;
1253 SHOW CREATE TABLE t1;
1254 DROP TABLE t1;
1255 
1256 --echo #
1257 --echo # Bug #36995: valgrind error in remove_const during subquery executions
1258 --echo #
1259 
1260 create table t1 (a bit(1) not null,b int) engine=myisam;
1261 create table t2 (c int) engine=innodb;
1262 explain
1263 select b from t1 where a not in (select b from t1,t2 group by a) group by a;
1264 DROP TABLE t1,t2;
1265 
1266 --echo End of 5.0 tests
1267 
1268 # Fix for BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY
1269 # UPDATE": if the row is updated, it's like a regular UPDATE:
1270 # LAST_INSERT_ID() is not affected.
1271 CREATE TABLE `t2` (
1272  `k` int(11) NOT NULL auto_increment,
1273  `a` int(11) default NULL,
1274  `c` int(11) default NULL,
1275  PRIMARY KEY (`k`),
1276  UNIQUE KEY `idx_1` (`a`)
1277 );
1278 insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1279 ifnull( c,
1280 0 ) + 1;
1281 insert into t2 ( a ) values ( 7 ) on duplicate key update c =
1282 ifnull( c,
1283 0 ) + 1;
1284 select last_insert_id();
1285 select * from t2;
1286 insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1287 ifnull( c,
1288 0 ) + 1;
1289 select last_insert_id();
1290 # test again when last_insert_id() is 0 initially
1291 select last_insert_id(0);
1292 insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1293 ifnull( c,
1294 0 ) + 1;
1295 select last_insert_id();
1296 select * from t2;
1297 
1298 # Test of LAST_INSERT_ID() when autogenerated will fail:
1299 # last_insert_id() should not change
1300 insert ignore into t2 values (null,6,1),(10,8,1);
1301 select last_insert_id();
1302 # First and second autogenerated will fail, last_insert_id() should
1303 # point to third
1304 insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
1305 select last_insert_id();
1306 select * from t2;
1307 
1308 # Test of the workaround which enables people to know the id of the
1309 # updated row in INSERT ON DUPLICATE KEY UPDATE, by using
1310 # LAST_INSERT_ID(autoinc_col) in the UPDATE clause.
1311 
1312 insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1313 ifnull( c,
1314 0 ) + 1, k=last_insert_id(k);
1315 select last_insert_id();
1316 select * from t2;
1317 
1318 drop table t2;
1319 
1320 
1321 #
1322 # Tests for bug #28415 "Some ALTER TABLE statements no longer work
1323 # under LOCK TABLES" and some aspects of fast ALTER TABLE behaviour
1324 # for transactional tables.
1325 #
1326 --disable_warnings
1327 drop table if exists t1, t2;
1328 --enable_warnings
1329 create table t1 (i int);
1330 alter table t1 modify i int default 1;
1331 alter table t1 modify i int default 2, rename t2;
1332 lock table t2 write;
1333 alter table t2 modify i int default 3;
1334 unlock tables;
1335 lock table t2 write;
1336 alter table t2 modify i int default 4, rename t1;
1337 unlock tables;
1338 drop table t1;
1339 
1340 
1341 #
1342 # Some more tests for ALTER TABLE and LOCK TABLES for transactional tables.
1343 #
1344 # Table which is altered under LOCK TABLES should stay in list of locked
1345 # tables and be available after alter takes place unless ALTER contains
1346 # RENAME clause. We should see the new definition of table, of course.
1347 # Before 5.1 this behavior was inconsistent across the platforms and
1348 # different engines. See also tests in alter_table.test
1349 #
1350 --disable_warnings
1351 drop table if exists t1;
1352 --enable_warnings
1353 create table t1 (i int);
1354 insert into t1 values ();
1355 lock table t1 write;
1356 # Example of so-called 'fast' ALTER TABLE
1357 alter table t1 modify i int default 1;
1358 insert into t1 values ();
1359 select * from t1;
1360 # And now full-blown ALTER TABLE
1361 alter table t1 change i c char(10) default "Two";
1362 insert into t1 values ();
1363 select * from t1;
1364 unlock tables;
1365 select * from t1;
1366 drop tables t1;
1367 
1368 #
1369 # Bug#29310: An InnoDB table was updated when the data wasn't actually changed.
1370 #
1371 create table t1(f1 varchar(5) unique, f2 timestamp NOT NULL DEFAULT
1372  CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
1373 insert into t1(f1) values(1);
1374 --replace_column 1 #
1375 select @a:=f2 from t1;
1376 --sleep 5
1377 update t1 set f1=1;
1378 --replace_column 1 #
1379 select @b:=f2 from t1;
1380 select if(@a=@b,"ok","wrong");
1381 --sleep 5
1382 insert into t1(f1) values (1) on duplicate key update f1="1";
1383 --replace_column 1 #
1384 select @b:=f2 from t1;
1385 select if(@a=@b,"ok","wrong");
1386 --sleep 5
1387 insert into t1(f1) select f1 from t1 on duplicate key update f1="1";
1388 --replace_column 1 #
1389 select @b:=f2 from t1;
1390 select if(@a=@b,"ok","wrong");
1391 drop table t1;
1392 
1393 #
1394 # Bug #31310: Locked rows silently skipped in read-committed isolation level.
1395 #
1396 
1397 connect (con1,localhost,root,,);
1398 connect (con2,localhost,root,,);
1399 SET SESSION AUTOCOMMIT = 0;
1400 SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1401 set binlog_format=mixed;
1402 --echo # Switch to connection con1
1403 connection con1;
1404 
1405 eval
1406 CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256))
1407 ENGINE = $engine_type;
1408 INSERT INTO t1 VALUES (1,2);
1409 
1410 --echo # 1. test for locking:
1411 
1412 BEGIN;
1413 --enable_info
1414 UPDATE t1 SET b = 12 WHERE a = 1;
1415 --disable_info
1416 SELECT * FROM t1;
1417 
1418 --echo # Switch to connection con2
1419 connection con2;
1420 
1421 --enable_info
1422 --disable_abort_on_error
1423 --error ER_LOCK_WAIT_TIMEOUT
1424 UPDATE t1 SET b = 21 WHERE a = 1;
1425 --disable_info
1426 
1427 --echo # Switch to connection con1
1428 connection con1;
1429 SELECT * FROM t1;
1430 ROLLBACK;
1431 
1432 --echo # Switch to connection con2
1433 connection con2;
1434 ROLLBACK;
1435 
1436 --echo # Switch to connection con1
1437 connection con1;
1438 
1439 --echo # 2. test for serialized update:
1440 
1441 CREATE TABLE t2 (a INT);
1442 
1443 TRUNCATE t1;
1444 INSERT INTO t1 VALUES (1,'init');
1445 
1446 DELIMITER |;
1447 CREATE PROCEDURE p1()
1448 BEGIN
1449  UPDATE t1 SET b = CONCAT(b, '+con2') WHERE a = 1;
1450  INSERT INTO t2 VALUES ();
1451 END|
1452 DELIMITER ;|
1453 
1454 BEGIN;
1455 --enable_info
1456 UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1;
1457 --disable_info
1458 SELECT * FROM t1;
1459 
1460 --echo # Switch to connection con2
1461 connection con2;
1462 
1463 --send CALL p1;
1464 
1465 --echo # Switch to connection con1
1466 connection con1;
1467 SELECT * FROM t1;
1468 COMMIT;
1469 
1470 let $bug31310 = 1;
1471 while ($bug31310)
1472 {
1473  let $bug31310= `SELECT 1 - COUNT(*) FROM t2`;
1474 }
1475 
1476 SELECT * FROM t1;
1477 
1478 --echo # Switch to connection con2
1479 connection con2;
1480 --reap
1481 SELECT * FROM t1;
1482 COMMIT;
1483 
1484 --echo # Switch to connection con1
1485 connection con1;
1486 
1487 --echo # 3. test for updated key column:
1488 
1489 TRUNCATE t1;
1490 TRUNCATE t2;
1491 
1492 INSERT INTO t1 VALUES (1,'init');
1493 
1494 BEGIN;
1495 --enable_info
1496 UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1;
1497 --disable_info
1498 SELECT * FROM t1;
1499 
1500 --echo # Switch to connection con2
1501 connection con2;
1502 
1503 --send CALL p1;
1504 
1505 --echo # Switch to connection con1
1506 connection con1;
1507 SELECT * FROM t1;
1508 COMMIT;
1509 
1510 let $bug31310 = 1;
1511 while ($bug31310)
1512 {
1513  let $bug31310= `SELECT 1 - COUNT(*) FROM t2`;
1514 }
1515 
1516 SELECT * FROM t1;
1517 
1518 --echo # Switch to connection con2
1519 connection con2;
1520 --reap
1521 SELECT * FROM t1;
1522 
1523 --enable_abort_on_error
1524 connection default;
1525 disconnect con1;
1526 disconnect con2;
1527 DROP PROCEDURE p1;
1528 DROP TABLE t1, t2;
1529 # Bug#30747 Create table with identical constraint names behaves incorrectly
1530 #
1531 
1532 if ($test_foreign_keys)
1533 {
1534  CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b)) engine=innodb;
1535  --error ER_WRONG_FK_DEF
1536  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1537  CONSTRAINT c2 FOREIGN KEY f2 (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
1538  --error ER_WRONG_FK_DEF
1539  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1540  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
1541  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1542  CONSTRAINT c1 FOREIGN KEY c2 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
1543  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
1544  ALTER TABLE t2 DROP FOREIGN KEY c2;
1545  DROP TABLE t2;
1546  --error ER_WRONG_FK_DEF
1547  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1548  FOREIGN KEY (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
1549  --error ER_WRONG_FK_DEF
1550  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1551  FOREIGN KEY f1 (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
1552  CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1553  CONSTRAINT c1 FOREIGN KEY f1 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
1554  CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
1555  FOREIGN KEY f3 (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
1556  FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
1557  SHOW CREATE TABLE t2;
1558  DROP TABLE t2;
1559  DROP TABLE t1;
1560 }
1561 
1562 #
1563 # Bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB and
1564 # auto_increment keys
1565 #
1566 create table t1 (a int auto_increment primary key) engine=innodb;
1567 alter table t1 order by a;
1568 drop table t1;
1569 
1570 #
1571 # Bug #33697: ORDER BY primary key DESC vs. ref access + filesort
1572 # (reproduced only with InnoDB tables)
1573 #
1574 
1575 CREATE TABLE t1
1576  (vid integer NOT NULL,
1577  tid integer NOT NULL,
1578  idx integer NOT NULL,
1579  name varchar(128) NOT NULL,
1580  type varchar(128) NULL,
1581  PRIMARY KEY(idx, vid, tid),
1582  UNIQUE(vid, tid, name)
1583 ) ENGINE=InnoDB;
1584 
1585 INSERT INTO t1 VALUES
1586  (1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL),
1587  (5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL),
1588  (4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL),
1589  (4,1,3,'pk',NULL),(5,1,3,'c2',NULL),
1590  (2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL);
1591 
1592 -- disable_query_log
1593 -- disable_result_log
1594 ANALYZE TABLE t1;
1595 -- enable_result_log
1596 -- enable_query_log
1597 
1598 EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
1599 
1600 SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
1601 
1602 DROP TABLE t1;
1603 
1604 --echo #
1605 --echo # Bug #44290: explain crashes for subquery with distinct in
1606 --echo # SQL_SELECT::test_quick_select
1607 --echo # (reproduced only with InnoDB tables)
1608 --echo #
1609 
1610 eval
1611 CREATE TABLE t1 (c1 INT, c2 INT, c3 INT, KEY (c3), KEY (c2, c3))
1612  ENGINE=$engine_type;
1613 INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
1614 
1615 -- disable_query_log
1616 -- disable_result_log
1617 ANALYZE TABLE t1;
1618 -- enable_result_log
1619 -- enable_query_log
1620 
1621 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1622  FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1623 EXPLAIN
1624 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1625  FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1626 
1627 DROP TABLE t1;
1628 
1629 eval
1630 CREATE TABLE t1 (c1 REAL, c2 REAL, c3 REAL, KEY (c3), KEY (c2, c3))
1631  ENGINE=$engine_type;
1632 INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
1633 
1634 -- disable_query_log
1635 -- disable_result_log
1636 ANALYZE TABLE t1;
1637 -- enable_result_log
1638 -- enable_query_log
1639 
1640 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1641  FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1642 EXPLAIN
1643 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1644  FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1645 
1646 DROP TABLE t1;
1647 
1648 eval
1649 CREATE TABLE t1 (c1 DECIMAL(12,2), c2 DECIMAL(12,2), c3 DECIMAL(12,2),
1650  KEY (c3), KEY (c2, c3))
1651  ENGINE=$engine_type;
1652 INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
1653 
1654 -- disable_query_log
1655 -- disable_result_log
1656 ANALYZE TABLE t1;
1657 -- enable_result_log
1658 -- enable_query_log
1659 
1660 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1661  FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1662 EXPLAIN
1663 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1664  FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1665 
1666 DROP TABLE t1;
1667 
1668 --echo End of 5.1 tests
1669 
1670 --echo #
1671 --echo # Bug#43600: Incorrect type conversion caused wrong result.
1672 --echo #
1673 CREATE TABLE t1 (
1674  a int NOT NULL
1675 ) engine= innodb;
1676 
1677 CREATE TABLE t2 (
1678  a int NOT NULL,
1679  b int NOT NULL,
1680  filler char(100) DEFAULT NULL,
1681  KEY a (a,b)
1682 ) engine= innodb;
1683 
1684 insert into t1 values (0),(1),(2),(3),(4);
1685 insert into t2 select A.a + 10 *B.a, 1, 'filler' from t1 A, t1 B;
1686 
1687 -- disable_query_log
1688 -- disable_result_log
1689 analyze table t1;
1690 analyze table t2;
1691 -- enable_result_log
1692 -- enable_query_log
1693 
1694 explain select * from t1, t2 where t2.a=t1.a and t2.b + 1;
1695 select * from t1, t2 where t2.a=t1.a and t2.b + 1;
1696 
1697 drop table t1,t2;
1698 --echo # End of test case for the bug#43600
1699 
1700 --echo #
1701 --echo # Bug#42643: InnoDB does not support replication of TRUNCATE TABLE
1702 --echo #
1703 --echo # Check that a TRUNCATE TABLE statement, needing an exclusive meta
1704 --echo # data lock, waits for a shared metadata lock owned by a concurrent
1705 --echo # transaction.
1706 --echo #
1707 
1708 eval CREATE TABLE t1 (a INT) ENGINE=$engine_type;
1709 INSERT INTO t1 VALUES (1),(2),(3);
1710 BEGIN;
1711 SELECT * FROM t1 ORDER BY a;
1712 --echo # Connection con1
1713 connect (con1, localhost, root,,);
1714 --send TRUNCATE TABLE t1;
1715 --echo # Connection default
1716 connection default;
1717 let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist
1718  WHERE state='Waiting for table metadata lock' AND info='TRUNCATE TABLE t1';
1719 --source include/wait_condition.inc
1720 SELECT * FROM t1 ORDER BY a;
1721 ROLLBACK;
1722 --echo # Connection con1
1723 connection con1;
1724 --echo # Reaping TRUNCATE TABLE
1725 --reap
1726 SELECT * FROM t1;
1727 --echo # Disconnect con1
1728 disconnect con1;
1729 --echo # Connection default
1730 connection default;
1731 DROP TABLE t1;