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.
13 # Note: The comments/expectations refer to InnoDB.
14 # They might be not valid for other storage engines.
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.
28 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
29 eval SET SESSION DEFAULT_TMP_STORAGE_ENGINE = $engine_type;
32 drop
table if exists t1,t2,t3,t1m,t1i,t2m,t2i,t4;
33 drop procedure
if exists p1;
37 # BUG#16798: Uninitialized row buffer reads in ref-or-null optimizer
38 # (repeatable only w/innodb).
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)
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);
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)
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);
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))
79 c.c_id = 218 and expiredate is null;
81 select * from t1 where org_id is null;
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))
87 c.c_id = 218 and expiredate is null;
92 # Bug#17212: results not sorted correctly by ORDER BY when using index
93 # (repeatable only w/innodb because of index props)
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));
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;
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;
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;
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;
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;
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
128 CREATE
TABLE `t1` (`id1` INT) ;
129 INSERT INTO `t1` (`id1`) VALUES (1),(5),(2);
136 UNIQUE (`id2`,`id4`),
140 INSERT INTO `t2`(`id1`,`id2`,`id3`,`id4`) VALUES
148 SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = 1 AND `id3` = 2);
152 # Bug #22728 - Handler_rollback value is growing
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,,);
164 let $after= `show status like
'Handler_rollback'`;
165 # Compare the before and after value, it should be equal
167 eval select STRCMP(
"$before",
"$after") as "Before and after comparison";
174 # Bug #13191: INSERT...ON DUPLICATE KEY UPDATE of UTF-8 string fields
175 # used in partial unique indices.
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');
182 INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE
KEY UPDATE cnt=cnt+1;
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');
190 INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE
KEY UPDATE cnt=cnt+1;
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');
198 INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE
KEY UPDATE cnt=cnt+1;
203 # Bug #28272: EXPLAIN for SELECT from an empty InnoDB table
207 a1 decimal(10,0) DEFAULT NULL,
209 a3 time DEFAULT NULL,
211 a5
char(175) DEFAULT NULL,
212 a6 timestamp NOT NULL DEFAULT
'0000-00-00 00:00:00',
214 INDEX idx (a6,a7(239),a5)
217 EXPLAIN SELECT a4 FROM t1 WHERE
219 a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
221 EXPLAIN SELECT t1.a4 FROM t1, t1 t WHERE
222 t.a6=t.a6 AND t1.a6=NULL AND
223 t1.a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
228 # Bug #12882 min/max inconsistent on empty table
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);
237 insert into t2m values (5);
238 insert into t2i values (5);
241 -- disable_result_log
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;
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;
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;
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;
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;
276 explain select count(*), min(7), max(7) from t1m, t2i;
277 select count(*), min(7), max(7) from t1m, t2i;
279 explain select count(*), min(7), max(7) from t2m, t1i;
280 select count(*), min(7), max(7) from t2m, t1i;
282 drop
table t1m, t1i, t2m, t2i;
285 # Bug #12882: primary key implcitly included in every innodb index
286 # (was part of group_min_max.test)
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;
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');
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 ' '
331 insert into t4 (a1, a2, b, c, d, dummy) select * from t1;
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);
338 select distinct a1 from t4 where pk_col not in (1,2,3,4);
344 # BUG#18819: DELETE IGNORE hangs on foreign key parent delete
346 # The bug itself does not relate to InnoDB, but we have to use foreign
347 # keys to reproduce it.
350 DROP
TABLE IF EXISTS t2, t1;
353 CREATE
TABLE t1 (
i INT NOT NULL PRIMARY
KEY) ENGINE= InnoDB;
356 FOREIGN
KEY (
i) REFERENCES t1 (
i) ON DELETE NO ACTION
359 INSERT INTO t1 VALUES (1);
360 INSERT INTO t2 VALUES (1);
362 DELETE IGNORE FROM t1 WHERE
i = 1;
364 SELECT * FROM t1, t2;
369 --echo End of 4.1 tests.
373 # Bug #6142: a problem with the empty innodb table
374 # (was part of group_min_max.test)
379 a varchar(30), b varchar(30), primary key(a), key(b)
382 select distinct a from t1;
386 # Bug #9798: group by with rollup
387 # (was part of group_min_max.test)
391 create
table t1(a
int, key(a));
393 insert into t1 values(1);
394 select a, count(a) from t1
group by a with rollup;
398 # Bug #13293 Wrongly used index results in endless loop.
399 # (was part of group_min_max.test)
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;
409 # Test for bug #17164: ORed FALSE blocked conversion of outer join into join
412 CREATE
TABLE t1 (
id int(11) NOT NULL PRIMARY
KEY,
name varchar(20),
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)
419 ALTER
TABLE t2 ADD FOREIGN KEY (fkey) REFERENCES t2(
id);
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);
425 -- disable_result_log
432 SELECT COUNT(*) FROM t2 LEFT
JOIN t1 ON t2.fkey = t1.
id
433 WHERE t1.
name LIKE '
A%';
436 SELECT COUNT(*) FROM t2 LEFT
JOIN t1 ON t2.fkey = t1.
id
437 WHERE t1.
name LIKE 'A%' OR FALSE;
442 # Bug#26159: crash for a loose scan of a table that has been emptied
447 name varchar(20) NOT NULL,
448 dept varchar(20) NOT NULL,
449 age tinyint(3)
unsigned NOT NULL,
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');
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';
462 --echo
# Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
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';
469 --source include/innodb_rollback_on_timeout.inc
472 # Bug #27210: INNODB ON DUPLICATE KEY UPDATE
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,,);
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');
487 connect (con2,localhost,root,,);
490 INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '1234')
491 ON DUPLICATE KEY UPDATE `test2` = '1234';
498 set global query_cache_type=@save_qcache_type;
499 set global query_cache_size=@save_qcache_size;
501 --source include/innodb_rollback_on_timeout.inc
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)
509 id int auto_increment,
511 counter
int not null
default 1,
516 insert into t1 (
id, c) values
519 on duplicate key update
id = values(
id), counter = counter + 1;
523 insert into t1 (
id, c) values
525 on duplicate key update
id = values(
id), counter = counter + 1;
531 insert into t1 (
id, c) values (NULL, 'a');
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;
540 insert into t1 (
id, c) values (NULL, 'a')
541 on duplicate key update
id = values(
id), c = values(c), counter = counter + 1;
548 # Bug #28189: optimizer erroniously prefers ref access to range access
549 # for an InnoDB table
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),
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),
566 ) ENGINE=InnoDB STATS_PERSISTENT=0;
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);
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);
589 SELECT COUNT(*) FROM t1;
590 SELECT COUNT(*) FROM t1 WHERE acct_id=785;
593 -- disable_result_log
598 EXPLAIN SELECT COUNT(*) FROM t1 WHERE stat_id IN (1,3) AND acct_id=785;
600 INSERT INTO t2 SELECT * FROM t1;
604 -- disable_result_log
609 EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
614 # Bug #28652: assert when alter innodb table operation
616 create
table t1(a
int) engine=innodb;
617 alter
table t1 comment
'123';
618 show create
table t1;
622 # Bug #25866: Getting "#HY000 Can't find record in..." on and INSERT
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';
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';
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';
653 # Test bug when trying to drop data file which no InnoDB directory entry
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;
660 select * from bug29807;
664 create
table bug29807 (a
int);
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");
673 # Bug #29154: LOCK TABLES is not atomic when >1 InnoDB tables are locked
676 CREATE
TABLE t1 (a INT) ENGINE=InnoDB;
677 CREATE
TABLE t2 (a INT) ENGINE=InnoDB;
679 CONNECT (c1,localhost,root,,);
680 CONNECT (c2,localhost,root,,);
682 --echo
switch to connection c1
685 INSERT INTO t2 VALUES (1);
687 --echo
switch to connection c2
690 --error ER_LOCK_WAIT_TIMEOUT
691 LOCK TABLES t1 READ, t2 READ;
693 --echo
switch to connection c1
696 INSERT INTO t1 VALUES (1);
698 --echo
switch to connection
default
700 SET AUTOCOMMIT=
default;
706 # Bug #25798: a query with forced index merge returns wrong result
710 id int NOT NULL auto_increment PRIMARY KEY,
718 b
int NOT NULL auto_increment PRIMARY KEY,
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;
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;
741 -- disable_result_log
747 set @@sort_buffer_size=8192;
749 SELECT COUNT(*) FROM t1;
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;
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;
765 set @@sort_buffer_size=default;
769 # Test of behaviour with CREATE ... SELECT
772 CREATE
TABLE t1 (a
int, b
int);
773 insert into t1 values (1,1),(1,2);
775 CREATE
TABLE t2 (primary key (a)) select * from t1;
776 # This should give warning
777 drop
table if exists t2;
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));
784 INSERT INTO t2 values(100,100);
785 CREATE
TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
791 INSERT INTO t2 select * from t1;
795 CREATE TEMPORARY
TABLE t2 (a
int, b
int, primary key (a));
797 INSERT INTO t2 values(100,100);
798 CREATE TEMPORARY
TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
802 INSERT INTO t2 values(101,101);
803 CREATE TEMPORARY
TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
809 INSERT INTO t2 select * from t1;
814 # Bug#17530: Incorrect key truncation on table creation caused server crash.
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');
823 # Bug#22781: SQL_BIG_RESULT fails to influence sort plan
825 CREATE
TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
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;
837 -- disable_result_log
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;
846 --source include/innodb_rollback_on_timeout.inc
849 # Bug#27296 Assertion in ALTER TABLE SET DEFAULT in Linux Debug build
850 # (possible deadlock).
852 # The bug is applicable only to a transactoinal table.
853 # Cover with tests behavior that no longer causes an
857 drop
table if exists t1;
859 create
table t1 (a
int) engine=innodb;
860 alter
table t1 alter a
set default 1;
864 --echo Bug#24918 drop
table and lock / inconsistent between
865 --echo perm and
temp tables
867 --echo
Check transactional tables under LOCK TABLES
870 drop
table if exists t24918, t24918_tmp, t24918_trans, t24918_trans_tmp,
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;
879 lock
table t24918 write, t24918_tmp write, t24918_trans write, t24918_trans_tmp write;
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;
894 drop
table t24918_access;
896 # Bug #28591: MySQL need not sort the records in case of ORDER BY
897 # primary_key on InnoDB table
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;
905 -- disable_result_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;
916 CREATE
TABLE t2 (a
int, b
int, c
int, PRIMARY KEY (a), KEY bkey (b,c))
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;
923 -- disable_result_log
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;
941 # Bug #29644: alter table hangs if records locked in share mode by long
942 # running transaction
945 CREATE
TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB;
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;
952 CREATE PROCEDURE p1 ()
954 DECLARE i INT DEFAULT 50;
956 # Continue even in the presence of ER_LOCK_DEADLOCK.
957 DECLARE CONTINUE HANDLER FOR 1213 BEGIN END;
959 ALTER
TABLE t1 ENGINE=InnoDB;
964 SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE;
971 CONNECT (con1,localhost,root,,);
972 CONNECT (con2,localhost,root,,);
993 # Bug #28125: ERROR 2013 when adding index.
995 create
table t1(a text) engine=innodb
default charset=utf8;
996 insert into t1 values(
'aaa');
998 show create
table t1;
1002 # Bug #28570: handler::index_read() is called with different find_flag when
1012 INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
1015 SELECT * FROM t1 WHERE b=20 FOR UPDATE;
1017 --connect (conn2, localhost, root,,test)
1019 # This statement gives a "failed: 1205: Lock wait timeout exceeded; try
1020 # restarting transaction" message when the bug is present.
1022 SELECT * FROM t1 WHERE b=10
ORDER BY A FOR UPDATE;
1026 --connection
default
1032 # Bug#30596: GROUP BY optimization gives wrong result order
1042 INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
1044 -- disable_query_log
1045 -- disable_result_log
1047 -- enable_result_log
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;
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;
1065 # Bug #31001: ORDER BY DESC in InnoDB not working
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);
1070 -- disable_query_log
1071 -- disable_result_log
1073 -- enable_result_log
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;
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;
1093 ###########################################################################
1097 --echo # Bug#27610: ALTER
TABLE ROW_FORMAT=... does not rebuild the
table.
1105 DROP
TABLE IF EXISTS t1;
1110 CREATE
TABLE t1(c INT)
1112 ROW_FORMAT = COMPACT;
1115 --echo # - initial check;
1119 FROM INFORMATION_SCHEMA.TABLES
1120 WHERE table_schema = DATABASE() AND table_name = 't1';
1123 --echo
# - change ROW_FORMAT and check;
1126 ALTER
TABLE t1 ROW_FORMAT = REDUNDANT;
1131 FROM INFORMATION_SCHEMA.TABLES
1132 WHERE table_schema = DATABASE() AND table_name = 't1';
1135 --echo
# - that's it, cleanup.
1140 ###########################################################################
1143 # Bug #31137: Assertion failed: primary_key_no == -1 || primary_key_no == 0
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;
1148 show create
table t1;
1152 # Bug #32815: query with ORDER BY and a possible ref_or_null access
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);
1159 -- disable_query_log
1160 -- disable_result_log
1162 -- enable_result_log
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;
1171 # Bug #34223: Assertion failed: (optp->var_type & 127) == 8,
1172 # file .\my_getopt.c, line 830
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;
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;
1184 # Bug #37830: ORDER BY ASC/DESC - no difference
1187 CREATE
TABLE t1 (a
int, b
int, c
int, PRIMARY KEY (a), KEY t1_b (b))
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;
1193 -- disable_query_log
1194 -- disable_result_log
1196 -- enable_result_log
1199 # should be range access
1200 EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1
ORDER BY a DESC LIMIT 5;
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;
1208 # Bug#37284 Crash in Field_string::type()
1211 DROP
TABLE IF EXISTS t1;
1213 CREATE
TABLE t1 (a
char(50)) ENGINE=InnoDB;
1214 CREATE INDEX i1 on t1 (a(3));
1215 SELECT * FROM t1 WHERE a = 'abcde';
1220 --echo # BUG #26288: savepoint are not deleted on comit,
if the transaction
1221 --echo # was otherwise empty
1227 RELEASE SAVEPOINT s1;
1233 ROLLBACK TO SAVEPOINT s2;
1239 RELEASE SAVEPOINT s3;
1245 ROLLBACK TO SAVEPOINT s4;
1248 # Bug#39793 Foreign keys not constructed when column has a '#' in a comment or default value
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;
1257 --echo # Bug #36995: valgrind error in remove_const during subquery executions
1260 create
table t1 (a bit(1) not null,b
int) engine=myisam;
1261 create
table t2 (c
int) engine=innodb;
1263 select b from t1 where a not in (select b from t1,t2
group by a)
group by a;
1266 --echo End of 5.0 tests
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.
1272 `k` int(11) NOT NULL auto_increment,
1273 `a`
int(11) default NULL,
1274 `c`
int(11) default NULL,
1276 UNIQUE KEY `idx_1` (`a`)
1278 insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1281 insert into t2 ( a ) values ( 7 ) on duplicate key update c =
1284 select last_insert_id();
1286 insert into t2 ( a ) values ( 6 ) on duplicate key update c =
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 =
1295 select last_insert_id();
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
1304 insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
1305 select last_insert_id();
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.
1312 insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1314 0 ) + 1, k=last_insert_id(k);
1315 select last_insert_id();
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.
1327 drop
table if exists t1, t2;
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;
1335 lock
table t2 write;
1336 alter
table t2 modify i
int default 4, rename t1;
1342 # Some more tests for ALTER TABLE and LOCK TABLES for transactional tables.
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
1351 drop
table if exists t1;
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 ();
1360 # And now full-blown ALTER TABLE
1361 alter
table t1 change i c char(10) default "Two";
1362 insert into t1 values ();
1369 # Bug#29310: An InnoDB table was updated when the data wasn't actually changed.
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;
1378 --replace_column 1 #
1379 select @b:=f2 from t1;
1380 select
if(@a=@b,
"ok",
"wrong");
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");
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");
1394 # Bug #31310: Locked rows silently skipped in read-committed isolation level.
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
1406 CREATE
TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256))
1407 ENGINE = $engine_type;
1408 INSERT INTO t1 VALUES (1,2);
1410 --echo
# 1. test for locking:
1414 UPDATE t1 SET b = 12 WHERE a = 1;
1418 --echo # Switch
to connection con2
1422 --disable_abort_on_error
1423 --error ER_LOCK_WAIT_TIMEOUT
1424 UPDATE t1 SET b = 21 WHERE a = 1;
1427 --echo # Switch
to connection con1
1432 --echo # Switch
to connection con2
1436 --echo # Switch
to connection con1
1439 --echo # 2. test
for serialized update:
1441 CREATE
TABLE t2 (a INT);
1444 INSERT INTO t1 VALUES (1,
'init');
1447 CREATE PROCEDURE p1()
1449 UPDATE t1 SET b = CONCAT(b, '+con2') WHERE a = 1;
1450 INSERT INTO t2 VALUES ();
1456 UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1;
1460 --echo
# Switch to connection con2
1465 --echo # Switch
to connection con1
1473 let $bug31310= `SELECT 1 - COUNT(*) FROM t2`;
1478 --echo
# Switch to connection con2
1484 --echo # Switch
to connection con1
1487 --echo # 3. test
for updated key column:
1492 INSERT INTO t1 VALUES (1,
'init');
1496 UPDATE t1 SET a = 2, b = CONCAT(b,
'+con1') WHERE a = 1;
1500 --echo
# Switch to connection con2
1505 --echo # Switch
to connection con1
1513 let $bug31310= `SELECT 1 - COUNT(*) FROM t2`;
1518 --echo
# Switch to connection con2
1523 --enable_abort_on_error
1529 # Bug#30747 Create table with identical constraint names behaves incorrectly
1532 if ($test_foreign_keys)
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;
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;
1563 # Bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB and
1564 # auto_increment keys
1566 create
table t1 (a
int auto_increment primary key) engine=innodb;
1567 alter
table t1 order by a;
1571 # Bug #33697: ORDER BY primary key DESC vs. ref access + filesort
1572 # (reproduced only with InnoDB tables)
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)
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);
1592 -- disable_query_log
1593 -- disable_result_log
1595 -- enable_result_log
1598 EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3
ORDER BY idx DESC;
1600 SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3
ORDER BY idx DESC;
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)
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);
1615 -- disable_query_log
1616 -- disable_result_log
1618 -- enable_result_log
1621 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1622 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1624 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1625 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
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);
1634 -- disable_query_log
1635 -- disable_result_log
1637 -- enable_result_log
1640 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1641 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1643 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1644 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
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);
1654 -- disable_query_log
1655 -- disable_result_log
1657 -- enable_result_log
1660 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1661 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1663 SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
1664 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1668 --echo End of 5.1 tests
1671 --echo # Bug#43600: Incorrect
type conversion caused wrong result.
1680 filler
char(100) DEFAULT NULL,
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;
1687 -- disable_query_log
1688 -- disable_result_log
1691 -- enable_result_log
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;
1698 --echo
# End of test case for the bug#43600
1701 --echo # Bug#42643: InnoDB does not support replication of TRUNCATE
TABLE
1704 --echo # data lock, waits
for a shared metadata lock owned by a concurrent
1705 --echo # transaction.
1708 eval CREATE
TABLE t1 (a INT) ENGINE=$engine_type;
1709 INSERT INTO t1 VALUES (1),(2),(3);
1711 SELECT * FROM t1
ORDER BY a;
1713 connect (con1, localhost, root,,);
1714 --send TRUNCATE
TABLE t1;
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;
1724 --echo # Reaping TRUNCATE
TABLE
1727 --echo # Disconnect con1