1set optimizer_switch='index_condition_pushdown=on'; 2# 3# Bug#36981 - "innodb crash when selecting for update" 4# 5CREATE TABLE t1 ( 6c1 CHAR(1), 7c2 CHAR(10), 8KEY (c1) 9); 10INSERT INTO t1 VALUES ('3', null); 11SELECT * FROM t1 WHERE c1='3' FOR UPDATE; 12c1 c2 133 NULL 14DROP TABLE t1; 15CREATE TABLE t1 (a INT); 16INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); 17CREATE TABLE t2 (a INT); 18INSERT INTO t2 SELECT A.a + 10*(B.a + 10*C.a) FROM t1 A, t1 B, t1 C; 19CREATE TABLE t3 ( 20c1 CHAR(10) NOT NULL, 21c2 CHAR(10) NOT NULL, 22c3 CHAR(200) NOT NULL, 23KEY (c1) 24); 25INSERT INTO t3 26SELECT CONCAT('c-',1000+t2.a,'=w'), CONCAT('c-',1000+ t2.a,'=w'), 'filler' 27 FROM t2; 28INSERT INTO t3 29SELECT CONCAT('c-',1000+t2.a,'=w'), CONCAT('c-',2000+t2.a,'=w'), 'filler-1' 30 FROM t2; 31INSERT INTO t3 32SELECT CONCAT('c-',1000+t2.a,'=w'), CONCAT('c-',3000+t2.a,'=w'), 'filler-2' 33 FROM t2; 34SELECT c1,c3 FROM t3 WHERE c1 >= 'c-1994=w' and c1 != 'c-1996=w' FOR UPDATE; 35c1 c3 36c-1994=w filler 37c-1994=w filler-1 38c-1994=w filler-2 39c-1995=w filler 40c-1995=w filler-1 41c-1995=w filler-2 42c-1997=w filler 43c-1997=w filler-1 44c-1997=w filler-2 45c-1998=w filler 46c-1998=w filler-1 47c-1998=w filler-2 48c-1999=w filler 49c-1999=w filler-1 50c-1999=w filler-2 51DROP TABLE t1,t2,t3; 52# 53# Bug#43360 - Server crash with a simple multi-table update 54# 55CREATE TABLE t1 ( 56a CHAR(2) NOT NULL PRIMARY KEY, 57b VARCHAR(20) NOT NULL, 58KEY (b) 59); 60CREATE TABLE t2 ( 61a CHAR(2) NOT NULL PRIMARY KEY, 62b VARCHAR(30) NOT NULL, 63KEY (b) 64); 65INSERT INTO t1 VALUES 66('AB','MySQL AB'), 67('JA','Sun Microsystems'), 68('MS','Microsoft'), 69('IB','IBM- Inc.'), 70('GO','Google Inc.'); 71INSERT INTO t2 VALUES 72('AB','Sweden'), 73('JA','USA'), 74('MS','United States of America'), 75('IB','North America'), 76('GO','South America'); 77UPDATE t1,t2 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'United%'; 78SELECT * FROM t1 ORDER BY a; 79a b 80AB MySQL AB 81GO Google Inc. 82IB IBM- Inc. 83JA Sun Microsystems 84MS Microsoft 85SELECT * FROM t2 ORDER BY a; 86a b 87AB Sweden 88GO South America 89IB North America 90JA USA 91MS United States of America 92DROP TABLE t1,t2; 93# 94# Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on 95# 96CREATE TABLE t ( 97dummy INT PRIMARY KEY, 98a INT UNIQUE, 99b INT 100); 101INSERT INTO t VALUES (1,1,1),(3,3,3),(5,5,5); 102SELECT * FROM t WHERE a > 2 FOR UPDATE; 103dummy a b 1043 3 3 1055 5 5 106DROP TABLE t; 107# 108# Bug#35080 - Innodb crash at mem_block_get_len line 72 109# 110CREATE TABLE t1 ( 111t1_autoinc INT(11) NOT NULL AUTO_INCREMENT, 112uuid VARCHAR(36) DEFAULT NULL, 113PRIMARY KEY (t1_autoinc), 114KEY k (uuid) 115); 116CREATE TABLE t2 ( 117t2_autoinc INT(11) NOT NULL AUTO_INCREMENT, 118uuid VARCHAR(36) DEFAULT NULL, 119date DATETIME DEFAULT NULL, 120PRIMARY KEY (t2_autoinc), 121KEY k (uuid) 122); 123CREATE VIEW v1 AS 124SELECT t1_autoinc, uuid 125FROM t1 126WHERE (ISNULL(uuid) OR (uuid like '%-%')); 127CREATE VIEW v2 AS 128SELECT t2_autoinc, uuid, date 129FROM t2 130WHERE (ISNULL(uuid) OR (LENGTH(uuid) = 36)); 131CREATE PROCEDURE delete_multi (IN uuid CHAR(36)) 132DELETE v1, v2 FROM v1 INNER JOIN v2 133ON v1.uuid = v2.uuid 134WHERE v1.uuid = @uuid; 135SET @uuid = UUID(); 136INSERT INTO v1 (uuid) VALUES (@uuid); 137INSERT INTO v2 (uuid, date) VALUES (@uuid, '2009-09-09'); 138CALL delete_multi(@uuid); 139DROP procedure delete_multi; 140DROP table t1,t2; 141DROP view v1,v2; 142# 143# Bug#41996 - multi-table delete crashes server (InnoDB table) 144# 145CREATE TABLE t1 ( 146b BIGINT, 147i INT, 148KEY (b) 149); 150INSERT INTO t1 VALUES (2, 2); 151DELETE t1 FROM t1 a, t1 WHERE a.i=t1.b; 152DROP TABLE t1; 153# 154# Bug#43448 - Server crashes on multi table delete with Innodb 155# 156CREATE TABLE t1 ( 157id1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 158t CHAR(12) 159); 160CREATE TABLE t2 ( 161id2 INT NOT NULL, 162t CHAR(12) 163); 164CREATE TABLE t3( 165id3 INT NOT NULL, 166t CHAR(12), 167INDEX(id3) 168); 169CREATE PROCEDURE insert_data () 170BEGIN 171DECLARE i1 INT DEFAULT 20; 172DECLARE i2 INT; 173DECLARE i3 INT; 174WHILE (i1 > 0) DO 175INSERT INTO t1(t) VALUES (i1); 176SET i2 = 2; 177WHILE (i2 > 0) DO 178INSERT INTO t2(id2, t) VALUES (i1, i2); 179SET i3 = 2; 180WHILE (i3 > 0) DO 181INSERT INTO t3(id3, t) VALUES (i1, i2); 182SET i3 = i3 -1; 183END WHILE; 184SET i2 = i2 -1; 185END WHILE; 186SET i1 = i1 - 1; 187END WHILE; 188END | 189CALL insert_data(); 190SELECT COUNT(*) FROM t1 WHERE id1 > 10; 191COUNT(*) 19210 193SELECT COUNT(*) FROM t2 WHERE id2 > 10; 194COUNT(*) 19520 196SELECT COUNT(*) FROM t3 WHERE id3 > 10; 197COUNT(*) 19840 199DELETE t1, t2, t3 200FROM t1, t2, t3 201WHERE t1.id1 = t2.id2 AND t2.id2 = t3.id3 AND t1.id1 > 3; 202SELECT COUNT(*) FROM t1; 203COUNT(*) 2043 205SELECT COUNT(*) FROM t2; 206COUNT(*) 2076 208SELECT COUNT(*) FROM t3; 209COUNT(*) 21012 211DROP PROCEDURE insert_data; 212DROP TABLE t1, t2, t3; 213# 214# Bug#42580 - Innodb's ORDER BY ..LIMIT returns no rows for 215# null-safe operator <=> NULL 216# 217CREATE TABLE t1( 218c1 DATE NOT NULL, 219c2 DATE NULL, 220c3 DATETIME, 221c4 TIMESTAMP, 222PRIMARY KEY(c1), 223UNIQUE(c2) 224); 225 226INSERT INTO t1 VALUES('0000-00-00', '0000-00-00', '2008-01-04', '2008-01-05'); 227INSERT INTO t1 VALUES('2007-05-25', '2007-05-25', '2007-05-26', '2007-05-26'); 228INSERT INTO t1 VALUES('2008-01-01', NULL , '2008-01-02', '2008-01-03'); 229INSERT INTO t1 VALUES('2008-01-17', NULL , NULL , '2009-01-29'); 230INSERT INTO t1 VALUES('2009-01-29', '2009-01-29', '2009-01-29', '2009-01-29'); 231 232SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c1,c2; 233c1 c2 c3 c4 2342008-01-01 NULL 2008-01-02 00:00:00 2008-01-03 00:00:00 2352008-01-17 NULL NULL 2009-01-29 00:00:00 236 237SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2; 238c1 c2 c3 c4 2392008-01-01 NULL 2008-01-02 00:00:00 2008-01-03 00:00:00 2402008-01-17 NULL NULL 2009-01-29 00:00:00 241 242DROP TABLE t1; 243# 244# Bug#43617 - Innodb returns wrong results with timestamp's range value 245# in IN clause 246# (Note: Fixed by patch for BUG#42580) 247# 248CREATE TABLE t1( 249c1 TIMESTAMP NOT NULL, 250c2 TIMESTAMP NULL, 251c3 DATE, 252c4 DATETIME, 253PRIMARY KEY(c1), 254UNIQUE INDEX(c2) 255); 256INSERT INTO t1 VALUES 257('0000-00-00 00:00:00','0000-00-00 00:00:00','2008-01-04','2008-01-05 00:00:00'), 258('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02 00:00:00'), 259('1999-01-01 00:00:00','1999-01-01 00:00:00', NULL, NULL), 260('2007-05-23 09:15:28','2007-05-23 09:15:28','2007-05-24','2007-05-24 09:15:28'), 261('2007-05-27 00:00:00','2007-05-25 00:00:00','2007-05-26','2007-05-26 00:00:00'), 262('2008-01-01 00:00:00', NULL, '2008-01-02','2008-01-03 00:00:00'), 263('2009-01-29 11:11:27','2009-01-29 11:11:27','2009-01-29','2009-01-29 11:11:27'), 264('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06 00:00:00'); 265 266SELECT * 267FROM t1 268WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') 269ORDER BY c2; 270c1 c2 c3 c4 2712038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00 272 273SELECT * 274FROM t1 275WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') 276ORDER BY c2 LIMIT 2; 277c1 c2 c3 c4 2782038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00 279 280SELECT * 281FROM t1 282WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') 283ORDER BY c2 DESC; 284c1 c2 c3 c4 2852038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00 286 287SELECT * 288FROM t1 289WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') 290ORDER BY c2 DESC LIMIT 2; 291c1 c2 c3 c4 2922038-01-09 03:14:07 2038-01-09 03:14:07 2009-01-05 2009-01-06 00:00:00 293 294DROP TABLE t1; 295# 296# Bug#43249 - Innodb returns zero time for the time column 297# with <=> NULL order by limit 298# (Note: Fixed by patch for BUG#42580) 299# 300CREATE TABLE t1( 301c1 TIME NOT NULL, 302c2 TIME NULL, 303c3 DATE, 304PRIMARY KEY(c1), 305UNIQUE INDEX(c2) 306); 307INSERT INTO t1 VALUES('8:29:45',NULL,'2009-02-01'); 308 309SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c2 LIMIT 2; 310c1 c2 c3 31108:29:45 NULL 2009-02-01 312 313SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c2 LIMIT 2; 314c1 c2 c3 31508:29:45 NULL 2009-02-01 316DROP TABLE t1; 317# 318# BUG#43618: MyISAM&Maria returns wrong results with 'between' 319# on timestamp 320# 321CREATE TABLE t1( 322ts TIMESTAMP NOT NULL, 323c char NULL, 324PRIMARY KEY(ts) 325); 326INSERT INTO t1 VALUES 327('1971-01-01','a'), 328('2007-05-25','b'), 329('2008-01-01','c'), 330('2038-01-09','d'); 331 332# Execute select with invalid timestamp, desc ordering 333SELECT * 334FROM t1 335WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' 336ORDER BY ts DESC 337LIMIT 2; 338ts c 3392008-01-01 00:00:00 c 3402007-05-25 00:00:00 b 341 342# Should use index condition 343EXPLAIN 344SELECT * 345FROM t1 346WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' 347ORDER BY ts DESC 348LIMIT 2; 349id select_type table type possible_keys key key_len ref rows Extra 3501 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using index condition 351 352DROP TABLE t1; 353# 354# BUG#49906: Assertion failed - Field_varstring::val_str in field.cc 355# 356CREATE TABLE t1 ( 357f1 VARCHAR(1024), 358f2 VARCHAR(10), 359INDEX test_idx USING BTREE (f2,f1(5)) 360); 361INSERT INTO t1 VALUES ('a','c'), ('b','d'); 362SELECT f1 363FROM t1 364WHERE f2 LIKE 'd' 365ORDER BY f1; 366f1 367b 368DROP TABLE t1; 369# 370# Bug#52660 - "Perf. regr. using ICP for MyISAM on range queries on 371# an index containing TEXT" 372# 373CREATE TABLE t1 (a INT); 374INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); 375CREATE TABLE t2 (a INT); 376INSERT INTO t2 SELECT A.a + 10*(B.a) FROM t1 A, t1 B; 377CREATE TABLE t3 ( 378c1 TINYTEXT NOT NULL, 379i1 INT NOT NULL, 380KEY (c1(6),i1) 381); 382INSERT INTO t3 SELECT CONCAT('c-',1000+t2.a,'=w'), 1 FROM t2; 383EXPLAIN SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2; 384id select_type table type possible_keys key key_len ref rows Extra 3851 SIMPLE t3 range c1 c1 12 NULL 2 Using where 386SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2; 387c1 388DROP TABLE t1, t2, t3; 389# 390# Bug#57372 "Multi-table updates and deletes fail when running with ICP 391# against InnoDB" 392# 393CREATE TABLE t1 ( 394a INT KEY, 395b INT 396) ENGINE = INNODB; 397CREATE TABLE t2 ( 398a INT KEY, 399b INT 400) ENGINE = INNODB; 401INSERT INTO t1 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105); 402INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); 403UPDATE t1, t2 404SET t1.a = t1.a + 100, t2.b = t1.a + 10 405WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b - 100; 406SELECT * FROM t1; 407a b 4081 101 409102 102 410103 103 411104 104 4125 105 413SELECT * FROM t2; 414a b 4151 1 4162 12 4173 13 4184 14 4195 5 420DROP TABLE t1, t2; 421# 422# Bug#52605 - "Adding LIMIT 1 clause to query with complex range 423# predicate causes wrong results" 424# 425CREATE TABLE t1 ( 426pk INT NOT NULL, 427c1 INT, 428PRIMARY KEY (pk), 429KEY k1 (c1) 430); 431INSERT INTO t1 VALUES (1,NULL); 432INSERT INTO t1 VALUES (2,6); 433INSERT INTO t1 VALUES (3,NULL); 434INSERT INTO t1 VALUES (4,6); 435INSERT INTO t1 VALUES (5,NULL); 436INSERT INTO t1 VALUES (6,NULL); 437INSERT INTO t1 VALUES (7,9); 438INSERT INTO t1 VALUES (8,0); 439SELECT pk, c1 440FROM t1 441WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240 442ORDER BY c1 443LIMIT 1; 444pk c1 4454 6 446EXPLAIN SELECT pk, c1 447FROM t1 448WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240 449ORDER BY c1 450LIMIT 1; 451id select_type table type possible_keys key key_len ref rows Extra 4521 SIMPLE t1 range PRIMARY,k1 k1 5 NULL 4 Using index condition; Using where 453DROP TABLE t1; 454# 455# Bug#42991 "invalid memory access and/or crash when using 456# index condition pushdown + InnoDB" 457# 458CREATE TABLE t1 ( 459c1 TINYTEXT NOT NULL, 460c2 INT NOT NULL, 461PRIMARY KEY (c2), 462KEY id1 (c1(4)) 463); 464INSERT INTO t1 VALUES ('Anastasia', 5); 465INSERT INTO t1 VALUES ('Karianne', 4); 466SELECT * FROM t1 WHERE (c1 <= '6566-06-15' AND c2 <> 3); 467c1 c2 468EXPLAIN SELECT * FROM t1 WHERE (c1 <= '6566-06-15' AND c2 <> 3); 469id select_type table type possible_keys key key_len ref rows Extra 4701 SIMPLE t1 range PRIMARY,id1 id1 6 NULL 1 Using where 471DROP TABLE t1; 472# 473# Bug#56529 - "Crash due to long semaphore wait in InnoDB 474# with ICP and subqueries" 475# 476CREATE TABLE t1 ( 477col_int_nokey INTEGER, 478col_int_key INTEGER, 479col_varchar_key VARCHAR(1), 480KEY (col_int_key), 481KEY (col_varchar_key, col_int_key) 482) stats_persistent=0; 483INSERT INTO t1 VALUES (NULL,2,'w'); 484INSERT INTO t1 VALUES (7,9,'m'); 485INSERT INTO t1 VALUES (9,3,'m'); 486INSERT INTO t1 VALUES (7,9,'k'); 487INSERT INTO t1 VALUES (4,NULL,'r'); 488INSERT INTO t1 VALUES (2,9,'t'); 489INSERT INTO t1 VALUES (6,3,'j'); 490INSERT INTO t1 VALUES (8,8,'u'); 491INSERT INTO t1 VALUES (NULL,8,'h'); 492INSERT INTO t1 VALUES (5,53,'o'); 493INSERT INTO t1 VALUES (NULL,0,NULL); 494INSERT INTO t1 VALUES (6,5,'k'); 495INSERT INTO t1 VALUES (188,166,'e'); 496INSERT INTO t1 VALUES (2,3,'n'); 497INSERT INTO t1 VALUES (1,0,'t'); 498INSERT INTO t1 VALUES (1,1,'c'); 499INSERT INTO t1 VALUES (0,9,'m'); 500INSERT INTO t1 VALUES (9,5,'y'); 501INSERT INTO t1 VALUES (NULL,6,'f'); 502CREATE TABLE t2 ( 503c1 INTEGER NOT NULL 504) stats_persistent=0; 505EXPLAIN SELECT table1.col_int_nokey 506FROM t1 AS table1 STRAIGHT_JOIN ( 507t1 AS table2 INNER JOIN t1 AS table3 508ON table3.col_varchar_key = table2.col_varchar_key) 509ON table3.col_int_nokey = table1.col_int_key 510WHERE table3.col_int_key != SOME ( SELECT c1 FROM t2 ); 511id select_type table type possible_keys key key_len ref rows Extra 5121 PRIMARY table1 ALL col_int_key NULL NULL NULL 19 NULL 5131 PRIMARY table3 ALL col_varchar_key NULL NULL NULL 19 Using where; Using join buffer (Block Nested Loop) 5141 PRIMARY table2 ref col_varchar_key col_varchar_key 4 test.table3.col_varchar_key 2 Using index 5152 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 516SELECT table1.col_int_nokey 517FROM t1 AS table1 STRAIGHT_JOIN ( 518t1 AS table2 INNER JOIN t1 AS table3 519ON table3.col_varchar_key = table2.col_varchar_key) 520ON table3.col_int_nokey = table1.col_int_key 521WHERE table3.col_int_key != SOME ( SELECT c1 FROM t2 ); 522col_int_nokey 523DROP TABLE t1, t2; 524# 525# Bug#58243 "RQG test optimizer_subquery causes server crash 526# when running with ICP" 527# 528CREATE TABLE t1 ( 529pk INTEGER NOT NULL, 530c1 INTEGER NOT NULL, 531c2 INTEGER NOT NULL, 532PRIMARY KEY (pk) 533); 534INSERT INTO t1 VALUES (1,6,7); 535CREATE TABLE t2 ( 536c1 INTEGER NOT NULL 537); 538EXPLAIN SELECT t1.c1 539FROM t1 540WHERE t1.pk < 317 AND 2 IN (SELECT COUNT(t2.c1) 541FROM t2) 542ORDER BY t1.c2; 543id select_type table type possible_keys key key_len ref rows Extra 5441 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 5452 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 546SELECT t1.c1 547FROM t1 548WHERE t1.pk < 317 AND 2 IN (SELECT COUNT(t2.c1) 549FROM t2) 550ORDER BY t1.c2; 551c1 552DROP TABLE t1, t2; 553CREATE TABLE t1 ( 554i1 INTEGER NOT NULL, 555c1 VARCHAR(1) NOT NULL 556); 557INSERT INTO t1 VALUES (2,'w'); 558CREATE TABLE t2 ( 559i1 INTEGER NOT NULL, 560c1 VARCHAR(1) NOT NULL, 561c2 VARCHAR(1) NOT NULL, 562KEY (c1, i1) 563); 564INSERT INTO t2 VALUES (8,'d','d'); 565INSERT INTO t2 VALUES (4,'v','v'); 566CREATE TABLE t3 ( 567c1 VARCHAR(1) NOT NULL 568); 569INSERT INTO t3 VALUES ('v'); 570EXPLAIN SELECT i1 571FROM t1 572WHERE EXISTS (SELECT t2.c1 573FROM (t2 INNER JOIN t3 ON (t3.c1 = t2.c1)) 574WHERE t2.c2 != t1.c1 AND t2.c2 = (SELECT MIN(t3.c1) 575FROM t3)); 576id select_type table type possible_keys key key_len ref rows Extra 5771 PRIMARY t1 system NULL NULL NULL NULL 1 NULL 5782 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 1 NULL 5792 DEPENDENT SUBQUERY t2 ref c1 c1 3 const 1 Using where 5803 SUBQUERY t3 system NULL NULL NULL NULL 1 NULL 581SELECT i1 582FROM t1 583WHERE EXISTS (SELECT t2.c1 584FROM (t2 INNER JOIN t3 ON (t3.c1 = t2.c1)) 585WHERE t2.c2 != t1.c1 AND t2.c2 = (SELECT MIN(t3.c1) 586FROM t3)); 587i1 5882 589DROP TABLE t1,t2,t3; 590# 591# Bug#58015 "Assert in row_sel_field_store_in_mysql_format 592# when running innodb_mrr_icp test" 593# 594create table t1 (a char(2) charset utf8,b double, primary key (a(1)),key (b)); 595insert into t1 values ('',1); 596select 1 from t1 where b <= 1 and a <> ''; 5971 598drop table t1; 599# 600# Bug#59259 "Incorrect rows returned for a correlated subquery 601# when ICP is on" 602# 603CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB; 604INSERT INTO t1 VALUES (11,0); 605INSERT INTO t1 VALUES (12,5); 606INSERT INTO t1 VALUES (15,0); 607CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB; 608INSERT INTO t2 VALUES (11,1); 609INSERT INTO t2 VALUES (12,2); 610INSERT INTO t2 VALUES (15,4); 611SELECT * FROM t1 612WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE t1.i); 613pk i 61412 5 615DROP TABLE t1, t2; 616# 617# Bug #58816 "Extra temporary duplicate rows in result set when 618# switching ICP off" 619# 620set @save_optimizer_switch_bug58816= @@optimizer_switch; 621CREATE TABLE t1 ( 622pk INT NOT NULL, 623c1 INT NOT NULL, 624PRIMARY KEY (pk) 625); 626INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1); 627EXPLAIN SELECT pk, c1 FROM t1 WHERE pk <> 3; 628id select_type table type possible_keys key key_len ref rows Extra 6291 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 Using where 630SET SESSION optimizer_switch='index_condition_pushdown=off'; 631SELECT pk, c1 FROM t1 WHERE pk <> 3; 632pk c1 6331 9 6342 7 6354 3 6365 1 637DROP TABLE t1; 638set optimizer_switch= @save_optimizer_switch_bug58816; 639# 640# Bug#58837: ICP crash or valgrind error due to uninitialized 641# value in innobase_index_cond 642# 643CREATE TABLE t1 ( 644t1_int INT, 645t1_time TIME 646); 647CREATE TABLE t2 ( 648t2_int int PRIMARY KEY, 649t2_int2 INT 650); 651INSERT INTO t2 VALUES (); 652INSERT INTO t1 VALUES (); 653 654SELECT * 655FROM t1 AS t1a 656WHERE NOT EXISTS 657(SELECT * 658FROM t1 AS t1b 659WHERE t1b.t1_int NOT IN 660(SELECT t2.t2_int 661FROM t2 662WHERE t1b.t1_time LIKE t1b.t1_int 663OR t1b.t1_time <> t2.t2_int2 664AND 6=7 665) 666) 667;; 668t1_int t1_time 669 670EXPLAIN SELECT * 671FROM t1 AS t1a 672WHERE NOT EXISTS 673(SELECT * 674FROM t1 AS t1b 675WHERE t1b.t1_int NOT IN 676(SELECT t2.t2_int 677FROM t2 678WHERE t1b.t1_time LIKE t1b.t1_int 679OR t1b.t1_time <> t2.t2_int2 680AND 6=7 681) 682) 683;; 684id select_type table type possible_keys key key_len ref rows Extra 6851 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 6862 SUBQUERY t1b system NULL NULL NULL NULL 1 NULL 6873 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 688 689DROP TABLE t1,t2; 690# 691# Bug#59186 Wrong results of join when ICP is enabled 692# 693CREATE TABLE t1 ( 694pk INTEGER NOT NULL, 695c1 VARCHAR(3) NOT NULL, 696PRIMARY KEY (pk) 697); 698INSERT INTO t1 VALUES (1,'y'),(0,'or'); 699CREATE TABLE t2 ( 700pk INTEGER NOT NULL, 701c1 VARCHAR(3) NOT NULL, 702c2 VARCHAR(6) NOT NULL, 703PRIMARY KEY (pk) 704); 705INSERT INTO t2 VALUES (6,'y','RPOYT'),(10,'m','JINQE'); 706EXPLAIN SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 707WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR 708(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); 709id select_type table type possible_keys key key_len ref rows Extra 7101 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition 7111 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Using join buffer (Block Nested Loop) 712SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 713WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR 714(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); 715c2 716DROP TABLE t1, t2; 717# 718# Bug#58838 "Wrong results with HAVING + LIMIT without GROUP BY when 719# ICP is enabled" 720# 721CREATE TABLE t1 ( 722pk INT NOT NULL, 723c1 INT, 724PRIMARY KEY (pk), 725KEY col_int_key (c1) 726); 727INSERT INTO t1 VALUES (1,37),(2,8),(3,-25),(4,NULL),(5,55); 728SELECT pk FROM t1 WHERE c1 <> 1 HAVING pk = 3 ORDER BY pk LIMIT 0; 729pk 730SELECT pk FROM t1 WHERE c1 <> 1 HAVING pk = 3 ORDER BY pk LIMIT 1; 731pk 7323 733SELECT pk FROM t1 WHERE c1 <> 1 HAVING pk = 3 ORDER BY pk LIMIT 2; 734pk 7353 736SELECT pk FROM t1 WHERE c1 <> 1 HAVING pk = 3 ORDER BY pk LIMIT 5; 737pk 7383 739DROP TABLE t1; 740# 741# Bug#59483 "Crash on INSERT/REPLACE in 742# rec_convert_dtuple_to_rec_comp with ICP on" 743# 744CREATE TABLE t1 ( 745pk INTEGER AUTO_INCREMENT PRIMARY KEY, 746i1 INTEGER, 747c1 CHAR(6), 748i2 INTEGER NOT NULL, 749KEY (i2) 750); 751INSERT INTO t1 VALUES 752(NULL, 4, 'that', 8), 753(NULL, 1, 'she', 6), 754(NULL, 6, 'tell', 2); 755SELECT * FROM t1 WHERE i2 IN (3, 6) LIMIT 2 FOR UPDATE; 756pk i1 c1 i2 7572 1 she 6 758INSERT INTO t1 (i2) VALUES (1); 759DROP TABLE t1; 760# 761# Bug #11766678 - 59843: 762# USING UNINITIALISED VALUE IN USES_INDEX_FIELDS_ONLY 763# 764CREATE TABLE t1 ( 765col999 FLOAT NOT NULL, 766COL1000 VARBINARY(179) NOT NULL, 767col1003 DATE DEFAULT NULL, 768KEY idx4267 (col1000, col1003) 769); 770INSERT INTO t1 VALUES (),(); 771Warnings: 772Warning 1364 Field 'col999' doesn't have a default value 773Warning 1364 Field 'COL1000' doesn't have a default value 774SELECT col999 FROM t1 WHERE col1000 = "3" AND col1003 <=> sysdate(); 775col999 776DROP TABLE t1; 777# 778# Bug#11873324 "WRONG RESULT WITH ICP AND STRAIGHT_JOIN" 779# 780CREATE TABLE t1 ( 781pk INTEGER NOT NULL, 782i1 INTEGER, 783PRIMARY KEY (pk), 784KEY col_int_key (i1) 785); 786INSERT INTO t1 VALUES (14,NULL), (18,133); 787CREATE TABLE t2 ( 788pk INTEGER NOT NULL, 789i1 INTEGER, 790c1 VARCHAR(1), 791PRIMARY KEY (pk), 792KEY col_int_key (i1) 793); 794INSERT INTO t2 VALUES (1,7,'f'); 795set @old_opt_switch=@@optimizer_switch; 796EXPLAIN SELECT t1.i1 797FROM t1 798WHERE t1.i1 NOT IN 799( SELECT STRAIGHT_JOIN SUBQUERY_t1.pk 800FROM t1 AS SUBQUERY_t1 801JOIN t2 AS SUBQUERY_t2 802ON SUBQUERY_t2.i1 = SUBQUERY_t1.pk 803WHERE SUBQUERY_t1.i1 > 0 804OR SUBQUERY_t2.c1 = 'a' 805); 806id select_type table type possible_keys key key_len ref rows Extra 8071 PRIMARY t1 index NULL col_int_key 5 NULL 2 Using where; Using index 8082 DEPENDENT SUBQUERY SUBQUERY_t1 eq_ref PRIMARY,col_int_key PRIMARY 4 func 1 Using where; Full scan on NULL key 8092 DEPENDENT SUBQUERY SUBQUERY_t2 ALL col_int_key NULL NULL NULL 1 Using where; Using join buffer (Block Nested Loop) 810SELECT t1.i1 811FROM t1 812WHERE t1.i1 NOT IN 813( SELECT STRAIGHT_JOIN SUBQUERY_t1.pk 814FROM t1 AS SUBQUERY_t1 815JOIN t2 AS SUBQUERY_t2 816ON SUBQUERY_t2.i1 = SUBQUERY_t1.pk 817WHERE SUBQUERY_t1.i1 > 0 818OR SUBQUERY_t2.c1 = 'a' 819); 820i1 821NULL 822133 823set @@optimizer_switch=@old_opt_switch; 824DROP TABLE t1,t2; 825# 826# Bug#11876420 "MISSING ROW IN RESULT WITH SUBQUERY + IN + XOR + 827# NULL VALUES AND ICP ENABLED" 828# 829CREATE TABLE t1 ( 830i1 INTEGER, 831c1 VARCHAR(1), 832KEY col_varchar_key (c1) 833); 834INSERT INTO t1 VALUES (1,'j'), (0,'e'), (210,'f'), (8,'v'), (7,'x'), 835(5,'m'), (NULL,'c'); 836CREATE TABLE t2 ( 837i1 INTEGER, 838c1 VARCHAR(1), 839KEY col_varchar_key (c1) 840); 841INSERT INTO t2 VALUES (8,NULL); 842CREATE TABLE t3 ( 843i1 INTEGER, 844c1 VARCHAR(1), 845KEY col_varchar_key (c1) 846) ENGINE=InnoDB; 847INSERT INTO t3 VALUES (NULL,'w'), (1,NULL), (2,'d'); 848set @old_opt_switch=@@optimizer_switch; 849EXPLAIN SELECT i1 850FROM t3 851WHERE c1 IN 852( SELECT t1.c1 853FROM t2 JOIN t1 854ON t2.i1 >= t1.i1 855WHERE t1.c1 > t2.c1 856) 857XOR i1; 858id select_type table type possible_keys key key_len ref rows Extra 8591 PRIMARY t3 ALL NULL NULL NULL NULL 3 Using where 8602 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 861SELECT i1 862FROM t3 863WHERE c1 IN 864( SELECT t1.c1 865FROM t2 JOIN t1 866ON t2.i1 >= t1.i1 867WHERE t1.c1 > t2.c1 868) 869XOR i1; 870i1 8711 8722 873set @@optimizer_switch=@old_opt_switch; 874DROP TABLE t1, t2, t3; 875# 876# Bug#12355958 "FAILING ASSERTION: TRX->LOCK.N_ACTIVE_THRS == 1" 877# 878CREATE TABLE t1 ( 879pk INTEGER PRIMARY KEY, 880a INTEGER NOT NULL, 881b CHAR(1), 882KEY(b) 883); 884INSERT INTO t1 VALUES (23,5,'d'); 885EXPLAIN SELECT a1.pk 886FROM t1 AS a1 JOIN (SELECT * FROM t1 LIMIT 1) AS a2 ON a2.b = a1.b 887WHERE a1.a = (SELECT pk FROM t1 LIMIT 1) 888AND (a1.a != a2.a OR a1.b IS NULL); 889id select_type table type possible_keys key key_len ref rows Extra 8901 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 8913 SUBQUERY t1 system NULL NULL NULL NULL 1 NULL 8922 DERIVED t1 system NULL NULL NULL NULL 1 NULL 893SELECT a1.pk 894FROM t1 AS a1 JOIN (SELECT * FROM t1 LIMIT 1) AS a2 ON a2.b = a1.b 895WHERE a1.a = (SELECT pk FROM t1 LIMIT 1) 896AND (a1.a != a2.a OR a1.b IS NULL); 897pk 898CREATE VIEW v1 AS SELECT * FROM t1; 899EXPLAIN SELECT a1.pk 900FROM v1 AS a1 JOIN (SELECT * FROM v1 LIMIT 1) AS a2 ON a2.b = a1.b 901WHERE a1.a = (SELECT pk FROM v1 LIMIT 1) 902AND (a1.a != a2.a OR a1.b IS NULL); 903id select_type table type possible_keys key key_len ref rows Extra 9041 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 9053 SUBQUERY t1 system NULL NULL NULL NULL 1 NULL 9062 DERIVED t1 system NULL NULL NULL NULL 1 NULL 907SELECT a1.pk 908FROM v1 AS a1 JOIN (SELECT * FROM v1 LIMIT 1) AS a2 ON a2.b = a1.b 909WHERE a1.a = (SELECT pk FROM v1 LIMIT 1) 910AND (a1.a != a2.a OR a1.b IS NULL); 911pk 912DROP VIEW v1; 913DROP TABLE t1; 914# 915# BUG#12601961 "SEGFAULT IN HANDLER::COMPARE_KEY2" 916# BUG#12724899 "SELECT STRAIGHT_JOIN QUERY GIVES 2 DATES VERSUS 917# 2 WARNINGS WITH ICP ON" 918# 919CREATE TABLE t1 ( 920pk INTEGER NOT NULL, 921i1 INTEGER NOT NULL, 922c1 VARCHAR(1) NOT NULL, 923PRIMARY KEY (pk) 924); 925INSERT INTO t1 VALUES (1,3,'j'), (20,8,'e'); 926EXPLAIN SELECT alias2.i1 927FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2 928ON alias2.pk AND alias2.pk <= alias1.c1 929WHERE alias2.pk = 1; 930id select_type table type possible_keys key key_len ref rows Extra 9311 SIMPLE alias1 ALL NULL NULL NULL NULL 2 NULL 9321 SIMPLE alias2 const PRIMARY PRIMARY 4 const 1 Using where 933SELECT alias2.i1 934FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2 935ON alias2.pk AND alias2.pk <= alias1.c1 936WHERE alias2.pk = 1; 937i1 938Warnings: 939Warning 1292 Truncated incorrect DOUBLE value: 'j' 940Warning 1292 Truncated incorrect DOUBLE value: 'e' 941DROP TABLE t1; 942# 943# BUG#12822678 - 2 MORE ROWS WHEN ICP=ON W/ STRAIGHT_JOIN 944# 945CREATE TABLE t1 ( 946i1 INTEGER NOT NULL, 947d1 DOUBLE, 948KEY k1 (d1) 949); 950INSERT INTO t1 VALUES (10,1), (17,NULL), (22,NULL); 951CREATE TABLE t2 ( 952pk INTEGER NOT NULL, 953i1 INTEGER NOT NULL, 954PRIMARY KEY (pk) 955); 956INSERT INTO t2 VALUES (4,1); 957EXPLAIN SELECT t1.d1, t2.pk, t2.i1 958FROM t1 STRAIGHT_JOIN t2 ON t2.i1 959WHERE t2.pk <> t1.d1 AND t2.pk = 4; 960id select_type table type possible_keys key key_len ref rows Extra 9611 SIMPLE t1 index NULL k1 9 NULL 3 Using index 9621 SIMPLE t2 const PRIMARY PRIMARY 4 const 1 Using where 963SELECT t1.d1, t2.pk, t2.i1 964FROM t1 STRAIGHT_JOIN t2 ON t2.i1 965WHERE t2.pk <> t1.d1 AND t2.pk = 4; 966d1 pk i1 9671 4 1 968DROP TABLE t1, t2; 969# 970# BUG#12838420 "DUPLICATE VALUES FOR GROUP-BY COLUMN WHEN JOIN 971# BUFFERING IS OFF" 972# 973CREATE TABLE t1 ( 974col_int_key INT, 975pk INT, 976PRIMARY KEY (pk), 977KEY (col_int_key) 978); 979INSERT INTO t1 VALUES (2,3),(3,2),(3,5),(4,6); 980CREATE TABLE t2 ( 981col_int_key INT, 982pk INT, 983PRIMARY KEY (pk), 984KEY (col_int_key) 985); 986INSERT INTO t2 VALUES (0,9),(3,10),(4,6),(6,1),(100,3),(200,5); 987set @old_opt_switch=@@optimizer_switch; 988SET optimizer_switch="block_nested_loop=off"; 989EXPLAIN SELECT t2.col_int_key AS field1 990FROM t2 USE INDEX(col_int_key) STRAIGHT_JOIN t1 ON t2.col_int_key 991WHERE t2.pk < 7 AND t2.col_int_key <> 7 992GROUP BY field1; 993id select_type table type possible_keys key key_len ref rows Extra 9941 SIMPLE t2 ALL col_int_key NULL NULL NULL 6 Using where; Using temporary; Using filesort 9951 SIMPLE t1 index NULL PRIMARY 4 NULL 4 Using index 996SELECT t2.col_int_key AS field1 997FROM t2 USE INDEX(col_int_key) STRAIGHT_JOIN t1 ON t2.col_int_key 998WHERE t2.pk < 7 AND t2.col_int_key <> 7 999GROUP BY field1; 1000field1 10014 10026 1003100 1004200 1005SET @@optimizer_switch=@old_opt_switch; 1006DROP TABLE t1,t2; 1007# 1008# Bug#12976163 "CRASH IN INDEX CONDITION PUSHDOWN CODE AGAINST 1009# A MYISAM TABLE" 1010# 1011CREATE TABLE t1 ( 1012i1 INTEGER NOT NULL, 1013i2 INTEGER NOT NULL 1014); 1015INSERT INTO t1 VALUES (14,1), (15,2), (16,3); 1016CREATE TABLE t2 ( 1017i1 INTEGER NOT NULL, 1018i2 INTEGER NOT NULL, 1019c1 TINYTEXT 1020); 1021INSERT INTO t2 1022SELECT i1, 10 * i2, "MySQL" FROM t1; 1023CREATE PROCEDURE proc1(id INTEGER) 1024BEGIN 1025SELECT i2 1026FROM ( 1027(SELECT i1, i2, NULL AS a1 FROM t1) 1028UNION 1029(SELECT i1, i2, c1 AS a1 FROM t2) 1030) u1 1031WHERE i1 = id; 1032END$$ 1033CALL proc1(15); 1034i2 10352 103620 1037DROP PROCEDURE proc1; 1038DROP TABLE t1, t2; 1039# 1040# Bug#13655397 "CRASH IN SYNC_THREAD_LEVELS_NONEMPTY_TRX" 1041# 1042CREATE TABLE t1 ( 1043i1 INTEGER NOT NULL, 1044i2 INTEGER NOT NULL, 1045KEY (i1) 1046); 1047INSERT INTO t1 VALUES (4,4), (5,5); 1048CREATE TABLE t2 ( 1049pk INTEGER NOT NULL, 1050PRIMARY KEY (pk) 1051); 1052INSERT INTO t2 VALUES (1); 1053CREATE FUNCTION f1() RETURNS INTEGER 1054RETURN (SELECT MOD(COUNT(DISTINCT pk), 10) FROM t2); 1055EXPLAIN SELECT i1, i2 FROM t1 WHERE f1() = 1 AND i1 = 5; 1056id select_type table type possible_keys key key_len ref rows Extra 10571 SIMPLE t1 ref i1 i1 4 const 1 Using where 1058SELECT i1, i2 FROM t1 WHERE f1() = 1 AND i1 = 5; 1059i1 i2 10605 5 1061DROP FUNCTION f1; 1062DROP TABLE t1, t2; 1063set optimizer_switch=default; 1064