1set optimizer_switch='index_condition_pushdown=on';
2set @save_storage_engine= @@default_storage_engine;
3set default_storage_engine=InnoDB;
4# Bug#36981 - "innodb crash when selecting for update"
5#
6CREATE TABLE t1 (
7c1 CHAR(1),
8c2 CHAR(10),
9KEY (c1)
10);
11INSERT INTO t1 VALUES ('3', null);
12SELECT * FROM t1 WHERE c1='3' FOR UPDATE;
13c1	c2
143	NULL
15DROP TABLE t1;
16CREATE TABLE t1 (a INT);
17INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
18CREATE TABLE t2 (a INT);
19INSERT INTO t2 SELECT A.a + 10*(B.a + 10*C.a) FROM t1 A, t1 B, t1 C;
20CREATE TABLE t3 (
21c1 CHAR(10) NOT NULL,
22c2 CHAR(10) NOT NULL,
23c3 CHAR(200) NOT NULL,
24KEY (c1)
25);
26INSERT INTO t3
27SELECT CONCAT('c-',1000+t2.a,'=w'), CONCAT('c-',1000+ t2.a,'=w'), 'filler'
28  FROM t2;
29INSERT INTO t3
30SELECT CONCAT('c-',1000+t2.a,'=w'), CONCAT('c-',2000+t2.a,'=w'), 'filler-1'
31  FROM t2;
32INSERT INTO t3
33SELECT CONCAT('c-',1000+t2.a,'=w'), CONCAT('c-',3000+t2.a,'=w'), 'filler-2'
34  FROM t2;
35SELECT c1,c3 FROM t3 WHERE c1 >= 'c-1994=w' and c1 != 'c-1996=w' FOR UPDATE;
36c1	c3
37c-1994=w	filler
38c-1994=w	filler-1
39c-1994=w	filler-2
40c-1995=w	filler
41c-1995=w	filler-1
42c-1995=w	filler-2
43c-1997=w	filler
44c-1997=w	filler-1
45c-1997=w	filler-2
46c-1998=w	filler
47c-1998=w	filler-1
48c-1998=w	filler-2
49c-1999=w	filler
50c-1999=w	filler-1
51c-1999=w	filler-2
52DROP TABLE t1,t2,t3;
53#
54# Bug#43360 - Server crash with a simple multi-table update
55#
56CREATE TABLE t1 (
57a CHAR(2) NOT NULL PRIMARY KEY,
58b VARCHAR(20) NOT NULL,
59KEY (b)
60);
61CREATE TABLE t2 (
62a CHAR(2) NOT NULL PRIMARY KEY,
63b VARCHAR(30) NOT NULL,
64KEY (b)
65);
66INSERT INTO t1 VALUES
67('AB','MySQL AB'),
68('JA','Sun Microsystems'),
69('MS','Microsoft'),
70('IB','IBM- Inc.'),
71('GO','Google Inc.');
72INSERT INTO t2 VALUES
73('AB','Sweden'),
74('JA','USA'),
75('MS','United States of America'),
76('IB','North America'),
77('GO','South America');
78UPDATE t1,t2 SET t1.b=UPPER(t1.b) WHERE t1.b LIKE 'United%';
79SELECT * FROM t1 ORDER BY a;
80a	b
81AB	MySQL AB
82GO	Google Inc.
83IB	IBM- Inc.
84JA	Sun Microsystems
85MS	Microsoft
86SELECT * FROM t2 ORDER BY a;
87a	b
88AB	Sweden
89GO	South America
90IB	North America
91JA	USA
92MS	United States of America
93DROP TABLE t1,t2;
94#
95# Bug#40992 - InnoDB: Crash when engine_condition_pushdown is on
96#
97CREATE TABLE t (
98dummy INT PRIMARY KEY,
99a INT UNIQUE,
100b INT
101);
102INSERT INTO t VALUES (1,1,1),(3,3,3),(5,5,5);
103SELECT * FROM t WHERE a > 2 FOR UPDATE;
104dummy	a	b
1053	3	3
1065	5	5
107DROP TABLE t;
108#
109# Bug#35080 - Innodb crash at mem_block_get_len line 72
110#
111CREATE TABLE t1 (
112t1_autoinc INT(11) NOT NULL AUTO_INCREMENT,
113uuid VARCHAR(36) DEFAULT NULL,
114PRIMARY KEY (t1_autoinc),
115KEY k (uuid)
116);
117CREATE TABLE t2 (
118t2_autoinc INT(11) NOT NULL AUTO_INCREMENT,
119uuid VARCHAR(36) DEFAULT NULL,
120date DATETIME DEFAULT NULL,
121PRIMARY KEY (t2_autoinc),
122KEY k (uuid)
123);
124CREATE VIEW v1 AS
125SELECT t1_autoinc, uuid
126FROM t1
127WHERE (ISNULL(uuid) OR (uuid like '%-%'));
128CREATE VIEW v2 AS
129SELECT t2_autoinc, uuid, date
130FROM t2
131WHERE (ISNULL(uuid) OR (LENGTH(uuid) = 36));
132CREATE PROCEDURE delete_multi (IN uuid CHAR(36))
133DELETE v1, v2 FROM v1 INNER JOIN v2
134ON v1.uuid = v2.uuid
135WHERE v1.uuid = @uuid;
136SET @uuid = UUID();
137INSERT INTO v1 (uuid) VALUES (@uuid);
138INSERT INTO v2 (uuid, date) VALUES (@uuid, '2009-09-09');
139CALL delete_multi(@uuid);
140DROP procedure delete_multi;
141DROP table t1,t2;
142DROP view v1,v2;
143#
144# Bug#41996 - multi-table delete crashes server (InnoDB table)
145#
146CREATE TABLE t1 (
147b BIGINT,
148i INT,
149KEY (b)
150);
151INSERT INTO t1 VALUES (2, 2);
152DELETE t1 FROM t1 a, t1 WHERE a.i=t1.b;
153DROP TABLE t1;
154#
155# Bug#43448 - Server crashes on multi table delete with Innodb
156#
157CREATE TABLE t1 (
158id1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
159t CHAR(12)
160);
161CREATE TABLE t2 (
162id2 INT NOT NULL,
163t CHAR(12)
164);
165CREATE TABLE t3(
166id3 INT NOT NULL,
167t CHAR(12),
168INDEX(id3)
169);
170CREATE PROCEDURE insert_data ()
171BEGIN
172DECLARE i1 INT DEFAULT 20;
173DECLARE i2 INT;
174DECLARE i3 INT;
175WHILE (i1 > 0) DO
176INSERT INTO t1(t) VALUES (i1);
177SET i2 = 2;
178WHILE (i2 > 0) DO
179INSERT INTO t2(id2, t) VALUES (i1, i2);
180SET i3 = 2;
181WHILE (i3 > 0) DO
182INSERT INTO t3(id3, t) VALUES (i1, i2);
183SET i3 = i3 -1;
184END WHILE;
185SET i2 = i2 -1;
186END WHILE;
187SET i1 = i1 - 1;
188END WHILE;
189END |
190CALL insert_data();
191SELECT COUNT(*) FROM t1 WHERE id1 > 10;
192COUNT(*)
19310
194SELECT COUNT(*) FROM t2 WHERE id2 > 10;
195COUNT(*)
19620
197SELECT COUNT(*) FROM t3 WHERE id3 > 10;
198COUNT(*)
19940
200DELETE t1, t2, t3
201FROM t1, t2, t3
202WHERE t1.id1 = t2.id2 AND t2.id2 = t3.id3 AND t1.id1 > 3;
203SELECT COUNT(*) FROM t1;
204COUNT(*)
2053
206SELECT COUNT(*) FROM t2;
207COUNT(*)
2086
209SELECT COUNT(*) FROM t3;
210COUNT(*)
21112
212DROP PROCEDURE insert_data;
213DROP TABLE t1, t2, t3;
214#
215# Bug#42580 - Innodb's ORDER BY ..LIMIT returns no rows for
216#             null-safe operator <=> NULL
217#
218SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
219Warnings:
220Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
221CREATE TABLE t1(
222c1 DATE NOT NULL,
223c2 DATE NULL,
224c3 DATETIME,
225c4 TIMESTAMP,
226PRIMARY KEY(c1),
227UNIQUE(c2)
228);
229
230INSERT INTO t1 VALUES('0000-00-00', '0000-00-00', '2008-01-04', '2008-01-05');
231INSERT INTO t1 VALUES('2007-05-25', '2007-05-25', '2007-05-26', '2007-05-26');
232INSERT INTO t1 VALUES('2008-01-01', NULL        , '2008-01-02', '2008-01-03');
233INSERT INTO t1 VALUES('2008-01-17', NULL        , NULL        , '2009-01-29');
234INSERT INTO t1 VALUES('2009-01-29', '2009-01-29', '2009-01-29', '2009-01-29');
235
236SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c1,c2;
237c1	c2	c3	c4
2382008-01-01	NULL	2008-01-02 00:00:00	2008-01-03 00:00:00
2392008-01-17	NULL	NULL	2009-01-29 00:00:00
240
241SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2;
242c1	c2	c3	c4
2432008-01-01	NULL	2008-01-02 00:00:00	2008-01-03 00:00:00
2442008-01-17	NULL	NULL	2009-01-29 00:00:00
245
246DROP TABLE t1;
247SET sql_mode = default;
248#
249# Bug#43617 - Innodb returns wrong results with timestamp's range value
250#             in IN clause
251# (Note: Fixed by patch for BUG#42580)
252#
253SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
254Warnings:
255Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
256CREATE TABLE t1(
257c1 TIMESTAMP NOT NULL,
258c2 TIMESTAMP NULL,
259c3 DATE,
260c4 DATETIME,
261PRIMARY KEY(c1),
262UNIQUE INDEX(c2)
263);
264INSERT INTO t1 VALUES
265('0000-00-00 00:00:00','0000-00-00 00:00:00','2008-01-04','2008-01-05 00:00:00'),
266('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02 00:00:00'),
267('1999-01-01 00:00:00','1999-01-01 00:00:00', NULL,        NULL),
268('2007-05-23 09:15:28','2007-05-23 09:15:28','2007-05-24','2007-05-24 09:15:28'),
269('2007-05-27 00:00:00','2007-05-25 00:00:00','2007-05-26','2007-05-26 00:00:00'),
270('2008-01-01 00:00:00', NULL,                '2008-01-02','2008-01-03 00:00:00'),
271('2009-01-29 11:11:27','2009-01-29 11:11:27','2009-01-29','2009-01-29 11:11:27'),
272('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06 00:00:00');
273
274SELECT *
275FROM t1
276WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
277ORDER BY c2;
278c1	c2	c3	c4
2792038-01-09 03:14:07	2038-01-09 03:14:07	2009-01-05	2009-01-06 00:00:00
280
281SELECT *
282FROM t1
283WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
284ORDER BY c2 LIMIT 2;
285c1	c2	c3	c4
2862038-01-09 03:14:07	2038-01-09 03:14:07	2009-01-05	2009-01-06 00:00:00
287
288SELECT *
289FROM t1
290WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
291ORDER BY c2 DESC;
292c1	c2	c3	c4
2932038-01-09 03:14:07	2038-01-09 03:14:07	2009-01-05	2009-01-06 00:00:00
294
295SELECT *
296FROM t1
297WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07')
298ORDER BY c2 DESC LIMIT 2;
299c1	c2	c3	c4
3002038-01-09 03:14:07	2038-01-09 03:14:07	2009-01-05	2009-01-06 00:00:00
301
302DROP TABLE t1;
303SET sql_mode = default;
304#
305# Bug#43249 - Innodb returns zero time for the time column
306#             with <=> NULL order by limit
307# (Note: Fixed by patch for BUG#42580)
308#
309CREATE TABLE t1(
310c1 TIME NOT NULL,
311c2 TIME NULL,
312c3 DATE,
313PRIMARY KEY(c1),
314UNIQUE INDEX(c2)
315);
316INSERT INTO t1 VALUES('8:29:45',NULL,'2009-02-01');
317
318SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c2 LIMIT 2;
319c1	c2	c3
32008:29:45	NULL	2009-02-01
321
322SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c2 LIMIT 2;
323c1	c2	c3
32408:29:45	NULL	2009-02-01
325DROP TABLE t1;
326#
327# BUG#43618: MyISAM&Maria returns wrong results with 'between'
328#            on timestamp
329#
330CREATE TABLE t1(
331ts TIMESTAMP NOT NULL,
332c char NULL,
333PRIMARY KEY(ts)
334);
335INSERT INTO t1 VALUES
336('1971-01-01','a'),
337('2007-05-25','b'),
338('2008-01-01','c'),
339('2038-01-09','d');
340
341# Execute select with invalid timestamp, desc ordering
342SET sql_mode = '';
343SELECT *
344FROM t1
345WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
346ORDER BY ts DESC
347LIMIT 2;
348ts	c
3492008-01-01 00:00:00	c
3502007-05-25 00:00:00	b
351SET sql_mode = default;
352
353# Should use index condition
354EXPLAIN
355SELECT *
356FROM t1
357WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00'
358ORDER BY ts DESC
359LIMIT 2;
360id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3611	SIMPLE	t1	NULL	range	PRIMARY	PRIMARY	4	NULL	4	100.00	Using where
362
363DROP TABLE t1;
364#
365# BUG#49906: Assertion failed - Field_varstring::val_str in field.cc
366#
367CREATE TABLE t1 (
368f1 VARCHAR(1024),
369f2 VARCHAR(10),
370INDEX test_idx USING BTREE (f2,f1(5))
371);
372INSERT INTO t1 VALUES  ('a','c'), ('b','d');
373SELECT f1
374FROM t1
375WHERE f2 LIKE 'd'
376ORDER BY f1;
377f1
378b
379DROP TABLE t1;
380#
381# Bug#52660 - "Perf. regr. using ICP for MyISAM on range queries on
382#              an index containing TEXT"
383#
384CREATE TABLE t1 (a INT);
385INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
386CREATE TABLE t2 (a INT);
387INSERT INTO t2 SELECT A.a + 10*(B.a) FROM t1 A, t1 B;
388CREATE TABLE t3 (
389c1 TINYTEXT NOT NULL,
390i1 INT NOT NULL,
391KEY (c1(6),i1)
392);
393INSERT INTO t3 SELECT CONCAT('c-',1000+t2.a,'=w'), 1 FROM t2;
394EXPLAIN SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
395id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3961	SIMPLE	t3	NULL	range	c1	c1	12	NULL	2	33.33	Using index condition; Using where
397Warnings:
398Note	1003	/* select#1 */ select `test`.`t3`.`c1` AS `c1` from `test`.`t3` where ((`test`.`t3`.`c1` >= 'c-1004=w') and (`test`.`t3`.`c1` <= 'c-1006=w') and (`test`.`t3`.`i1` > 2))
399SELECT c1 FROM t3 WHERE c1 >= 'c-1004=w' and c1 <= 'c-1006=w' and i1 > 2;
400c1
401DROP TABLE t1, t2, t3;
402#
403# Bug#57372 "Multi-table updates and deletes fail when running with ICP
404#            against InnoDB"
405#
406CREATE TABLE t1 (
407a INT KEY,
408b INT
409) ENGINE = INNODB;
410CREATE TABLE t2 (
411a INT KEY,
412b INT
413) ENGINE = INNODB;
414INSERT INTO t1 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105);
415INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
416UPDATE t1, t2
417SET t1.a = t1.a + 100, t2.b = t1.a + 10
418WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b - 100;
419SELECT * FROM t1;
420a	b
4211	101
422102	102
423103	103
424104	104
4255	105
426SELECT * FROM t2;
427a	b
4281	1
4292	12
4303	13
4314	14
4325	5
433DROP TABLE t1, t2;
434#
435# Bug#52605 - "Adding LIMIT 1 clause to query with complex range
436#              predicate causes wrong results"
437#
438CREATE TABLE t1 (
439pk INT NOT NULL,
440c1 INT,
441PRIMARY KEY (pk),
442KEY k1 (c1)
443);
444INSERT INTO t1 VALUES (1,NULL);
445INSERT INTO t1 VALUES (2,6);
446INSERT INTO t1 VALUES (3,NULL);
447INSERT INTO t1 VALUES (4,6);
448INSERT INTO t1 VALUES (5,NULL);
449INSERT INTO t1 VALUES (6,NULL);
450INSERT INTO t1 VALUES (7,9);
451INSERT INTO t1 VALUES (8,0);
452SELECT pk, c1
453FROM t1
454WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
455ORDER BY c1
456LIMIT 1;
457pk	c1
4584	6
459EXPLAIN SELECT pk, c1
460FROM t1
461WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
462ORDER BY c1
463LIMIT 1;
464id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4651	SIMPLE	t1	NULL	range	PRIMARY,k1	k1	5	NULL	4	37.50	Using where; Using index
466Warnings:
467Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1` AS `c1` from `test`.`t1` where (((`test`.`t1`.`pk` between 4 and 5) or (`test`.`t1`.`pk` < 2)) and (`test`.`t1`.`c1` < 240)) order by `test`.`t1`.`c1` limit 1
468DROP TABLE t1;
469#
470# Bug#42991 "invalid memory access and/or crash when using
471#            index condition pushdown + InnoDB"
472#
473CREATE TABLE t1 (
474c1 TINYTEXT NOT NULL,
475c2 INT NOT NULL,
476PRIMARY KEY (c2),
477KEY id1 (c1(4))
478);
479INSERT INTO t1 VALUES ('Anastasia', 5);
480INSERT INTO t1 VALUES ('Karianne', 4);
481SELECT * FROM t1 WHERE (c1 <= '6566-06-15' AND c2 <> 3);
482c1	c2
483EXPLAIN SELECT * FROM t1 WHERE (c1 <= '6566-06-15' AND c2 <> 3);
484id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4851	SIMPLE	t1	NULL	range	PRIMARY,id1	id1	6	NULL	1	100.00	Using index condition; Using where
486Warnings:
487Note	1003	/* select#1 */ select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where ((`test`.`t1`.`c1` <= '6566-06-15') and (`test`.`t1`.`c2` <> 3))
488DROP TABLE t1;
489#
490# Bug#56529 - "Crash due to long semaphore wait in InnoDB
491#              with ICP and subqueries"
492#
493CREATE TABLE t1 (
494col_int_nokey INTEGER,
495col_int_key INTEGER,
496col_varchar_key VARCHAR(1),
497KEY (col_int_key),
498KEY (col_varchar_key, col_int_key)
499) stats_persistent=0;
500INSERT INTO t1 VALUES (NULL,2,'w');
501INSERT INTO t1 VALUES (7,9,'m');
502INSERT INTO t1 VALUES (9,3,'m');
503INSERT INTO t1 VALUES (7,9,'k');
504INSERT INTO t1 VALUES (4,NULL,'r');
505INSERT INTO t1 VALUES (2,9,'t');
506INSERT INTO t1 VALUES (6,3,'j');
507INSERT INTO t1 VALUES (8,8,'u');
508INSERT INTO t1 VALUES (NULL,8,'h');
509INSERT INTO t1 VALUES (5,53,'o');
510INSERT INTO t1 VALUES (NULL,0,NULL);
511INSERT INTO t1 VALUES (6,5,'k');
512INSERT INTO t1 VALUES (188,166,'e');
513INSERT INTO t1 VALUES (2,3,'n');
514INSERT INTO t1 VALUES (1,0,'t');
515INSERT INTO t1 VALUES (1,1,'c');
516INSERT INTO t1 VALUES (0,9,'m');
517INSERT INTO t1 VALUES (9,5,'y');
518INSERT INTO t1 VALUES (NULL,6,'f');
519CREATE TABLE t2 (
520c1 INTEGER NOT NULL
521) stats_persistent=0;
522EXPLAIN SELECT table1.col_int_nokey
523FROM t1 AS table1 STRAIGHT_JOIN (
524t1 AS table2 INNER JOIN t1 AS table3
525ON table3.col_varchar_key = table2.col_varchar_key)
526ON table3.col_int_nokey = table1.col_int_key
527WHERE table3.col_int_key != SOME ( SELECT c1 FROM t2 );
528id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5291	PRIMARY	table1	NULL	ALL	col_int_key	NULL	NULL	NULL	19	100.00	NULL
5301	PRIMARY	table3	NULL	ALL	col_varchar_key	NULL	NULL	NULL	19	10.00	Using where; Using join buffer (Block Nested Loop)
5311	PRIMARY	table2	NULL	ref	col_varchar_key	col_varchar_key	4	test.table3.col_varchar_key	1	100.00	Using index
5322	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
533Warnings:
534Note	1003	/* select#1 */ select `test`.`table1`.`col_int_nokey` AS `col_int_nokey` from `test`.`t1` `table1` join `test`.`t1` `table2` join `test`.`t1` `table3` where ((`test`.`table2`.`col_varchar_key` = `test`.`table3`.`col_varchar_key`) and (`test`.`table3`.`col_int_nokey` = `test`.`table1`.`col_int_key`) and <nop>(<in_optimizer>(`test`.`table3`.`col_int_key`,<exists>(/* select#2 */ select 1 from `test`.`t2` where <if>(outer_field_is_not_null, (<cache>(`test`.`table3`.`col_int_key`) <> `test`.`t2`.`c1`), true)))))
535SELECT table1.col_int_nokey
536FROM t1 AS table1 STRAIGHT_JOIN (
537t1 AS table2 INNER JOIN t1 AS table3
538ON table3.col_varchar_key = table2.col_varchar_key)
539ON table3.col_int_nokey = table1.col_int_key
540WHERE table3.col_int_key != SOME ( SELECT c1 FROM t2 );
541col_int_nokey
542DROP TABLE t1, t2;
543#
544# Bug#58243 "RQG test optimizer_subquery causes server crash
545#            when running with ICP"
546#
547CREATE TABLE t1 (
548pk INTEGER NOT NULL,
549c1 INTEGER NOT NULL,
550c2 INTEGER NOT NULL,
551PRIMARY KEY (pk)
552);
553INSERT INTO t1 VALUES (1,6,7);
554CREATE TABLE t2 (
555c1 INTEGER NOT NULL
556);
557EXPLAIN SELECT t1.c1
558FROM t1
559WHERE t1.pk < 317 AND 2 IN (SELECT COUNT(t2.c1)
560FROM t2)
561ORDER BY t1.c2;
562id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5631	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
5642	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
565Warnings:
566Note	1003	/* select#1 */ select `test`.`t1`.`c1` AS `c1` from `test`.`t1` where 0 order by `test`.`t1`.`c2`
567SELECT t1.c1
568FROM t1
569WHERE t1.pk < 317 AND 2 IN (SELECT COUNT(t2.c1)
570FROM t2)
571ORDER BY t1.c2;
572c1
573DROP TABLE t1, t2;
574CREATE TABLE t1 (
575i1 INTEGER NOT NULL,
576c1 VARCHAR(1) NOT NULL
577);
578INSERT INTO t1 VALUES (2,'w');
579CREATE TABLE t2 (
580i1 INTEGER NOT NULL,
581c1 VARCHAR(1) NOT NULL,
582c2 VARCHAR(1) NOT NULL,
583KEY (c1, i1)
584);
585INSERT INTO t2 VALUES (8,'d','d');
586INSERT INTO t2 VALUES (4,'v','v');
587CREATE TABLE t3 (
588c1 VARCHAR(1) NOT NULL
589);
590INSERT INTO t3 VALUES ('v');
591EXPLAIN SELECT i1
592FROM t1
593WHERE EXISTS (SELECT t2.c1
594FROM (t2 INNER JOIN t3 ON (t3.c1 = t2.c1))
595WHERE t2.c2 != t1.c1 AND t2.c2 = (SELECT MIN(t3.c1)
596FROM t3));
597id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5981	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
5992	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
6002	DEPENDENT SUBQUERY	t2	NULL	ref	c1	c1	3	test.t3.c1	1	50.00	Using where
6013	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
602Warnings:
603Note	1276	Field or reference 'test.t1.c1' of SELECT #2 was resolved in SELECT #1
604Note	1003	/* select#1 */ select `test`.`t1`.`i1` AS `i1` from `test`.`t1` where exists(/* select#2 */ select `test`.`t2`.`c1` from `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`c1` = `test`.`t3`.`c1`) and (`test`.`t2`.`c2` = (/* select#3 */ select min(`test`.`t3`.`c1`) from `test`.`t3`)) and ((/* select#3 */ select min(`test`.`t3`.`c1`) from `test`.`t3`) <> `test`.`t1`.`c1`)))
605SELECT i1
606FROM t1
607WHERE EXISTS (SELECT t2.c1
608FROM (t2 INNER JOIN t3 ON (t3.c1 = t2.c1))
609WHERE t2.c2 != t1.c1 AND t2.c2 = (SELECT MIN(t3.c1)
610FROM t3));
611i1
6122
613DROP TABLE t1,t2,t3;
614#
615# Bug#58015 "Assert in row_sel_field_store_in_mysql_format
616#            when running innodb_mrr_icp test"
617#
618create table t1 (a char(2) charset utf8,b double, primary key (a(1)),key (b));
619insert into t1 values ('',1);
620select 1 from t1 where b <= 1 and a <> '';
6211
622drop table t1;
623#
624# Bug#59259 "Incorrect rows returned for a correlated subquery
625#            when ICP is on"
626#
627CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
628INSERT INTO t1 VALUES (11,0);
629INSERT INTO t1 VALUES (12,5);
630INSERT INTO t1 VALUES (15,0);
631CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL) ENGINE=InnoDB;
632INSERT INTO t2 VALUES (11,1);
633INSERT INTO t2 VALUES (12,2);
634INSERT INTO t2 VALUES (15,4);
635SELECT * FROM t1
636WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE t1.i);
637pk	i
63812	5
639DROP TABLE t1, t2;
640#
641# Bug #58816 "Extra temporary duplicate rows in result set when
642#             switching ICP off"
643#
644set @save_optimizer_switch_bug58816= @@optimizer_switch;
645CREATE TABLE t1 (
646pk INT NOT NULL,
647c1 INT NOT NULL,
648PRIMARY KEY (pk)
649);
650INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1);
651EXPLAIN SELECT pk, c1 FROM t1 WHERE pk <> 3;
652id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6531	SIMPLE	t1	NULL	range	PRIMARY	PRIMARY	4	NULL	4	100.00	Using where
654Warnings:
655Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1` AS `c1` from `test`.`t1` where (`test`.`t1`.`pk` <> 3)
656SET SESSION optimizer_switch='index_condition_pushdown=off';
657SELECT pk, c1 FROM t1 WHERE pk <> 3;
658pk	c1
6591	9
6602	7
6614	3
6625	1
663DROP TABLE t1;
664set optimizer_switch= @save_optimizer_switch_bug58816;
665#
666# Bug#58837: ICP crash or valgrind error due to uninitialized
667#            value in innobase_index_cond
668#
669CREATE TABLE t1 (
670t1_int INT,
671t1_time TIME
672);
673CREATE TABLE t2 (
674t2_int int PRIMARY KEY,
675t2_int2 INT
676);
677INSERT IGNORE INTO t2 VALUES ();
678INSERT INTO t1 VALUES ();
679
680SELECT *
681FROM t1 AS t1a
682WHERE NOT EXISTS
683(SELECT *
684FROM t1 AS t1b
685WHERE t1b.t1_int NOT IN
686(SELECT t2.t2_int
687FROM t2
688WHERE t1b.t1_time LIKE t1b.t1_int
689OR t1b.t1_time <> t2.t2_int2
690AND 6=7
691)
692)
693;;
694t1_int	t1_time
695
696EXPLAIN SELECT *
697FROM t1 AS t1a
698WHERE NOT EXISTS
699(SELECT *
700FROM t1 AS t1b
701WHERE t1b.t1_int NOT IN
702(SELECT t2.t2_int
703FROM t2
704WHERE t1b.t1_time LIKE t1b.t1_int
705OR t1b.t1_time <> t2.t2_int2
706AND 6=7
707)
708)
709;;
710id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7111	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
7122	SUBQUERY	t1b	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
7133	DEPENDENT SUBQUERY	t2	NULL	unique_subquery	PRIMARY	PRIMARY	4	func	1	100.00	Using where; Full scan on NULL key
714Warnings:
715Note	1276	Field or reference 'test.t1b.t1_time' of SELECT #3 was resolved in SELECT #2
716Note	1276	Field or reference 'test.t1b.t1_int' of SELECT #3 was resolved in SELECT #2
717Note	1276	Field or reference 'test.t1b.t1_time' of SELECT #3 was resolved in SELECT #2
718Note	1003	/* select#1 */ select `test`.`t1a`.`t1_int` AS `t1_int`,`test`.`t1a`.`t1_time` AS `t1_time` from `test`.`t1` `t1a` where 0
719
720DROP TABLE t1,t2;
721#
722# Bug#59186 Wrong results of join when ICP is enabled
723#
724CREATE TABLE t1 (
725pk INTEGER NOT NULL,
726c1 VARCHAR(3) NOT NULL,
727PRIMARY KEY (pk)
728);
729INSERT INTO t1 VALUES (1,'y'),(0,'or');
730CREATE TABLE t2 (
731pk INTEGER NOT NULL,
732c1 VARCHAR(3) NOT NULL,
733c2 VARCHAR(6) NOT NULL,
734PRIMARY KEY (pk)
735);
736INSERT INTO t2 VALUES (6,'y','RPOYT'),(10,'m','JINQE');
737EXPLAIN SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
738WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
739(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
740id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7411	SIMPLE	t1	NULL	range	PRIMARY	PRIMARY	4	NULL	1	100.00	Using where
7421	SIMPLE	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
743Warnings:
744Note	1003	/* select#1 */ select `test`.`t2`.`c2` AS `c2` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`c1` = `test`.`t1`.`c1`) and (((`test`.`t2`.`pk` <= 4) and (`test`.`t1`.`pk` in (2,1))) or ((`test`.`t1`.`pk` > 1) and (`test`.`t2`.`pk` between 6 and 6))))
745SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
746WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
747(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
748c2
749DROP TABLE t1, t2;
750#
751# Bug#58838 "Wrong results with HAVING + LIMIT without GROUP BY when
752#            ICP is enabled"
753#
754CREATE TABLE t1 (
755pk INT NOT NULL,
756c1 INT,
757PRIMARY KEY (pk),
758KEY col_int_key (c1)
759);
760INSERT INTO t1 VALUES (1,37),(2,8),(3,-25),(4,NULL),(5,55);
761SELECT pk FROM t1 WHERE c1 <> 1 HAVING pk = 3 ORDER BY pk LIMIT 0;
762pk
763SELECT pk FROM t1 WHERE c1 <> 1 HAVING pk = 3 ORDER BY pk LIMIT 1;
764pk
7653
766SELECT pk FROM t1 WHERE c1 <> 1 HAVING pk = 3 ORDER BY pk LIMIT 2;
767pk
7683
769SELECT pk FROM t1 WHERE c1 <> 1 HAVING pk = 3 ORDER BY pk LIMIT 5;
770pk
7713
772DROP TABLE t1;
773#
774# Bug#59483 "Crash on INSERT/REPLACE in
775#            rec_convert_dtuple_to_rec_comp with ICP on"
776#
777CREATE TABLE t1 (
778pk INTEGER AUTO_INCREMENT PRIMARY KEY,
779i1 INTEGER,
780c1 CHAR(6),
781i2 INTEGER NOT NULL,
782KEY (i2)
783);
784INSERT INTO t1 VALUES
785(NULL, 4, 'that', 8),
786(NULL, 1, 'she', 6),
787(NULL, 6, 'tell', 2);
788SELECT * FROM t1 WHERE i2 IN (3, 6) LIMIT 2 FOR UPDATE;
789pk	i1	c1	i2
7902	1	she	6
791INSERT INTO t1 (i2) VALUES (1);
792DROP TABLE t1;
793#
794# Bug #11766678 - 59843:
795# USING UNINITIALISED VALUE IN USES_INDEX_FIELDS_ONLY
796#
797CREATE TABLE t1 (
798col999 FLOAT NOT NULL,
799COL1000 VARBINARY(179) NOT NULL,
800col1003 DATE DEFAULT NULL,
801KEY idx4267 (col1000, col1003)
802);
803INSERT IGNORE INTO t1 VALUES (),();
804Warnings:
805Warning	1364	Field 'col999' doesn't have a default value
806Warning	1364	Field 'COL1000' doesn't have a default value
807SELECT col999 FROM t1 WHERE col1000 = "3" AND col1003 <=> sysdate();
808col999
809DROP TABLE t1;
810#
811# Bug#11873324 "WRONG RESULT WITH ICP AND STRAIGHT_JOIN"
812#
813CREATE TABLE t1 (
814pk INTEGER NOT NULL,
815i1 INTEGER,
816PRIMARY KEY (pk),
817KEY col_int_key (i1)
818);
819INSERT INTO t1 VALUES (14,NULL), (18,133);
820CREATE TABLE t2 (
821pk INTEGER NOT NULL,
822i1 INTEGER,
823c1 VARCHAR(1),
824PRIMARY KEY (pk),
825KEY col_int_key (i1)
826);
827INSERT INTO t2 VALUES (1,7,'f');
828set @old_opt_switch=@@optimizer_switch;
829EXPLAIN SELECT t1.i1
830FROM t1
831WHERE t1.i1 NOT IN
832( SELECT STRAIGHT_JOIN subquery_t1.pk
833FROM t1 AS subquery_t1
834JOIN t2 AS subquery_t2
835ON subquery_t2.i1 = subquery_t1.pk
836WHERE subquery_t1.i1 > 0
837OR subquery_t2.c1 = 'a'
838);
839id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8401	PRIMARY	t1	NULL	index	NULL	col_int_key	5	NULL	2	100.00	Using where; Using index
8412	DEPENDENT SUBQUERY	subquery_t1	NULL	eq_ref	PRIMARY,col_int_key	PRIMARY	4	func	1	100.00	Using where; Full scan on NULL key
8422	DEPENDENT SUBQUERY	subquery_t2	NULL	ref	col_int_key	col_int_key	5	func	1	100.00	Using where; Full scan on NULL key
843Warnings:
844Note	1003	/* select#1 */ select `test`.`t1`.`i1` AS `i1` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`i1`,<exists>(/* select#2 */ select straight_join 1 from `test`.`t1` `subquery_t1` join `test`.`t2` `subquery_t2` where ((`test`.`subquery_t2`.`i1` = `test`.`subquery_t1`.`pk`) and ((`test`.`subquery_t1`.`i1` > 0) or (`test`.`subquery_t2`.`c1` = 'a')) and <if>(outer_field_is_not_null, (<cache>(`test`.`t1`.`i1`) = `test`.`subquery_t1`.`pk`), true))))))
845SELECT t1.i1
846FROM t1
847WHERE t1.i1 NOT IN
848( SELECT STRAIGHT_JOIN subquery_t1.pk
849FROM t1 AS subquery_t1
850JOIN t2 AS subquery_t2
851ON subquery_t2.i1 = subquery_t1.pk
852WHERE subquery_t1.i1 > 0
853OR subquery_t2.c1 = 'a'
854);
855i1
856NULL
857133
858set @@optimizer_switch=@old_opt_switch;
859DROP TABLE t1,t2;
860#
861# Bug#11876420 "MISSING ROW IN RESULT WITH SUBQUERY + IN + XOR +
862#               NULL VALUES AND ICP ENABLED"
863#
864CREATE TABLE t1 (
865i1 INTEGER,
866c1 VARCHAR(1),
867KEY col_varchar_key (c1)
868);
869INSERT INTO t1 VALUES (1,'j'), (0,'e'), (210,'f'), (8,'v'), (7,'x'),
870(5,'m'), (NULL,'c');
871CREATE TABLE t2 (
872i1 INTEGER,
873c1 VARCHAR(1),
874KEY col_varchar_key (c1)
875);
876INSERT INTO t2 VALUES (8,NULL);
877CREATE TABLE t3 (
878i1 INTEGER,
879c1 VARCHAR(1),
880KEY col_varchar_key (c1)
881) ENGINE=InnoDB;
882INSERT INTO t3 VALUES (NULL,'w'), (1,NULL), (2,'d');
883set @old_opt_switch=@@optimizer_switch;
884EXPLAIN SELECT i1
885FROM t3
886WHERE c1 IN
887( SELECT t1.c1
888FROM t2 JOIN t1
889ON t2.i1 >= t1.i1
890WHERE t1.c1 > t2.c1
891)
892XOR i1;
893id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8941	PRIMARY	t3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
8952	DEPENDENT SUBQUERY	t2	NULL	ALL	col_varchar_key	NULL	NULL	NULL	1	100.00	NULL
8962	DEPENDENT SUBQUERY	t1	NULL	ref_or_null	col_varchar_key	col_varchar_key	4	func	2	33.33	Using where; Full scan on NULL key
897Warnings:
898Note	1003	/* select#1 */ select `test`.`t3`.`i1` AS `i1` from `test`.`t3` where (<in_optimizer>(`test`.`t3`.`c1`,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t1` where ((`test`.`t1`.`c1` > `test`.`t2`.`c1`) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t3`.`c1`) = `test`.`t1`.`c1`) or isnull(`test`.`t1`.`c1`)), true) and (`test`.`t2`.`i1` >= `test`.`t1`.`i1`)) having <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t1`.`c1`), true))) xor `test`.`t3`.`i1`)
899SELECT i1
900FROM t3
901WHERE c1 IN
902( SELECT t1.c1
903FROM t2 JOIN t1
904ON t2.i1 >= t1.i1
905WHERE t1.c1 > t2.c1
906)
907XOR i1;
908i1
9091
9102
911set @@optimizer_switch=@old_opt_switch;
912DROP TABLE t1, t2, t3;
913#
914# Bug#12355958 "FAILING ASSERTION: TRX->LOCK.N_ACTIVE_THRS == 1"
915#
916CREATE TABLE t1 (
917pk INTEGER PRIMARY KEY,
918a INTEGER NOT NULL,
919b CHAR(1),
920KEY(b)
921);
922INSERT INTO t1 VALUES (23,5,'d');
923EXPLAIN SELECT a1.pk
924FROM t1 AS a1 JOIN (SELECT * FROM t1 LIMIT 1) AS a2 ON a2.b = a1.b
925WHERE a1.a = (SELECT pk FROM t1 LIMIT 1)
926AND (a1.a != a2.a OR a1.b IS NULL);
927id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9281	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
9291	PRIMARY	a1	NULL	ref	b	b	2	const	1	100.00	Using where
9303	SUBQUERY	t1	NULL	index	NULL	b	2	NULL	1	100.00	Using index
9312	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
932Warnings:
933Note	1003	/* select#1 */ select `test`.`a1`.`pk` AS `pk` from `test`.`t1` `a1` where ((`test`.`a1`.`b` = 'd') and (`test`.`a1`.`a` = (/* select#3 */ select `test`.`t1`.`pk` from `test`.`t1` limit 1)) and (((/* select#3 */ select `test`.`t1`.`pk` from `test`.`t1` limit 1) <> '5') or isnull(`test`.`a1`.`b`)))
934SELECT a1.pk
935FROM t1 AS a1 JOIN (SELECT * FROM t1 LIMIT 1) AS a2 ON a2.b = a1.b
936WHERE a1.a = (SELECT pk FROM t1 LIMIT 1)
937AND (a1.a != a2.a OR a1.b IS NULL);
938pk
939CREATE VIEW v1 AS SELECT * FROM t1;
940EXPLAIN SELECT a1.pk
941FROM v1 AS a1 JOIN (SELECT * FROM v1 LIMIT 1) AS a2 ON a2.b = a1.b
942WHERE a1.a = (SELECT pk FROM v1 LIMIT 1)
943AND (a1.a != a2.a OR a1.b IS NULL);
944id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9451	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
9461	PRIMARY	t1	NULL	ref	b	b	2	const	1	100.00	Using where
9473	SUBQUERY	t1	NULL	index	NULL	b	2	NULL	1	100.00	Using index
9482	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
949Warnings:
950Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where ((`test`.`t1`.`b` = 'd') and (`test`.`t1`.`a` = (/* select#3 */ select `test`.`t1`.`pk` from `test`.`t1` limit 1)) and ((`test`.`t1`.`a` <> '5') or isnull(`test`.`t1`.`b`)))
951SELECT a1.pk
952FROM v1 AS a1 JOIN (SELECT * FROM v1 LIMIT 1) AS a2 ON a2.b = a1.b
953WHERE a1.a = (SELECT pk FROM v1 LIMIT 1)
954AND (a1.a != a2.a OR a1.b IS NULL);
955pk
956DROP VIEW v1;
957DROP TABLE t1;
958#
959# BUG#12601961 "SEGFAULT IN HANDLER::COMPARE_KEY2"
960# BUG#12724899 "SELECT STRAIGHT_JOIN QUERY GIVES 2 DATES VERSUS
961#               2 WARNINGS WITH ICP ON"
962#
963CREATE TABLE t1 (
964pk INTEGER NOT NULL,
965i1 INTEGER NOT NULL,
966c1 VARCHAR(1) NOT NULL,
967PRIMARY KEY (pk)
968);
969INSERT INTO t1 VALUES (1,3,'j'), (20,8,'e');
970EXPLAIN SELECT alias2.i1
971FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2
972ON alias2.pk AND alias2.pk <= alias1.c1
973WHERE alias2.pk = 1;
974id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9751	SIMPLE	alias1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
9761	SIMPLE	alias2	NULL	const	PRIMARY	PRIMARY	4	const	1	100.00	Using where
977Warnings:
978Note	1003	/* select#1 */ select `test`.`alias2`.`i1` AS `i1` from `test`.`t1` `alias1` straight_join `test`.`t1` `alias2` where ((`test`.`alias2`.`pk` = 1) and `test`.`alias2`.`pk` and (`test`.`alias2`.`pk` <= `test`.`alias1`.`c1`))
979SELECT alias2.i1
980FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2
981ON alias2.pk AND alias2.pk <= alias1.c1
982WHERE alias2.pk = 1;
983i1
984Warnings:
985Warning	1292	Truncated incorrect DOUBLE value: 'j'
986Warning	1292	Truncated incorrect DOUBLE value: 'e'
987DROP TABLE t1;
988#
989# BUG#12822678 - 2 MORE ROWS WHEN ICP=ON W/ STRAIGHT_JOIN
990#
991CREATE TABLE t1 (
992i1 INTEGER NOT NULL,
993d1 DOUBLE,
994KEY k1 (d1)
995);
996INSERT INTO t1 VALUES (10,1), (17,NULL), (22,NULL);
997CREATE TABLE t2 (
998pk INTEGER NOT NULL,
999i1 INTEGER NOT NULL,
1000PRIMARY KEY (pk)
1001);
1002INSERT INTO t2 VALUES (4,1);
1003EXPLAIN SELECT t1.d1, t2.pk, t2.i1
1004FROM t1 STRAIGHT_JOIN t2 ON t2.i1
1005WHERE t2.pk <> t1.d1 AND t2.pk = 4;
1006id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10071	SIMPLE	t1	NULL	index	NULL	k1	9	NULL	3	100.00	Using index
10081	SIMPLE	t2	NULL	const	PRIMARY	PRIMARY	4	const	1	100.00	Using where
1009Warnings:
1010Note	1003	/* select#1 */ select `test`.`t1`.`d1` AS `d1`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`i1` AS `i1` from `test`.`t1` straight_join `test`.`t2` where ((`test`.`t2`.`pk` = 4) and (`test`.`t2`.`pk` <> `test`.`t1`.`d1`) and `test`.`t2`.`i1`)
1011SELECT t1.d1, t2.pk, t2.i1
1012FROM t1 STRAIGHT_JOIN t2 ON t2.i1
1013WHERE t2.pk <> t1.d1 AND t2.pk = 4;
1014d1	pk	i1
10151	4	1
1016DROP TABLE t1, t2;
1017#
1018# BUG#12838420 "DUPLICATE VALUES FOR GROUP-BY COLUMN WHEN JOIN
1019# BUFFERING IS OFF"
1020#
1021CREATE TABLE t1 (
1022col_int_key INT,
1023pk INT,
1024PRIMARY KEY (pk),
1025KEY (col_int_key)
1026);
1027INSERT INTO t1 VALUES (2,3),(3,2),(3,5),(4,6);
1028CREATE TABLE t2 (
1029col_int_key INT,
1030pk INT,
1031PRIMARY KEY (pk),
1032KEY (col_int_key)
1033);
1034INSERT INTO t2 VALUES (0,9),(3,10),(4,6),(6,1),(100,3),(200,5);
1035set @old_opt_switch=@@optimizer_switch;
1036SET optimizer_switch="block_nested_loop=off";
1037EXPLAIN SELECT t2.col_int_key AS field1
1038FROM t2 USE INDEX(col_int_key) STRAIGHT_JOIN t1 ON t2.col_int_key
1039WHERE t2.pk < 7 AND t2.col_int_key <> 7
1040GROUP BY field1;
1041id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10421	SIMPLE	t2	NULL	index	col_int_key	col_int_key	5	NULL	6	33.33	Using where; Using index
10431	SIMPLE	t1	NULL	index	NULL	col_int_key	5	NULL	4	100.00	Using index
1044Warnings:
1045Note	1003	/* select#1 */ select `test`.`t2`.`col_int_key` AS `field1` from `test`.`t2` USE INDEX (`col_int_key`) straight_join `test`.`t1` where ((`test`.`t2`.`pk` < 7) and (`test`.`t2`.`col_int_key` <> 7) and `test`.`t2`.`col_int_key`) group by `field1`
1046SELECT t2.col_int_key AS field1
1047FROM t2 USE INDEX(col_int_key) STRAIGHT_JOIN t1 ON t2.col_int_key
1048WHERE t2.pk < 7 AND t2.col_int_key <> 7
1049GROUP BY field1;
1050field1
10514
10526
1053100
1054200
1055SET @@optimizer_switch=@old_opt_switch;
1056DROP TABLE t1,t2;
1057#
1058# Bug#12976163 "CRASH IN INDEX CONDITION PUSHDOWN CODE AGAINST
1059#               A MYISAM TABLE"
1060#
1061CREATE TABLE t1 (
1062i1 INTEGER NOT NULL,
1063i2 INTEGER NOT NULL
1064);
1065INSERT INTO t1 VALUES (14,1), (15,2), (16,3);
1066CREATE TABLE t2 (
1067i1 INTEGER NOT NULL,
1068i2 INTEGER NOT NULL,
1069c1 TINYTEXT
1070);
1071INSERT INTO t2
1072SELECT i1, 10 * i2, "MySQL" FROM t1;
1073CREATE PROCEDURE proc1(id INTEGER)
1074BEGIN
1075SELECT i2
1076FROM (
1077(SELECT i1, i2, NULL AS a1 FROM t1)
1078UNION
1079(SELECT i1, i2, c1 AS a1 FROM t2)
1080) u1
1081WHERE i1 = id;
1082END$$
1083CALL proc1(15);
1084i2
10852
108620
1087DROP PROCEDURE proc1;
1088DROP TABLE t1, t2;
1089#
1090# Bug#13655397 "CRASH IN SYNC_THREAD_LEVELS_NONEMPTY_TRX"
1091#
1092CREATE TABLE t1 (
1093i1 INTEGER NOT NULL,
1094i2 INTEGER NOT NULL,
1095KEY (i1)
1096);
1097INSERT INTO t1 VALUES (4,4), (5,5);
1098CREATE TABLE t2 (
1099pk INTEGER NOT NULL,
1100PRIMARY KEY (pk)
1101);
1102INSERT INTO t2 VALUES (1);
1103CREATE FUNCTION f1() RETURNS INTEGER
1104RETURN (SELECT MOD(COUNT(DISTINCT pk), 10) FROM t2);
1105EXPLAIN SELECT i1, i2 FROM t1 WHERE f1() = 1 AND i1 = 5;
1106id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11071	SIMPLE	t1	NULL	ref	i1	i1	4	const	1	100.00	Using where
1108Warnings:
1109Note	1003	/* select#1 */ select `test`.`t1`.`i1` AS `i1`,`test`.`t1`.`i2` AS `i2` from `test`.`t1` where ((`test`.`t1`.`i1` = 5) and (`f1`() = 1))
1110SELECT i1, i2 FROM t1 WHERE f1() = 1 AND i1 = 5;
1111i1	i2
11125	5
1113DROP FUNCTION f1;
1114DROP TABLE t1, t2;
1115set default_storage_engine= @save_storage_engine;
1116set optimizer_switch=default;
1117