1set optimizer_switch='materialization=on';
2set @old_opt_switch=@@optimizer_switch;
3set optimizer_switch='subquery_materialization_cost_based=off';
4drop table if exists t0, t1, t2, t10, t11, t12;
5create table t1 (a int not null, b int, primary key (a));
6create table t2 (a int not null, primary key (a));
7create table t3 (a int not null, b int, primary key (a));
8insert into t1 values (1,10), (2,20), (3,30),  (4,40);
9insert into t2 values (2), (3), (4), (5);
10insert into t3 values (10,3), (20,4), (30,5);
11select * from t2 where t2.a in (select a from t1);
12a
132
143
154
16explain extended select * from t2 where t2.a in (select a from t1);
17id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
181	PRIMARY	t2	NULL	index	NULL	PRIMARY	4	NULL	4	100.00	Using where; Using index
192	SUBQUERY	t1	NULL	index	PRIMARY	PRIMARY	4	NULL	4	100.00	Using index
20Warnings:
21Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
22Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
23select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
24a
252
264
27explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
28id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
291	PRIMARY	t2	NULL	index	NULL	PRIMARY	4	NULL	4	100.00	Using where; Using index
302	SUBQUERY	t1	NULL	ALL	PRIMARY	NULL	NULL	NULL	4	75.00	Using where
31Warnings:
32Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
33Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where (`test`.`t1`.`b` <> 30) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
34select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
35a
362
373
38explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
39id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
401	PRIMARY	t2	NULL	index	NULL	PRIMARY	4	NULL	4	100.00	Using where; Using index
412	SUBQUERY	t3	NULL	index	PRIMARY	PRIMARY	4	NULL	3	100.00	Using index
422	SUBQUERY	t1	NULL	ALL	PRIMARY	NULL	NULL	NULL	4	25.00	Using where; Using join buffer (Block Nested Loop)
43Warnings:
44Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
45Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where (`test`.`t1`.`b` = `test`.`t3`.`a`) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
46drop table t1, t2, t3;
47create table t1 (a int, b int, index a (a,b));
48create table t2 (a int, index a (a));
49create table t3 (a int, b int, index a (a));
50insert into t1 values (1,10), (2,20), (3,30), (4,40);
51create table t0(a int);
52insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
53insert into t1
54select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
55insert into t2 values (2), (3), (4), (5);
56insert into t3 values (10,3), (20,4), (30,5);
57select * from t2 where t2.a in (select a from t1);
58a
592
603
614
62explain extended select * from t2 where t2.a in (select a from t1);
63id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
641	PRIMARY	t2	NULL	index	NULL	a	5	NULL	4	100.00	Using where; Using index
652	SUBQUERY	t1	NULL	index	a	a	10	NULL	10004	100.00	Using index
66Warnings:
67Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
68Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
69select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
70a
712
724
73explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
74id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
751	PRIMARY	t2	NULL	index	NULL	a	5	NULL	4	100.00	Using where; Using index
762	SUBQUERY	t1	NULL	index	a	a	10	NULL	10004	90.00	Using where; Using index
77Warnings:
78Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
79Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where (`test`.`t1`.`b` <> 30) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
80select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
81a
822
833
84explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
85id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
861	PRIMARY	t2	NULL	index	NULL	a	5	NULL	4	100.00	Using where; Using index
872	SUBQUERY	t3	NULL	index	a	a	5	NULL	3	100.00	Using index
882	SUBQUERY	t1	NULL	index	a	a	10	NULL	10004	10.00	Using where; Using index; Using join buffer (Block Nested Loop)
89Warnings:
90Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
91Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where (`test`.`t1`.`b` = `test`.`t3`.`a`) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
92insert into t1 values (3,31);
93select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
94a
952
963
974
98select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31);
99a
1002
1014
102explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
103id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1041	PRIMARY	t2	NULL	index	NULL	a	5	NULL	4	100.00	Using where; Using index
1052	SUBQUERY	t1	NULL	index	a	a	10	NULL	10005	90.00	Using where; Using index
106Warnings:
107Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
108Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where (`test`.`t1`.`b` <> 30) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
109drop table t0, t1, t2, t3;
110create table t0 (a int);
111insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
112create table t1(a int, b int);
113insert into t1 values (0,0),(1,1),(2,2);
114create table t2 as select * from t1;
115create table t11(a int, b int);
116create table t10 (pk int, a int, primary key(pk));
117insert into t10 select a,a from t0;
118create table t12 like t10;
119insert into t12 select * from t10;
120Flattened because of dependency, t10=func(t1)
121explain select * from t1 where a in (select pk from t10);
122id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1231	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
1242	SUBQUERY	t10	NULL	index	PRIMARY	PRIMARY	4	NULL	10	100.00	Using index
125Warnings:
126Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`pk`)))))
127select * from t1 where a in (select pk from t10);
128a	b
1290	0
1301	1
1312	2
132A confluent case of dependency
133explain select * from t1 where a in (select a from t10 where pk=12);
134id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1351	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
1362	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
137Warnings:
138Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select NULL from `test`.`t10` where multiple equal(12, NULL) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
139select * from t1 where a in (select a from t10 where pk=12);
140a	b
141explain select * from t1 where a in (select a from t10 where pk=9);
142id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1431	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
1442	SUBQUERY	t10	NULL	const	PRIMARY	PRIMARY	4	const	1	100.00	NULL
145Warnings:
146Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select '9' from `test`.`t10` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
147select * from t1 where a in (select a from t10 where pk=9);
148a	b
149An empty table inside
150explain select * from t1 where a in (select a from t11);
151id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1521	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
1532	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
154Warnings:
155Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select NULL from `test`.`t11` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
156select * from t1 where a in (select a from t11);
157a	b
158explain select * from t1 where a in (select pk from t10) and b in (select pk from t10);
159id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1601	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
1613	SUBQUERY	t10	NULL	index	PRIMARY	PRIMARY	4	NULL	10	100.00	Using index
1622	SUBQUERY	t10	NULL	index	PRIMARY	PRIMARY	4	NULL	10	100.00	Using index
163Warnings:
164Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`pk`))))) and <in_optimizer>(`test`.`t1`.`b`,`test`.`t1`.`b` in ( <materialize> (/* select#3 */ select `test`.`t10`.`pk` from `test`.`t10` where 1 ), <primary_index_lookup>(`test`.`t1`.`b` in <temporary table> on <auto_key> where ((`test`.`t1`.`b` = `materialized-subquery`.`pk`))))))
165select * from t1 where a in (select pk from t10) and b in (select pk from t10);
166a	b
1670	0
1681	1
1692	2
170flattening a nested subquery
171explain select * from t1 where a in (select pk from t10 where t10.a in (select pk from t12));
172id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1731	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
1742	SUBQUERY	t10	NULL	ALL	PRIMARY	NULL	NULL	NULL	10	100.00	Using where
1753	SUBQUERY	t12	NULL	index	PRIMARY	PRIMARY	4	NULL	10	100.00	Using index
176Warnings:
177Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` where <in_optimizer>(`test`.`t10`.`a`,`test`.`t10`.`a` in ( <materialize> (/* select#3 */ select `test`.`t12`.`pk` from `test`.`t12` where 1 ), <primary_index_lookup>(`test`.`t10`.`a` in <temporary table> on <auto_key> where ((`test`.`t10`.`a` = `materialized-subquery`.`pk`))))) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`pk`)))))
178select * from t1 where a in (select pk from t10 where t10.a in (select pk from t12));
179a	b
1800	0
1811	1
1822	2
183flattening subquery w/ several tables
184explain extended select * from t1 where a in (select t10.pk from t10, t12 where t12.pk=t10.a);
185id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1861	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
1872	SUBQUERY	t10	NULL	ALL	PRIMARY	NULL	NULL	NULL	10	100.00	Using where
1882	SUBQUERY	t12	NULL	eq_ref	PRIMARY	PRIMARY	4	test.t10.a	1	100.00	Using index
189Warnings:
190Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
191Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` join `test`.`t12` where (`test`.`t12`.`pk` = `test`.`t10`.`a`) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`pk`)))))
192subqueries within outer joins go into ON expr.
193explAin extended
194select * from t1 left join (t2 A, t2 B) on ( A.A= t1.A And B.A in (select pk from t10));
195id	select_type	tABle	pArtitions	type	possiBle_keys	key	key_len	ref	rows	filtered	ExtrA
1961	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
1971	PRIMARY	A	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join Buffer (Block Nested Loop)
1981	PRIMARY	B	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join Buffer (Block Nested Loop)
1992	SUBQUERY	t10	NULL	index	PRIMARY	PRIMARY	4	NULL	10	100.00	Using index
200Warnings:
201WArning	1681	'EXTENDED' is deprecAted And will Be removed in A future releAse.
202Note	1003	/* select#1 */ select `test`.`t1`.`A` AS `A`,`test`.`t1`.`B` AS `B`,`test`.`A`.`A` AS `A`,`test`.`A`.`B` AS `B`,`test`.`B`.`A` AS `A`,`test`.`B`.`B` AS `B` from `test`.`t1` left join (`test`.`t2` `A` join `test`.`t2` `B`) on(((`test`.`A`.`A` = `test`.`t1`.`A`) And <in_optimizer>(`test`.`B`.`A`,`test`.`B`.`A` in ( <mAteriAlize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` where 1 ), <primAry_index_lookup>(`test`.`B`.`A` in <temporAry tABle> on <Auto_key> where ((`test`.`B`.`A` = `mAteriAlized-suBquery`.`pk`))))))) where 1
203t2 should be wrapped into OJ-nest, so we have "t1 LJ (t2 J t10)"
204explAin extended
205select * from t1 left join t2 on (t2.A= t1.A And t2.A in (select pk from t10));
206id	select_type	tABle	pArtitions	type	possiBle_keys	key	key_len	ref	rows	filtered	ExtrA
2071	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
2081	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join Buffer (Block Nested Loop)
2092	SUBQUERY	t10	NULL	index	PRIMARY	PRIMARY	4	NULL	10	100.00	Using index
210Warnings:
211WArning	1681	'EXTENDED' is deprecAted And will Be removed in A future releAse.
212Note	1003	/* select#1 */ select `test`.`t1`.`A` AS `A`,`test`.`t1`.`B` AS `B`,`test`.`t2`.`A` AS `A`,`test`.`t2`.`B` AS `B` from `test`.`t1` left join `test`.`t2` on(((`test`.`t2`.`A` = `test`.`t1`.`A`) And <in_optimizer>(`test`.`t1`.`A`,`test`.`t1`.`A` in ( <mAteriAlize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` where 1 ), <primAry_index_lookup>(`test`.`t1`.`A` in <temporAry tABle> on <Auto_key> where ((`test`.`t1`.`A` = `mAteriAlized-suBquery`.`pk`))))))) where 1
213we shouldn't flatten if we're going to get a join of > MAX_TABLES.
214explain select * from
215t1 s00, t1 s01,  t1 s02, t1 s03, t1 s04,t1 s05,t1 s06,t1 s07,t1 s08,t1 s09,
216t1 s10, t1 s11,  t1 s12, t1 s13, t1 s14,t1 s15,t1 s16,t1 s17,t1 s18,t1 s19,
217t1 s20, t1 s21,  t1 s22, t1 s23, t1 s24,t1 s25,t1 s26,t1 s27,t1 s28,t1 s29,
218t1 s30, t1 s31,  t1 s32, t1 s33, t1 s34,t1 s35,t1 s36,t1 s37,t1 s38,t1 s39,
219t1 s40, t1 s41,  t1 s42, t1 s43, t1 s44,t1 s45,t1 s46,t1 s47,t1 s48,t1 s49
220where
221s00.a in (
222select m00.a from
223t1 m00, t1 m01,  t1 m02, t1 m03, t1 m04,t1 m05,t1 m06,t1 m07,t1 m08,t1 m09,
224t1 m10, t1 m11,  t1 m12, t1 m13, t1 m14,t1 m15,t1 m16,t1 m17,t1 m18,t1 m19
225);
226id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
2271	PRIMARY	s00	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
2281	PRIMARY	s01	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2291	PRIMARY	s02	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2301	PRIMARY	s03	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2311	PRIMARY	s04	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2321	PRIMARY	s05	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2331	PRIMARY	s06	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2341	PRIMARY	s07	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2351	PRIMARY	s08	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2361	PRIMARY	s09	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2371	PRIMARY	s10	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2381	PRIMARY	s11	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2391	PRIMARY	s12	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2401	PRIMARY	s13	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2411	PRIMARY	s14	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2421	PRIMARY	s15	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2431	PRIMARY	s16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2441	PRIMARY	s17	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2451	PRIMARY	s18	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2461	PRIMARY	s19	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2471	PRIMARY	s20	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2481	PRIMARY	s21	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2491	PRIMARY	s22	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2501	PRIMARY	s23	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2511	PRIMARY	s24	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2521	PRIMARY	s25	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2531	PRIMARY	s26	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2541	PRIMARY	s27	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2551	PRIMARY	s28	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2561	PRIMARY	s29	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2571	PRIMARY	s30	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2581	PRIMARY	s31	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2591	PRIMARY	s32	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2601	PRIMARY	s33	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2611	PRIMARY	s34	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2621	PRIMARY	s35	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2631	PRIMARY	s36	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2641	PRIMARY	s37	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2651	PRIMARY	s38	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2661	PRIMARY	s39	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2671	PRIMARY	s40	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2681	PRIMARY	s41	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2691	PRIMARY	s42	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2701	PRIMARY	s43	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2711	PRIMARY	s44	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2721	PRIMARY	s45	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2731	PRIMARY	s46	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2741	PRIMARY	s47	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2751	PRIMARY	s48	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2761	PRIMARY	s49	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2772	SUBQUERY	m00	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
2782	SUBQUERY	m01	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2792	SUBQUERY	m02	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2802	SUBQUERY	m03	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2812	SUBQUERY	m04	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2822	SUBQUERY	m05	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2832	SUBQUERY	m06	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2842	SUBQUERY	m07	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2852	SUBQUERY	m08	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2862	SUBQUERY	m09	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2872	SUBQUERY	m10	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2882	SUBQUERY	m11	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2892	SUBQUERY	m12	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2902	SUBQUERY	m13	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2912	SUBQUERY	m14	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2922	SUBQUERY	m15	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2932	SUBQUERY	m16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2942	SUBQUERY	m17	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2952	SUBQUERY	m18	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
2962	SUBQUERY	m19	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (Block Nested Loop)
297Warnings:
298Note	1003	/* select#1 */ select `test`.`s00`.`a` AS `a`,`test`.`s00`.`b` AS `b`,`test`.`s01`.`a` AS `a`,`test`.`s01`.`b` AS `b`,`test`.`s02`.`a` AS `a`,`test`.`s02`.`b` AS `b`,`test`.`s03`.`a` AS `a`,`test`.`s03`.`b` AS `b`,`test`.`s04`.`a` AS `a`,`test`.`s04`.`b` AS `b`,`test`.`s05`.`a` AS `a`,`test`.`s05`.`b` AS `b`,`test`.`s06`.`a` AS `a`,`test`.`s06`.`b` AS `b`,`test`.`s07`.`a` AS `a`,`test`.`s07`.`b` AS `b`,`test`.`s08`.`a` AS `a`,`test`.`s08`.`b` AS `b`,`test`.`s09`.`a` AS `a`,`test`.`s09`.`b` AS `b`,`test`.`s10`.`a` AS `a`,`test`.`s10`.`b` AS `b`,`test`.`s11`.`a` AS `a`,`test`.`s11`.`b` AS `b`,`test`.`s12`.`a` AS `a`,`test`.`s12`.`b` AS `b`,`test`.`s13`.`a` AS `a`,`test`.`s13`.`b` AS `b`,`test`.`s14`.`a` AS `a`,`test`.`s14`.`b` AS `b`,`test`.`s15`.`a` AS `a`,`test`.`s15`.`b` AS `b`,`test`.`s16`.`a` AS `a`,`test`.`s16`.`b` AS `b`,`test`.`s17`.`a` AS `a`,`test`.`s17`.`b` AS `b`,`test`.`s18`.`a` AS `a`,`test`.`s18`.`b` AS `b`,`test`.`s19`.`a` AS `a`,`test`.`s19`.`b` AS `b`,`test`.`s20`.`a` AS `a`,`test`.`s20`.`b` AS `b`,`test`.`s21`.`a` AS `a`,`test`.`s21`.`b` AS `b`,`test`.`s22`.`a` AS `a`,`test`.`s22`.`b` AS `b`,`test`.`s23`.`a` AS `a`,`test`.`s23`.`b` AS `b`,`test`.`s24`.`a` AS `a`,`test`.`s24`.`b` AS `b`,`test`.`s25`.`a` AS `a`,`test`.`s25`.`b` AS `b`,`test`.`s26`.`a` AS `a`,`test`.`s26`.`b` AS `b`,`test`.`s27`.`a` AS `a`,`test`.`s27`.`b` AS `b`,`test`.`s28`.`a` AS `a`,`test`.`s28`.`b` AS `b`,`test`.`s29`.`a` AS `a`,`test`.`s29`.`b` AS `b`,`test`.`s30`.`a` AS `a`,`test`.`s30`.`b` AS `b`,`test`.`s31`.`a` AS `a`,`test`.`s31`.`b` AS `b`,`test`.`s32`.`a` AS `a`,`test`.`s32`.`b` AS `b`,`test`.`s33`.`a` AS `a`,`test`.`s33`.`b` AS `b`,`test`.`s34`.`a` AS `a`,`test`.`s34`.`b` AS `b`,`test`.`s35`.`a` AS `a`,`test`.`s35`.`b` AS `b`,`test`.`s36`.`a` AS `a`,`test`.`s36`.`b` AS `b`,`test`.`s37`.`a` AS `a`,`test`.`s37`.`b` AS `b`,`test`.`s38`.`a` AS `a`,`test`.`s38`.`b` AS `b`,`test`.`s39`.`a` AS `a`,`test`.`s39`.`b` AS `b`,`test`.`s40`.`a` AS `a`,`test`.`s40`.`b` AS `b`,`test`.`s41`.`a` AS `a`,`test`.`s41`.`b` AS `b`,`test`.`s42`.`a` AS `a`,`test`.`s42`.`b` AS `b`,`test`.`s43`.`a` AS `a`,`test`.`s43`.`b` AS `b`,`test`.`s44`.`a` AS `a`,`test`.`s44`.`b` AS `b`,`test`.`s45`.`a` AS `a`,`test`.`s45`.`b` AS `b`,`test`.`s46`.`a` AS `a`,`test`.`s46`.`b` AS `b`,`test`.`s47`.`a` AS `a`,`test`.`s47`.`b` AS `b`,`test`.`s48`.`a` AS `a`,`test`.`s48`.`b` AS `b`,`test`.`s49`.`a` AS `a`,`test`.`s49`.`b` AS `b` from `test`.`t1` `s00` join `test`.`t1` `s01` join `test`.`t1` `s02` join `test`.`t1` `s03` join `test`.`t1` `s04` join `test`.`t1` `s05` join `test`.`t1` `s06` join `test`.`t1` `s07` join `test`.`t1` `s08` join `test`.`t1` `s09` join `test`.`t1` `s10` join `test`.`t1` `s11` join `test`.`t1` `s12` join `test`.`t1` `s13` join `test`.`t1` `s14` join `test`.`t1` `s15` join `test`.`t1` `s16` join `test`.`t1` `s17` join `test`.`t1` `s18` join `test`.`t1` `s19` join `test`.`t1` `s20` join `test`.`t1` `s21` join `test`.`t1` `s22` join `test`.`t1` `s23` join `test`.`t1` `s24` join `test`.`t1` `s25` join `test`.`t1` `s26` join `test`.`t1` `s27` join `test`.`t1` `s28` join `test`.`t1` `s29` join `test`.`t1` `s30` join `test`.`t1` `s31` join `test`.`t1` `s32` join `test`.`t1` `s33` join `test`.`t1` `s34` join `test`.`t1` `s35` join `test`.`t1` `s36` join `test`.`t1` `s37` join `test`.`t1` `s38` join `test`.`t1` `s39` join `test`.`t1` `s40` join `test`.`t1` `s41` join `test`.`t1` `s42` join `test`.`t1` `s43` join `test`.`t1` `s44` join `test`.`t1` `s45` join `test`.`t1` `s46` join `test`.`t1` `s47` join `test`.`t1` `s48` join `test`.`t1` `s49` where <in_optimizer>(`test`.`s00`.`a`,`test`.`s00`.`a` in ( <materialize> (/* select#2 */ select `test`.`m00`.`a` from `test`.`t1` `m00` join `test`.`t1` `m01` join `test`.`t1` `m02` join `test`.`t1` `m03` join `test`.`t1` `m04` join `test`.`t1` `m05` join `test`.`t1` `m06` join `test`.`t1` `m07` join `test`.`t1` `m08` join `test`.`t1` `m09` join `test`.`t1` `m10` join `test`.`t1` `m11` join `test`.`t1` `m12` join `test`.`t1` `m13` join `test`.`t1` `m14` join `test`.`t1` `m15` join `test`.`t1` `m16` join `test`.`t1` `m17` join `test`.`t1` `m18` join `test`.`t1` `m19` where 1 ), <primary_index_lookup>(`test`.`s00`.`a` in <temporary table> on <auto_key> where ((`test`.`s00`.`a` = `materialized-subquery`.`a`)))))
299select * from
300t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
301where t1.a < 5;
302a	b	a	b
3030	0	0	0
3041	1	1	1
3052	2	2	2
306prepare s1 from
307' select * from
308    t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
309  where t1.a < 5';
310execute s1;
311a	b	a	b
3120	0	0	0
3131	1	1	1
3142	2	2	2
315execute s1;
316a	b	a	b
3170	0	0	0
3181	1	1	1
3192	2	2	2
320insert into t1 select (A.a + 10 * B.a),1 from t0 A, t0 B;
321explain extended select * from t1 where a in (select pk from t10 where pk<3);
322id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3231	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	103	100.00	Using where
3242	SUBQUERY	t10	NULL	range	PRIMARY	PRIMARY	4	NULL	4	100.00	Using where; Using index
325Warnings:
326Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
327Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t10`.`pk` from `test`.`t10` where (`test`.`t10`.`pk` < 3) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`pk`)))))
328drop table t0, t1, t2;
329drop table t10, t11, t12;
330#
331# Check that subqueries with outer joins or straight_join work for
332# different permutations of const and non-const tables.  (Ref. Bug#46692)
333#
334CREATE TABLE t1 (i INTEGER);
335CREATE TABLE t2 (i INTEGER);
336CREATE TABLE t3 (i INTEGER);
337SELECT (SELECT COUNT(*) from t1) AS c1,
338(SELECT COUNT(*) from t2) AS c2,
339(SELECT COUNT(*) from t3) AS c3;
340c1	c2	c3
3410	0	0
342EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
343(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
344id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3451	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
3462	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
347Warnings:
348Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` join `test`.`t3` where multiple equal(NULL, NULL) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
349SELECT * FROM t1 WHERE (t1.i) IN
350(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
351i
352PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
353(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
354EXECUTE stmt;
355i
356EXECUTE stmt;
357i
358DEALLOCATE PREPARE stmt;
359EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
360(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
361id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3621	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
3632	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
364Warnings:
365Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` join `test`.`t3` where multiple equal(NULL, NULL) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
366SELECT * FROM t1 WHERE (t1.i) IN
367(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
368i
369PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
370(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
371EXECUTE stmt;
372i
373EXECUTE stmt;
374i
375DEALLOCATE PREPARE stmt;
376EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
377(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
378id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3791	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
3802	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
381Warnings:
382Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
383SELECT * FROM t1 WHERE (t1.i) IN
384(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
385i
386EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
387(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
388id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3891	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
3902	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
391Warnings:
392Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
393SELECT * FROM t1 WHERE (t1.i) IN
394(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
395i
396EXPLAIN SELECT * FROM t1 WHERE (11) IN
397(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
398id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3991	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
4002	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
401Warnings:
402Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
403SELECT * FROM t1 WHERE (11) IN
404(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
405i
406EXPLAIN SELECT * FROM t1 WHERE (11) IN
407(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
408id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4091	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
4102	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
411Warnings:
412Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
413Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
414SELECT * FROM t1 WHERE (11) IN
415(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
416i
417EXPLAIN SELECT * FROM t1 WHERE (11) IN
418(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
419id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4201	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
4212	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
422Warnings:
423Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
424SELECT * FROM t1 WHERE (11) IN
425(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
426i
427EXPLAIN SELECT * FROM t1 WHERE (11) IN
428(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
429id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4301	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
4312	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
432Warnings:
433Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
434SELECT * FROM t1 WHERE (11) IN
435(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
436i
437INSERT INTO t3 VALUES (2);
438SELECT (SELECT COUNT(*) from t1) AS c1,
439(SELECT COUNT(*) from t2) AS c2,
440(SELECT COUNT(*) from t3) AS c3;
441c1	c2	c3
4420	0	1
443EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
444(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
445id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4461	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
4472	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
448Warnings:
449Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where multiple equal(NULL) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
450SELECT * FROM t1 WHERE (t1.i) IN
451(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
452i
453PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
454(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
455EXECUTE stmt;
456i
457EXECUTE stmt;
458i
459DEALLOCATE PREPARE stmt;
460EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
461(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
462id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4631	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
4642	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
465Warnings:
466Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where multiple equal(NULL) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
467SELECT * FROM t1 WHERE (t1.i) IN
468(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
469i
470PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
471(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
472EXECUTE stmt;
473i
474EXECUTE stmt;
475i
476DEALLOCATE PREPARE stmt;
477EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
478(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
479id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4801	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
4812	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
4822	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
483Warnings:
484Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from dual where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
485SELECT * FROM t1 WHERE (t1.i) IN
486(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
487i
488EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
489(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
490id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4911	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
4922	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
493Warnings:
494Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
495SELECT * FROM t1 WHERE (t1.i) IN
496(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
497i
498EXPLAIN SELECT * FROM t1 WHERE (11) IN
499(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
500id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5011	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
5022	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
503Warnings:
504Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
505SELECT * FROM t1 WHERE (11) IN
506(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
507i
508EXPLAIN SELECT * FROM t1 WHERE (11) IN
509(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
510id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5111	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
5122	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
513Warnings:
514Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
515Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
516SELECT * FROM t1 WHERE (11) IN
517(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
518i
519EXPLAIN SELECT * FROM t1 WHERE (11) IN
520(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
521id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5221	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
5232	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
524Warnings:
525Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
526SELECT * FROM t1 WHERE (11) IN
527(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
528i
529EXPLAIN SELECT * FROM t1 WHERE (11) IN
530(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
531id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5321	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
5332	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
534Warnings:
535Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
536SELECT * FROM t1 WHERE (11) IN
537(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
538i
539INSERT INTO t3 VALUES (1);
540SELECT (SELECT COUNT(*) from t1) AS c1,
541(SELECT COUNT(*) from t2) AS c2,
542(SELECT COUNT(*) from t3) AS c3;
543c1	c2	c3
5440	0	2
545EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
546(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
547id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5481	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
5492	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
550Warnings:
551Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where multiple equal(NULL, `test`.`t3`.`i`) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
552SELECT * FROM t1 WHERE (t1.i) IN
553(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
554i
555PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
556(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
557EXECUTE stmt;
558i
559EXECUTE stmt;
560i
561DEALLOCATE PREPARE stmt;
562EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
563(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
564id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5651	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
5662	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
567Warnings:
568Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where multiple equal(NULL, `test`.`t3`.`i`) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
569SELECT * FROM t1 WHERE (t1.i) IN
570(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
571i
572PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
573(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
574EXECUTE stmt;
575i
576EXECUTE stmt;
577i
578DEALLOCATE PREPARE stmt;
579EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
580(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
581id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5821	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
5832	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
5842	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
585Warnings:
586Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
587SELECT * FROM t1 WHERE (t1.i) IN
588(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
589i
590EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
591(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
592id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
5931	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
5942	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
595Warnings:
596Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
597SELECT * FROM t1 WHERE (t1.i) IN
598(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
599i
600EXPLAIN SELECT * FROM t1 WHERE (11) IN
601(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
602id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6031	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
6042	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
605Warnings:
606Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
607SELECT * FROM t1 WHERE (11) IN
608(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
609i
610EXPLAIN SELECT * FROM t1 WHERE (11) IN
611(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
612id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6131	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
6142	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
615Warnings:
616Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
617Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
618SELECT * FROM t1 WHERE (11) IN
619(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
620i
621EXPLAIN SELECT * FROM t1 WHERE (11) IN
622(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
623id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6241	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
6252	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
6262	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
627Warnings:
628Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
629SELECT * FROM t1 WHERE (11) IN
630(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
631i
632EXPLAIN SELECT * FROM t1 WHERE (11) IN
633(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
634id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6351	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
6362	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
637Warnings:
638Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
639SELECT * FROM t1 WHERE (11) IN
640(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
641i
642INSERT INTO t3 VALUES (0);
643DELETE FROM t3;
644INSERT INTO t2 VALUES (2);
645SELECT (SELECT COUNT(*) from t1) AS c1,
646(SELECT COUNT(*) from t2) AS c2,
647(SELECT COUNT(*) from t3) AS c3;
648c1	c2	c3
6490	1	0
650EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
651(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
652id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6531	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
6542	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
655Warnings:
656Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` where multiple equal('2', NULL) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
657SELECT * FROM t1 WHERE (t1.i) IN
658(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
659i
660PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
661(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
662EXECUTE stmt;
663i
664EXECUTE stmt;
665i
666DEALLOCATE PREPARE stmt;
667EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
668(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
669id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6701	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
6712	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
672Warnings:
673Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` where multiple equal('2', NULL) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
674SELECT * FROM t1 WHERE (t1.i) IN
675(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
676i
677PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
678(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
679EXECUTE stmt;
680i
681EXECUTE stmt;
682i
683DEALLOCATE PREPARE stmt;
684EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
685(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
686id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6871	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
6882	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
689Warnings:
690Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` left join `test`.`t2` on(multiple equal(NULL, NULL)) where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
691SELECT * FROM t1 WHERE (t1.i) IN
692(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
693i
694EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
695(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
696id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
6971	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
6982	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
699Warnings:
700Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
701SELECT * FROM t1 WHERE (t1.i) IN
702(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
703i
704EXPLAIN SELECT * FROM t1 WHERE (11) IN
705(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
706id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7071	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
7082	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
709Warnings:
710Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
711SELECT * FROM t1 WHERE (11) IN
712(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
713i
714EXPLAIN SELECT * FROM t1 WHERE (11) IN
715(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
716id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7171	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
7182	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
719Warnings:
720Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
721Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
722SELECT * FROM t1 WHERE (11) IN
723(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
724i
725EXPLAIN SELECT * FROM t1 WHERE (11) IN
726(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
727id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7281	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
7292	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
730Warnings:
731Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
732SELECT * FROM t1 WHERE (11) IN
733(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
734i
735EXPLAIN SELECT * FROM t1 WHERE (11) IN
736(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
737id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7381	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
7392	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
740Warnings:
741Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
742SELECT * FROM t1 WHERE (11) IN
743(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
744i
745INSERT INTO t3 VALUES (2);
746SELECT (SELECT COUNT(*) from t1) AS c1,
747(SELECT COUNT(*) from t2) AS c2,
748(SELECT COUNT(*) from t3) AS c3;
749c1	c2	c3
7500	1	1
751EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
752(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
753id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7541	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
7552	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
7562	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
757Warnings:
758Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from dual where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
759SELECT * FROM t1 WHERE (t1.i) IN
760(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
761i
762PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
763(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
764EXECUTE stmt;
765i
766EXECUTE stmt;
767i
768DEALLOCATE PREPARE stmt;
769EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
770(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
771id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7721	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
7732	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
7742	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
775Warnings:
776Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from dual where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
777SELECT * FROM t1 WHERE (t1.i) IN
778(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
779i
780PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
781(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
782EXECUTE stmt;
783i
784EXECUTE stmt;
785i
786DEALLOCATE PREPARE stmt;
787EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
788(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
789id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7901	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
7912	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
7922	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
793Warnings:
794Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
795SELECT * FROM t1 WHERE (t1.i) IN
796(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
797i
798EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
799(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
800id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8011	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
8022	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
8032	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
804Warnings:
805Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
806SELECT * FROM t1 WHERE (t1.i) IN
807(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
808i
809EXPLAIN SELECT * FROM t1 WHERE (11) IN
810(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
811id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8121	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
8132	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
814Warnings:
815Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
816SELECT * FROM t1 WHERE (11) IN
817(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
818i
819EXPLAIN SELECT * FROM t1 WHERE (11) IN
820(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
821id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8221	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
8232	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
824Warnings:
825Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
826Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
827SELECT * FROM t1 WHERE (11) IN
828(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
829i
830EXPLAIN SELECT * FROM t1 WHERE (11) IN
831(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
832id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8331	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
8342	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
835Warnings:
836Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
837SELECT * FROM t1 WHERE (11) IN
838(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
839i
840EXPLAIN SELECT * FROM t1 WHERE (11) IN
841(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
842id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8431	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
8442	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
845Warnings:
846Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
847SELECT * FROM t1 WHERE (11) IN
848(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
849i
850INSERT INTO t3 VALUES (1);
851SELECT (SELECT COUNT(*) from t1) AS c1,
852(SELECT COUNT(*) from t2) AS c2,
853(SELECT COUNT(*) from t3) AS c3;
854c1	c2	c3
8550	1	2
856EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
857(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
858id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8591	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
8602	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
8612	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
862Warnings:
863Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` where (`test`.`t3`.`i` = '2') ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
864SELECT * FROM t1 WHERE (t1.i) IN
865(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
866i
867PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
868(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
869EXECUTE stmt;
870i
871EXECUTE stmt;
872i
873DEALLOCATE PREPARE stmt;
874EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
875(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
876id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8771	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
8782	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
8792	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
880Warnings:
881Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` where (`test`.`t3`.`i` = '2') ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
882SELECT * FROM t1 WHERE (t1.i) IN
883(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
884i
885PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
886(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
887EXECUTE stmt;
888i
889EXECUTE stmt;
890i
891DEALLOCATE PREPARE stmt;
892EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
893(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
894id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
8951	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
8962	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
8972	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
898Warnings:
899Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` left join `test`.`t2` on((`test`.`t2`.`i` = `test`.`t3`.`i`)) where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
900SELECT * FROM t1 WHERE (t1.i) IN
901(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
902i
903EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
904(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
905id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9061	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
9072	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
9082	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
909Warnings:
910Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
911SELECT * FROM t1 WHERE (t1.i) IN
912(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
913i
914EXPLAIN SELECT * FROM t1 WHERE (11) IN
915(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
916id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9171	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
9182	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
919Warnings:
920Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
921SELECT * FROM t1 WHERE (11) IN
922(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
923i
924EXPLAIN SELECT * FROM t1 WHERE (11) IN
925(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
926id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9271	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
9282	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
929Warnings:
930Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
931Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
932SELECT * FROM t1 WHERE (11) IN
933(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
934i
935EXPLAIN SELECT * FROM t1 WHERE (11) IN
936(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
937id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9381	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
9392	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
9402	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
941Warnings:
942Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
943SELECT * FROM t1 WHERE (11) IN
944(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
945i
946EXPLAIN SELECT * FROM t1 WHERE (11) IN
947(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
948id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9491	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
9502	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
9512	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
952Warnings:
953Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
954SELECT * FROM t1 WHERE (11) IN
955(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
956i
957INSERT INTO t3 VALUES (0);
958DELETE FROM t3;
959INSERT INTO t2 VALUES (1);
960SELECT (SELECT COUNT(*) from t1) AS c1,
961(SELECT COUNT(*) from t2) AS c2,
962(SELECT COUNT(*) from t3) AS c3;
963c1	c2	c3
9640	2	0
965EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
966(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
967id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9681	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
9692	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
970Warnings:
971Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` join `test`.`t3` where multiple equal(`test`.`t2`.`i`, NULL) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
972SELECT * FROM t1 WHERE (t1.i) IN
973(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
974i
975PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
976(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
977EXECUTE stmt;
978i
979EXECUTE stmt;
980i
981DEALLOCATE PREPARE stmt;
982EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
983(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
984id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
9851	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
9862	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
987Warnings:
988Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` join `test`.`t3` where multiple equal(`test`.`t2`.`i`, NULL) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
989SELECT * FROM t1 WHERE (t1.i) IN
990(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
991i
992PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
993(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
994EXECUTE stmt;
995i
996EXECUTE stmt;
997i
998DEALLOCATE PREPARE stmt;
999EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1000(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1001id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10021	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
10032	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1004Warnings:
1005Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` left join `test`.`t2` on(multiple equal(`test`.`t2`.`i`, NULL)) where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1006SELECT * FROM t1 WHERE (t1.i) IN
1007(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1008i
1009EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1010(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1011id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10121	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
10132	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
10142	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	0	0.00	Using join buffer (Block Nested Loop)
1015Warnings:
1016Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1017SELECT * FROM t1 WHERE (t1.i) IN
1018(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1019i
1020EXPLAIN SELECT * FROM t1 WHERE (11) IN
1021(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1022id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10231	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
10242	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1025Warnings:
1026Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1027SELECT * FROM t1 WHERE (11) IN
1028(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1029i
1030EXPLAIN SELECT * FROM t1 WHERE (11) IN
1031(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1032id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10331	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
10342	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
1035Warnings:
1036Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1037Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
1038SELECT * FROM t1 WHERE (11) IN
1039(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1040i
1041EXPLAIN SELECT * FROM t1 WHERE (11) IN
1042(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1043id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10441	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
10452	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1046Warnings:
1047Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1048SELECT * FROM t1 WHERE (11) IN
1049(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1050i
1051EXPLAIN SELECT * FROM t1 WHERE (11) IN
1052(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1053id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10541	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
10552	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
10562	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	0	0.00	Using where; Using join buffer (Block Nested Loop)
1057Warnings:
1058Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1059SELECT * FROM t1 WHERE (11) IN
1060(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1061i
1062INSERT INTO t3 VALUES (2);
1063SELECT (SELECT COUNT(*) from t1) AS c1,
1064(SELECT COUNT(*) from t2) AS c2,
1065(SELECT COUNT(*) from t3) AS c3;
1066c1	c2	c3
10670	2	1
1068EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1069(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1070id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10711	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
10722	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
10732	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
1074Warnings:
1075Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where (`test`.`t2`.`i` = '2') ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1076SELECT * FROM t1 WHERE (t1.i) IN
1077(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1078i
1079PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1080(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1081EXECUTE stmt;
1082i
1083EXECUTE stmt;
1084i
1085DEALLOCATE PREPARE stmt;
1086EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1087(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1088id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
10891	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
10902	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
10912	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
1092Warnings:
1093Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where (`test`.`t2`.`i` = '2') ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1094SELECT * FROM t1 WHERE (t1.i) IN
1095(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1096i
1097PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1098(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1099EXECUTE stmt;
1100i
1101EXECUTE stmt;
1102i
1103DEALLOCATE PREPARE stmt;
1104EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1105(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1106id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11071	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
11082	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
11092	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
1110Warnings:
1111Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1112SELECT * FROM t1 WHERE (t1.i) IN
1113(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1114i
1115EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1116(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1117id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11181	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
11192	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
11202	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using join buffer (Block Nested Loop)
1121Warnings:
1122Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1123SELECT * FROM t1 WHERE (t1.i) IN
1124(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1125i
1126EXPLAIN SELECT * FROM t1 WHERE (11) IN
1127(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1128id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11291	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
11302	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1131Warnings:
1132Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1133SELECT * FROM t1 WHERE (11) IN
1134(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1135i
1136EXPLAIN SELECT * FROM t1 WHERE (11) IN
1137(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1138id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11391	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
11402	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
1141Warnings:
1142Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1143Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
1144SELECT * FROM t1 WHERE (11) IN
1145(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1146i
1147EXPLAIN SELECT * FROM t1 WHERE (11) IN
1148(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1149id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11501	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
11512	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1152Warnings:
1153Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1154SELECT * FROM t1 WHERE (11) IN
1155(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1156i
1157EXPLAIN SELECT * FROM t1 WHERE (11) IN
1158(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1159id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11601	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
11612	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
11622	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
1163Warnings:
1164Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1165SELECT * FROM t1 WHERE (11) IN
1166(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1167i
1168INSERT INTO t3 VALUES (1);
1169SELECT (SELECT COUNT(*) from t1) AS c1,
1170(SELECT COUNT(*) from t2) AS c2,
1171(SELECT COUNT(*) from t3) AS c3;
1172c1	c2	c3
11730	2	2
1174EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1175(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1176id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11771	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
11782	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
11792	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
1180Warnings:
1181Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where (`test`.`t3`.`i` = `test`.`t2`.`i`) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1182SELECT * FROM t1 WHERE (t1.i) IN
1183(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1184i
1185PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1186(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1187EXECUTE stmt;
1188i
1189EXECUTE stmt;
1190i
1191DEALLOCATE PREPARE stmt;
1192EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1193(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1194id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
11951	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
11962	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
11972	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
1198Warnings:
1199Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where (`test`.`t3`.`i` = `test`.`t2`.`i`) ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1200SELECT * FROM t1 WHERE (t1.i) IN
1201(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1202i
1203PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1204(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1205EXECUTE stmt;
1206i
1207EXECUTE stmt;
1208i
1209DEALLOCATE PREPARE stmt;
1210EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1211(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1212id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
12131	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
12142	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
12152	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
1216Warnings:
1217Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` left join `test`.`t2` on((`test`.`t2`.`i` = `test`.`t3`.`i`)) where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1218SELECT * FROM t1 WHERE (t1.i) IN
1219(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1220i
1221EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1222(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1223id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
12241	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
12252	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
12262	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (Block Nested Loop)
1227Warnings:
1228Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`i`)))))
1229SELECT * FROM t1 WHERE (t1.i) IN
1230(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1231i
1232EXPLAIN SELECT * FROM t1 WHERE (11) IN
1233(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1234id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
12351	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
12362	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
12372	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
1238Warnings:
1239Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1240SELECT * FROM t1 WHERE (11) IN
1241(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1242i
1243EXPLAIN SELECT * FROM t1 WHERE (11) IN
1244(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1245id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
12461	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
12472	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
1248Warnings:
1249Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1250Note	1003	/* select#1 */ select NULL AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where 0))
1251SELECT * FROM t1 WHERE (11) IN
1252(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1253i
1254EXPLAIN SELECT * FROM t1 WHERE (11) IN
1255(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1256id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
12571	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
12582	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
12592	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
1260Warnings:
1261Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1262SELECT * FROM t1 WHERE (11) IN
1263(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1264i
1265EXPLAIN SELECT * FROM t1 WHERE (11) IN
1266(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1267id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
12681	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
12692	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
12702	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
1271Warnings:
1272Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1273SELECT * FROM t1 WHERE (11) IN
1274(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1275i
1276INSERT INTO t3 VALUES (0);
1277DELETE FROM t3;
1278INSERT INTO t2 VALUES (0);
1279DELETE FROM t2;
1280INSERT INTO t1 VALUES (2);
1281SELECT (SELECT COUNT(*) from t1) AS c1,
1282(SELECT COUNT(*) from t2) AS c2,
1283(SELECT COUNT(*) from t3) AS c3;
1284c1	c2	c3
12851	0	0
1286EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1287(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1288id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
12891	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
12902	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1291Warnings:
1292Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((<cache>('2') = NULL) and multiple equal(NULL, NULL))))
1293SELECT * FROM t1 WHERE (t1.i) IN
1294(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1295i
1296PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1297(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1298EXECUTE stmt;
1299i
1300EXECUTE stmt;
1301i
1302DEALLOCATE PREPARE stmt;
1303EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1304(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1305id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
13061	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
13072	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1308Warnings:
1309Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((<cache>('2') = NULL) and multiple equal(NULL, NULL))))
1310SELECT * FROM t1 WHERE (t1.i) IN
1311(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1312i
1313PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1314(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1315EXECUTE stmt;
1316i
1317EXECUTE stmt;
1318i
1319DEALLOCATE PREPARE stmt;
1320EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1321(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1322id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
13231	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
13242	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1325Warnings:
1326Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where (<cache>('2') = NULL)))
1327SELECT * FROM t1 WHERE (t1.i) IN
1328(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1329i
1330EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1331(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1332id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
13331	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
13342	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1335Warnings:
1336Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` straight_join `test`.`t3` where (<cache>('2') = NULL)))
1337SELECT * FROM t1 WHERE (t1.i) IN
1338(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1339i
1340EXPLAIN SELECT * FROM t1 WHERE (11) IN
1341(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1342id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
13431	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
13442	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1345Warnings:
1346Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1347SELECT * FROM t1 WHERE (11) IN
1348(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1349i
1350EXPLAIN SELECT * FROM t1 WHERE (11) IN
1351(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1352id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
13531	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
13542	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1355Warnings:
1356Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1357Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where multiple equal(<cache>(11), NULL, NULL)))
1358SELECT * FROM t1 WHERE (11) IN
1359(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1360i
1361EXPLAIN SELECT * FROM t1 WHERE (11) IN
1362(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1363id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
13641	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
13652	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1366Warnings:
1367Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1368SELECT * FROM t1 WHERE (11) IN
1369(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1370i
1371EXPLAIN SELECT * FROM t1 WHERE (11) IN
1372(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1373id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
13741	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
13752	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1376Warnings:
1377Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1378SELECT * FROM t1 WHERE (11) IN
1379(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1380i
1381INSERT INTO t3 VALUES (2);
1382SELECT (SELECT COUNT(*) from t1) AS c1,
1383(SELECT COUNT(*) from t2) AS c2,
1384(SELECT COUNT(*) from t3) AS c3;
1385c1	c2	c3
13861	0	1
1387EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1388(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1389id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
13901	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
13912	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1392Warnings:
1393Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` where ((<cache>('2') = '2') and multiple equal(NULL))))
1394SELECT * FROM t1 WHERE (t1.i) IN
1395(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1396i
1397PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1398(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1399EXECUTE stmt;
1400i
1401EXECUTE stmt;
1402i
1403DEALLOCATE PREPARE stmt;
1404EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1405(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1406id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14071	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
14082	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1409Warnings:
1410Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` where ((<cache>('2') = '2') and multiple equal(NULL))))
1411SELECT * FROM t1 WHERE (t1.i) IN
1412(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1413i
1414PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1415(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1416EXECUTE stmt;
1417i
1418EXECUTE stmt;
1419i
1420DEALLOCATE PREPARE stmt;
1421EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1422(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1423id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14241	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
14252	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
14262	DEPENDENT SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
1427Warnings:
1428Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from dual where (<cache>('2') = '2')))
1429SELECT * FROM t1 WHERE (t1.i) IN
1430(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1431i
14322
1433EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1434(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1435id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14361	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
14372	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1438Warnings:
1439Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` straight_join `test`.`t3` where (<cache>('2') = '2')))
1440SELECT * FROM t1 WHERE (t1.i) IN
1441(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1442i
1443EXPLAIN SELECT * FROM t1 WHERE (11) IN
1444(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1445id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14461	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
14472	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1448Warnings:
1449Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1450SELECT * FROM t1 WHERE (11) IN
1451(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1452i
1453EXPLAIN SELECT * FROM t1 WHERE (11) IN
1454(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1455id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14561	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
14572	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1458Warnings:
1459Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1460Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` where multiple equal(<cache>(11))))
1461SELECT * FROM t1 WHERE (11) IN
1462(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1463i
1464EXPLAIN SELECT * FROM t1 WHERE (11) IN
1465(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1466id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14671	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
14682	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1469Warnings:
1470Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1471SELECT * FROM t1 WHERE (11) IN
1472(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1473i
1474EXPLAIN SELECT * FROM t1 WHERE (11) IN
1475(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1476id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14771	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
14782	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1479Warnings:
1480Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1481SELECT * FROM t1 WHERE (11) IN
1482(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1483i
1484INSERT INTO t3 VALUES (1);
1485SELECT (SELECT COUNT(*) from t1) AS c1,
1486(SELECT COUNT(*) from t2) AS c2,
1487(SELECT COUNT(*) from t3) AS c3;
1488c1	c2	c3
14891	0	2
1490EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1491(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1492id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14931	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
14942	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1495Warnings:
1496Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((<cache>('2') = `test`.`t3`.`i`) and multiple equal(NULL, `test`.`t3`.`i`))))
1497SELECT * FROM t1 WHERE (t1.i) IN
1498(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1499i
1500PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1501(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1502EXECUTE stmt;
1503i
1504EXECUTE stmt;
1505i
1506DEALLOCATE PREPARE stmt;
1507EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1508(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1509id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
15101	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
15112	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1512Warnings:
1513Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((<cache>('2') = `test`.`t3`.`i`) and multiple equal(NULL, `test`.`t3`.`i`))))
1514SELECT * FROM t1 WHERE (t1.i) IN
1515(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1516i
1517PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1518(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1519EXECUTE stmt;
1520i
1521EXECUTE stmt;
1522i
1523DEALLOCATE PREPARE stmt;
1524EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1525(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1526id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
15271	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
15282	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
15292	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
1530Warnings:
1531Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where (<cache>('2') = `test`.`t3`.`i`)))
1532SELECT * FROM t1 WHERE (t1.i) IN
1533(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1534i
15352
1536EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1537(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1538id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
15391	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
15402	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1541Warnings:
1542Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` straight_join `test`.`t3` where (<cache>('2') = `test`.`t3`.`i`)))
1543SELECT * FROM t1 WHERE (t1.i) IN
1544(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1545i
1546EXPLAIN SELECT * FROM t1 WHERE (11) IN
1547(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1548id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
15491	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
15502	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1551Warnings:
1552Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1553SELECT * FROM t1 WHERE (11) IN
1554(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1555i
1556EXPLAIN SELECT * FROM t1 WHERE (11) IN
1557(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1558id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
15591	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
15602	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1561Warnings:
1562Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1563Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where multiple equal(<cache>(11), `test`.`t3`.`i`, NULL)))
1564SELECT * FROM t1 WHERE (11) IN
1565(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1566i
1567EXPLAIN SELECT * FROM t1 WHERE (11) IN
1568(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1569id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
15701	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
15712	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
15722	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
1573Warnings:
1574Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1575SELECT * FROM t1 WHERE (11) IN
1576(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1577i
1578EXPLAIN SELECT * FROM t1 WHERE (11) IN
1579(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1580id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
15811	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
15822	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1583Warnings:
1584Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1585SELECT * FROM t1 WHERE (11) IN
1586(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1587i
1588INSERT INTO t3 VALUES (0);
1589DELETE FROM t3;
1590INSERT INTO t2 VALUES (2);
1591SELECT (SELECT COUNT(*) from t1) AS c1,
1592(SELECT COUNT(*) from t2) AS c2,
1593(SELECT COUNT(*) from t3) AS c3;
1594c1	c2	c3
15951	1	0
1596EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1597(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1598id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
15991	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
16002	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1601Warnings:
1602Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where ((<cache>('2') = NULL) and multiple equal('2', NULL))))
1603SELECT * FROM t1 WHERE (t1.i) IN
1604(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1605i
1606PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1607(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1608EXECUTE stmt;
1609i
1610EXECUTE stmt;
1611i
1612DEALLOCATE PREPARE stmt;
1613EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1614(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1615id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
16161	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
16172	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1618Warnings:
1619Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where ((<cache>('2') = NULL) and multiple equal('2', NULL))))
1620SELECT * FROM t1 WHERE (t1.i) IN
1621(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1622i
1623PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1624(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1625EXECUTE stmt;
1626i
1627EXECUTE stmt;
1628i
1629DEALLOCATE PREPARE stmt;
1630EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1631(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1632id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
16331	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
16342	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1635Warnings:
1636Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` left join `test`.`t2` on(multiple equal(NULL, NULL)) where (<cache>('2') = NULL)))
1637SELECT * FROM t1 WHERE (t1.i) IN
1638(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1639i
1640EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1641(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1642id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
16431	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
16442	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1645Warnings:
1646Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where (<cache>('2') = NULL)))
1647SELECT * FROM t1 WHERE (t1.i) IN
1648(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1649i
1650EXPLAIN SELECT * FROM t1 WHERE (11) IN
1651(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1652id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
16531	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
16542	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1655Warnings:
1656Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1657SELECT * FROM t1 WHERE (11) IN
1658(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1659i
1660EXPLAIN SELECT * FROM t1 WHERE (11) IN
1661(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1662id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
16631	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
16642	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1665Warnings:
1666Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1667Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t3` where multiple equal(<cache>(11), NULL)))
1668SELECT * FROM t1 WHERE (11) IN
1669(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1670i
1671EXPLAIN SELECT * FROM t1 WHERE (11) IN
1672(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1673id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
16741	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
16752	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1676Warnings:
1677Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1678SELECT * FROM t1 WHERE (11) IN
1679(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1680i
1681EXPLAIN SELECT * FROM t1 WHERE (11) IN
1682(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1683id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
16841	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
16852	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1686Warnings:
1687Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1688SELECT * FROM t1 WHERE (11) IN
1689(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1690i
1691INSERT INTO t3 VALUES (2);
1692SELECT (SELECT COUNT(*) from t1) AS c1,
1693(SELECT COUNT(*) from t2) AS c2,
1694(SELECT COUNT(*) from t3) AS c3;
1695c1	c2	c3
16961	1	1
1697EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1698(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1699id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17001	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
17012	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
17022	DEPENDENT SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
1703Warnings:
1704Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from dual where ((<cache>('2') = '2'))))
1705SELECT * FROM t1 WHERE (t1.i) IN
1706(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1707i
17082
1709PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1710(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1711EXECUTE stmt;
1712i
17132
1714EXECUTE stmt;
1715i
17162
1717DEALLOCATE PREPARE stmt;
1718EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1719(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1720id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17211	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
17222	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
17232	DEPENDENT SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
1724Warnings:
1725Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from dual where ((<cache>('2') = '2'))))
1726SELECT * FROM t1 WHERE (t1.i) IN
1727(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1728i
17292
1730PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1731(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1732EXECUTE stmt;
1733i
17342
1735EXECUTE stmt;
1736i
17372
1738DEALLOCATE PREPARE stmt;
1739EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1740(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1741id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17421	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
17432	DEPENDENT SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
17442	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
1745Warnings:
1746Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` where (<cache>('2') = '2')))
1747SELECT * FROM t1 WHERE (t1.i) IN
1748(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1749i
17502
1751EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1752(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1753id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17541	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
17552	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
17562	DEPENDENT SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
1757Warnings:
1758Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where (<cache>('2') = '2')))
1759SELECT * FROM t1 WHERE (t1.i) IN
1760(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1761i
17622
1763EXPLAIN SELECT * FROM t1 WHERE (11) IN
1764(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1765id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17661	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
17672	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1768Warnings:
1769Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1770SELECT * FROM t1 WHERE (11) IN
1771(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1772i
1773EXPLAIN SELECT * FROM t1 WHERE (11) IN
1774(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1775id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17761	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
17772	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1778Warnings:
1779Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1780Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from dual where 0))
1781SELECT * FROM t1 WHERE (11) IN
1782(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1783i
1784EXPLAIN SELECT * FROM t1 WHERE (11) IN
1785(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1786id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17871	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
17882	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1789Warnings:
1790Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1791SELECT * FROM t1 WHERE (11) IN
1792(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1793i
1794EXPLAIN SELECT * FROM t1 WHERE (11) IN
1795(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1796id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17971	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
17982	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1799Warnings:
1800Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1801SELECT * FROM t1 WHERE (11) IN
1802(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1803i
1804INSERT INTO t3 VALUES (1);
1805SELECT (SELECT COUNT(*) from t1) AS c1,
1806(SELECT COUNT(*) from t2) AS c2,
1807(SELECT COUNT(*) from t3) AS c3;
1808c1	c2	c3
18091	1	2
1810EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1811(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1812id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
18131	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
18142	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
18152	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
1816Warnings:
1817Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where ((`test`.`t3`.`i` = '2') and (<cache>('2') = '2'))))
1818SELECT * FROM t1 WHERE (t1.i) IN
1819(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1820i
18212
1822PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1823(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1824EXECUTE stmt;
1825i
18262
1827EXECUTE stmt;
1828i
18292
1830DEALLOCATE PREPARE stmt;
1831EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1832(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1833id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
18341	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
18352	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
18362	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
1837Warnings:
1838Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where ((`test`.`t3`.`i` = '2') and (<cache>('2') = '2'))))
1839SELECT * FROM t1 WHERE (t1.i) IN
1840(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1841i
18422
1843PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1844(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1845EXECUTE stmt;
1846i
18472
1848EXECUTE stmt;
1849i
18502
1851DEALLOCATE PREPARE stmt;
1852EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1853(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1854id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
18551	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
18562	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
18572	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
1858Warnings:
1859Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` left join `test`.`t2` on((`test`.`t2`.`i` = `test`.`t3`.`i`)) where (<cache>('2') = `test`.`t3`.`i`)))
1860SELECT * FROM t1 WHERE (t1.i) IN
1861(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1862i
18632
1864EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1865(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1866id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
18671	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
18682	DEPENDENT SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
18692	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
1870Warnings:
1871Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` where (<cache>('2') = `test`.`t3`.`i`)))
1872SELECT * FROM t1 WHERE (t1.i) IN
1873(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1874i
18752
1876EXPLAIN SELECT * FROM t1 WHERE (11) IN
1877(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1878id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
18791	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
18802	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1881Warnings:
1882Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1883SELECT * FROM t1 WHERE (11) IN
1884(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1885i
1886EXPLAIN SELECT * FROM t1 WHERE (11) IN
1887(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1888id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
18891	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
18902	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1891Warnings:
1892Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1893Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t3` where 0))
1894SELECT * FROM t1 WHERE (11) IN
1895(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1896i
1897EXPLAIN SELECT * FROM t1 WHERE (11) IN
1898(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1899id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
19001	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
19012	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
19022	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
1903Warnings:
1904Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1905SELECT * FROM t1 WHERE (11) IN
1906(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1907i
1908EXPLAIN SELECT * FROM t1 WHERE (11) IN
1909(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1910id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
19111	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
19122	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
19132	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
1914Warnings:
1915Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1916SELECT * FROM t1 WHERE (11) IN
1917(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1918i
1919INSERT INTO t3 VALUES (0);
1920DELETE FROM t3;
1921INSERT INTO t2 VALUES (1);
1922SELECT (SELECT COUNT(*) from t1) AS c1,
1923(SELECT COUNT(*) from t2) AS c2,
1924(SELECT COUNT(*) from t3) AS c3;
1925c1	c2	c3
19261	2	0
1927EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1928(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1929id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
19301	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
19312	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1932Warnings:
1933Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((<cache>('2') = NULL) and multiple equal(`test`.`t2`.`i`, NULL))))
1934SELECT * FROM t1 WHERE (t1.i) IN
1935(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
1936i
1937PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1938(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
1939EXECUTE stmt;
1940i
1941EXECUTE stmt;
1942i
1943DEALLOCATE PREPARE stmt;
1944EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1945(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1946id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
19471	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
19482	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1949Warnings:
1950Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((<cache>('2') = NULL) and multiple equal(`test`.`t2`.`i`, NULL))))
1951SELECT * FROM t1 WHERE (t1.i) IN
1952(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1953i
1954PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
1955(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
1956EXECUTE stmt;
1957i
1958EXECUTE stmt;
1959i
1960DEALLOCATE PREPARE stmt;
1961EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1962(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1963id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
19641	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
19652	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1966Warnings:
1967Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` left join `test`.`t2` on(multiple equal(`test`.`t2`.`i`, NULL)) where (<cache>('2') = NULL)))
1968SELECT * FROM t1 WHERE (t1.i) IN
1969(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
1970i
1971EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
1972(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1973id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
19741	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
19752	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
19762	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	0	0.00	Using where; Using join buffer (Block Nested Loop)
1977Warnings:
1978Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` straight_join `test`.`t3` where (<cache>('2') = `test`.`t3`.`i`)))
1979SELECT * FROM t1 WHERE (t1.i) IN
1980(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
1981i
1982EXPLAIN SELECT * FROM t1 WHERE (11) IN
1983(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1984id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
19851	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
19862	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1987Warnings:
1988Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
1989SELECT * FROM t1 WHERE (11) IN
1990(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
1991i
1992EXPLAIN SELECT * FROM t1 WHERE (11) IN
1993(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
1994id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
19951	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
19962	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1997Warnings:
1998Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
1999Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where multiple equal(<cache>(11), NULL, `test`.`t2`.`i`)))
2000SELECT * FROM t1 WHERE (11) IN
2001(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2002i
2003EXPLAIN SELECT * FROM t1 WHERE (11) IN
2004(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2005id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
20061	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
20072	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2008Warnings:
2009Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2010SELECT * FROM t1 WHERE (11) IN
2011(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2012i
2013EXPLAIN SELECT * FROM t1 WHERE (11) IN
2014(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2015id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
20161	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
20172	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
20182	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	0	0.00	Using where; Using join buffer (Block Nested Loop)
2019Warnings:
2020Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2021SELECT * FROM t1 WHERE (11) IN
2022(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2023i
2024INSERT INTO t3 VALUES (2);
2025SELECT (SELECT COUNT(*) from t1) AS c1,
2026(SELECT COUNT(*) from t2) AS c2,
2027(SELECT COUNT(*) from t3) AS c3;
2028c1	c2	c3
20291	2	1
2030EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2031(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2032id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
20331	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
20342	DEPENDENT SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
20352	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
2036Warnings:
2037Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`i` = '2') and (<cache>('2') = '2'))))
2038SELECT * FROM t1 WHERE (t1.i) IN
2039(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2040i
20412
2042PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2043(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2044EXECUTE stmt;
2045i
20462
2047EXECUTE stmt;
2048i
20492
2050DEALLOCATE PREPARE stmt;
2051EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2052(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2053id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
20541	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
20552	DEPENDENT SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
20562	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
2057Warnings:
2058Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`i` = '2') and (<cache>('2') = '2'))))
2059SELECT * FROM t1 WHERE (t1.i) IN
2060(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2061i
20622
2063PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2064(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2065EXECUTE stmt;
2066i
20672
2068EXECUTE stmt;
2069i
20702
2071DEALLOCATE PREPARE stmt;
2072EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2073(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2074id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
20751	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
20762	DEPENDENT SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
20772	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
2078Warnings:
2079Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` where (<cache>('2') = '2')))
2080SELECT * FROM t1 WHERE (t1.i) IN
2081(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2082i
20832
2084EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2085(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2086id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
20871	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
20882	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
20892	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
2090Warnings:
2091Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` straight_join `test`.`t3` where (<cache>('2') = `test`.`t3`.`i`)))
2092SELECT * FROM t1 WHERE (t1.i) IN
2093(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2094i
20952
2096EXPLAIN SELECT * FROM t1 WHERE (11) IN
2097(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2098id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
20991	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
21002	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2101Warnings:
2102Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2103SELECT * FROM t1 WHERE (11) IN
2104(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2105i
2106EXPLAIN SELECT * FROM t1 WHERE (11) IN
2107(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2108id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
21091	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
21102	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2111Warnings:
2112Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2113Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` where 0))
2114SELECT * FROM t1 WHERE (11) IN
2115(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2116i
2117EXPLAIN SELECT * FROM t1 WHERE (11) IN
2118(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2119id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
21201	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
21212	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2122Warnings:
2123Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2124SELECT * FROM t1 WHERE (11) IN
2125(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2126i
2127EXPLAIN SELECT * FROM t1 WHERE (11) IN
2128(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2129id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
21301	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
21312	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
21322	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
2133Warnings:
2134Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2135SELECT * FROM t1 WHERE (11) IN
2136(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2137i
2138INSERT INTO t3 VALUES (1);
2139SELECT (SELECT COUNT(*) from t1) AS c1,
2140(SELECT COUNT(*) from t2) AS c2,
2141(SELECT COUNT(*) from t3) AS c3;
2142c1	c2	c3
21431	2	2
2144EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2145(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2146id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
21471	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
21482	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
21492	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
2150Warnings:
2151Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`i` = `test`.`t3`.`i`) and (<cache>('2') = `test`.`t3`.`i`))))
2152SELECT * FROM t1 WHERE (t1.i) IN
2153(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2154i
21552
2156PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2157(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2158EXECUTE stmt;
2159i
21602
2161EXECUTE stmt;
2162i
21632
2164DEALLOCATE PREPARE stmt;
2165EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2166(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2167id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
21681	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
21692	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
21702	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
2171Warnings:
2172Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`i` = `test`.`t3`.`i`) and (<cache>('2') = `test`.`t3`.`i`))))
2173SELECT * FROM t1 WHERE (t1.i) IN
2174(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2175i
21762
2177PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2178(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2179EXECUTE stmt;
2180i
21812
2182EXECUTE stmt;
2183i
21842
2185DEALLOCATE PREPARE stmt;
2186EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2187(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2188id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
21891	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
21902	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
21912	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
2192Warnings:
2193Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t3` left join `test`.`t2` on((`test`.`t2`.`i` = `test`.`t3`.`i`)) where (<cache>('2') = `test`.`t3`.`i`)))
2194SELECT * FROM t1 WHERE (t1.i) IN
2195(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2196i
21972
2198EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2199(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2200id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
22011	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
22022	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
22032	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
2204Warnings:
2205Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>('2',<exists>(/* select#2 */ select 1 from `test`.`t2` straight_join `test`.`t3` where (<cache>('2') = `test`.`t3`.`i`)))
2206SELECT * FROM t1 WHERE (t1.i) IN
2207(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2208i
22092
2210EXPLAIN SELECT * FROM t1 WHERE (11) IN
2211(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2212id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
22131	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
22142	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
22152	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
2216Warnings:
2217Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2218SELECT * FROM t1 WHERE (11) IN
2219(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2220i
2221EXPLAIN SELECT * FROM t1 WHERE (11) IN
2222(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2223id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
22241	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
22252	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
22262	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
2227Warnings:
2228Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2229Note	1003	/* select#1 */ select '2' AS `i` from dual where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`i` = <cache>(11)) and (`test`.`t3`.`i` = <cache>(11)))))
2230SELECT * FROM t1 WHERE (11) IN
2231(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2232i
2233EXPLAIN SELECT * FROM t1 WHERE (11) IN
2234(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2235id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
22361	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
22372	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
22382	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
2239Warnings:
2240Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2241SELECT * FROM t1 WHERE (11) IN
2242(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2243i
2244EXPLAIN SELECT * FROM t1 WHERE (11) IN
2245(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2246id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
22471	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
22482	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
22492	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
2250Warnings:
2251Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2252SELECT * FROM t1 WHERE (11) IN
2253(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2254i
2255INSERT INTO t3 VALUES (0);
2256DELETE FROM t3;
2257INSERT INTO t2 VALUES (0);
2258DELETE FROM t2;
2259INSERT INTO t1 VALUES (1);
2260SELECT (SELECT COUNT(*) from t1) AS c1,
2261(SELECT COUNT(*) from t2) AS c2,
2262(SELECT COUNT(*) from t3) AS c3;
2263c1	c2	c3
22642	0	0
2265EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2266(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2267id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
22681	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
22692	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2270Warnings:
2271Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` join `test`.`t3` where multiple equal(NULL, NULL) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2272SELECT * FROM t1 WHERE (t1.i) IN
2273(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2274i
2275PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2276(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2277EXECUTE stmt;
2278i
2279EXECUTE stmt;
2280i
2281DEALLOCATE PREPARE stmt;
2282EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2283(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2284id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
22851	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
22862	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2287Warnings:
2288Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` join `test`.`t3` where multiple equal(NULL, NULL) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2289SELECT * FROM t1 WHERE (t1.i) IN
2290(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2291i
2292PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2293(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2294EXECUTE stmt;
2295i
2296EXECUTE stmt;
2297i
2298DEALLOCATE PREPARE stmt;
2299EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2300(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2301id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23021	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
23032	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2304Warnings:
2305Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2306SELECT * FROM t1 WHERE (t1.i) IN
2307(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2308i
2309EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2310(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2311id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23121	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
23132	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2314Warnings:
2315Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2316SELECT * FROM t1 WHERE (t1.i) IN
2317(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2318i
2319EXPLAIN SELECT * FROM t1 WHERE (11) IN
2320(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2321id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23221	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
23232	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2324Warnings:
2325Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2326SELECT * FROM t1 WHERE (11) IN
2327(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2328i
2329EXPLAIN SELECT * FROM t1 WHERE (11) IN
2330(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2331id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23321	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
23332	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2334Warnings:
2335Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2336Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where (`test`.`t1`.`i` and multiple equal(<cache>(11), NULL, NULL))))
2337SELECT * FROM t1 WHERE (11) IN
2338(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2339i
2340EXPLAIN SELECT * FROM t1 WHERE (11) IN
2341(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2342id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23431	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
23442	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2345Warnings:
2346Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2347SELECT * FROM t1 WHERE (11) IN
2348(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2349i
2350EXPLAIN SELECT * FROM t1 WHERE (11) IN
2351(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2352id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23531	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
23542	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2355Warnings:
2356Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2357SELECT * FROM t1 WHERE (11) IN
2358(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2359i
2360INSERT INTO t3 VALUES (2);
2361SELECT (SELECT COUNT(*) from t1) AS c1,
2362(SELECT COUNT(*) from t2) AS c2,
2363(SELECT COUNT(*) from t3) AS c3;
2364c1	c2	c3
23652	0	1
2366EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2367(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2368id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23691	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
23702	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2371Warnings:
2372Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where multiple equal(NULL) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2373SELECT * FROM t1 WHERE (t1.i) IN
2374(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2375i
2376PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2377(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2378EXECUTE stmt;
2379i
2380EXECUTE stmt;
2381i
2382DEALLOCATE PREPARE stmt;
2383EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2384(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2385id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23861	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
23872	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2388Warnings:
2389Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where multiple equal(NULL) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2390SELECT * FROM t1 WHERE (t1.i) IN
2391(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2392i
2393PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2394(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2395EXECUTE stmt;
2396i
2397EXECUTE stmt;
2398i
2399DEALLOCATE PREPARE stmt;
2400EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2401(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2402id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24031	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
24042	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
24052	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
2406Warnings:
2407Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from dual where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2408SELECT * FROM t1 WHERE (t1.i) IN
2409(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2410i
24112
2412EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2413(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2414id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24151	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
24162	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2417Warnings:
2418Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2419SELECT * FROM t1 WHERE (t1.i) IN
2420(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2421i
2422EXPLAIN SELECT * FROM t1 WHERE (11) IN
2423(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2424id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24251	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
24262	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2427Warnings:
2428Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2429SELECT * FROM t1 WHERE (11) IN
2430(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2431i
2432EXPLAIN SELECT * FROM t1 WHERE (11) IN
2433(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2434id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24351	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
24362	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2437Warnings:
2438Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2439Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` where (`test`.`t1`.`i` and multiple equal(<cache>(11)))))
2440SELECT * FROM t1 WHERE (11) IN
2441(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2442i
2443EXPLAIN SELECT * FROM t1 WHERE (11) IN
2444(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2445id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24461	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
24472	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2448Warnings:
2449Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2450SELECT * FROM t1 WHERE (11) IN
2451(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2452i
2453EXPLAIN SELECT * FROM t1 WHERE (11) IN
2454(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2455id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24561	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
24572	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2458Warnings:
2459Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2460SELECT * FROM t1 WHERE (11) IN
2461(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2462i
2463INSERT INTO t3 VALUES (1);
2464SELECT (SELECT COUNT(*) from t1) AS c1,
2465(SELECT COUNT(*) from t2) AS c2,
2466(SELECT COUNT(*) from t3) AS c3;
2467c1	c2	c3
24682	0	2
2469EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2470(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2471id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24721	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
24732	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2474Warnings:
2475Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where multiple equal(NULL, `test`.`t3`.`i`) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2476SELECT * FROM t1 WHERE (t1.i) IN
2477(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2478i
2479PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2480(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2481EXECUTE stmt;
2482i
2483EXECUTE stmt;
2484i
2485DEALLOCATE PREPARE stmt;
2486EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2487(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2488id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24891	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
24902	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2491Warnings:
2492Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where multiple equal(NULL, `test`.`t3`.`i`) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2493SELECT * FROM t1 WHERE (t1.i) IN
2494(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2495i
2496PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2497(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2498EXECUTE stmt;
2499i
2500EXECUTE stmt;
2501i
2502DEALLOCATE PREPARE stmt;
2503EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2504(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2505id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25061	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
25072	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
25082	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
2509Warnings:
2510Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2511SELECT * FROM t1 WHERE (t1.i) IN
2512(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2513i
25142
25151
2516EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2517(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2518id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25191	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
25202	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2521Warnings:
2522Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2523SELECT * FROM t1 WHERE (t1.i) IN
2524(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2525i
2526EXPLAIN SELECT * FROM t1 WHERE (11) IN
2527(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2528id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25291	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
25302	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2531Warnings:
2532Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2533SELECT * FROM t1 WHERE (11) IN
2534(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2535i
2536EXPLAIN SELECT * FROM t1 WHERE (11) IN
2537(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2538id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25391	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
25402	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2541Warnings:
2542Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2543Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where (`test`.`t1`.`i` and multiple equal(<cache>(11), `test`.`t3`.`i`, NULL))))
2544SELECT * FROM t1 WHERE (11) IN
2545(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2546i
2547EXPLAIN SELECT * FROM t1 WHERE (11) IN
2548(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2549id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25501	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
25512	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
25522	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
2553Warnings:
2554Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2555SELECT * FROM t1 WHERE (11) IN
2556(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2557i
2558EXPLAIN SELECT * FROM t1 WHERE (11) IN
2559(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2560id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25611	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
25622	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2563Warnings:
2564Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2565SELECT * FROM t1 WHERE (11) IN
2566(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2567i
2568INSERT INTO t3 VALUES (0);
2569DELETE FROM t3;
2570INSERT INTO t2 VALUES (2);
2571SELECT (SELECT COUNT(*) from t1) AS c1,
2572(SELECT COUNT(*) from t2) AS c2,
2573(SELECT COUNT(*) from t3) AS c3;
2574c1	c2	c3
25752	1	0
2576EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2577(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2578id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25791	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
25802	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2581Warnings:
2582Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` where multiple equal('2', NULL) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2583SELECT * FROM t1 WHERE (t1.i) IN
2584(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2585i
2586PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2587(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2588EXECUTE stmt;
2589i
2590EXECUTE stmt;
2591i
2592DEALLOCATE PREPARE stmt;
2593EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2594(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2595id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25961	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
25972	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2598Warnings:
2599Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` where multiple equal('2', NULL) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2600SELECT * FROM t1 WHERE (t1.i) IN
2601(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2602i
2603PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2604(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2605EXECUTE stmt;
2606i
2607EXECUTE stmt;
2608i
2609DEALLOCATE PREPARE stmt;
2610EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2611(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2612id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
26131	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
26142	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2615Warnings:
2616Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` left join `test`.`t2` on(multiple equal(NULL, NULL)) where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2617SELECT * FROM t1 WHERE (t1.i) IN
2618(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2619i
2620EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2621(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2622id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
26231	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
26242	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2625Warnings:
2626Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2627SELECT * FROM t1 WHERE (t1.i) IN
2628(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2629i
2630EXPLAIN SELECT * FROM t1 WHERE (11) IN
2631(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2632id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
26331	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
26342	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2635Warnings:
2636Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2637SELECT * FROM t1 WHERE (11) IN
2638(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2639i
2640EXPLAIN SELECT * FROM t1 WHERE (11) IN
2641(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2642id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
26431	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
26442	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2645Warnings:
2646Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2647Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t3` where (`test`.`t1`.`i` and multiple equal(<cache>(11), NULL))))
2648SELECT * FROM t1 WHERE (11) IN
2649(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2650i
2651EXPLAIN SELECT * FROM t1 WHERE (11) IN
2652(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2653id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
26541	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
26552	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2656Warnings:
2657Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2658SELECT * FROM t1 WHERE (11) IN
2659(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2660i
2661EXPLAIN SELECT * FROM t1 WHERE (11) IN
2662(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2663id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
26641	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
26652	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2666Warnings:
2667Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2668SELECT * FROM t1 WHERE (11) IN
2669(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2670i
2671INSERT INTO t3 VALUES (2);
2672SELECT (SELECT COUNT(*) from t1) AS c1,
2673(SELECT COUNT(*) from t2) AS c2,
2674(SELECT COUNT(*) from t3) AS c3;
2675c1	c2	c3
26762	1	1
2677EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2678(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2679id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
26801	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
26812	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
26822	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
2683Warnings:
2684Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from dual where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2685SELECT * FROM t1 WHERE (t1.i) IN
2686(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2687i
26882
2689PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2690(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2691EXECUTE stmt;
2692i
26932
2694EXECUTE stmt;
2695i
26962
2697DEALLOCATE PREPARE stmt;
2698EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2699(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2700id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
27011	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
27022	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
27032	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
2704Warnings:
2705Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from dual where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2706SELECT * FROM t1 WHERE (t1.i) IN
2707(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2708i
27092
2710PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2711(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2712EXECUTE stmt;
2713i
27142
2715EXECUTE stmt;
2716i
27172
2718DEALLOCATE PREPARE stmt;
2719EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2720(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2721id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
27221	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
27232	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
27242	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
2725Warnings:
2726Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2727SELECT * FROM t1 WHERE (t1.i) IN
2728(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2729i
27302
2731EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2732(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2733id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
27341	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
27352	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
27362	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
2737Warnings:
2738Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2739SELECT * FROM t1 WHERE (t1.i) IN
2740(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2741i
27422
2743EXPLAIN SELECT * FROM t1 WHERE (11) IN
2744(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2745id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
27461	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
27472	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2748Warnings:
2749Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2750SELECT * FROM t1 WHERE (11) IN
2751(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2752i
2753EXPLAIN SELECT * FROM t1 WHERE (11) IN
2754(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2755id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
27561	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
27572	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2758Warnings:
2759Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2760Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from dual where 0))
2761SELECT * FROM t1 WHERE (11) IN
2762(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2763i
2764EXPLAIN SELECT * FROM t1 WHERE (11) IN
2765(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2766id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
27671	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
27682	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2769Warnings:
2770Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2771SELECT * FROM t1 WHERE (11) IN
2772(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2773i
2774EXPLAIN SELECT * FROM t1 WHERE (11) IN
2775(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2776id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
27771	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
27782	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2779Warnings:
2780Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2781SELECT * FROM t1 WHERE (11) IN
2782(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2783i
2784INSERT INTO t3 VALUES (1);
2785SELECT (SELECT COUNT(*) from t1) AS c1,
2786(SELECT COUNT(*) from t2) AS c2,
2787(SELECT COUNT(*) from t3) AS c3;
2788c1	c2	c3
27892	1	2
2790EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2791(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2792id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
27931	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
27942	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
27952	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
2796Warnings:
2797Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` where (`test`.`t3`.`i` = '2') ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2798SELECT * FROM t1 WHERE (t1.i) IN
2799(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2800i
28012
2802PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2803(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2804EXECUTE stmt;
2805i
28062
2807EXECUTE stmt;
2808i
28092
2810DEALLOCATE PREPARE stmt;
2811EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2812(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2813id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
28141	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
28152	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
28162	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
2817Warnings:
2818Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` where (`test`.`t3`.`i` = '2') ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2819SELECT * FROM t1 WHERE (t1.i) IN
2820(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2821i
28222
2823PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2824(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2825EXECUTE stmt;
2826i
28272
2828EXECUTE stmt;
2829i
28302
2831DEALLOCATE PREPARE stmt;
2832EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2833(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2834id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
28351	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
28362	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
28372	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
2838Warnings:
2839Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` left join `test`.`t2` on((`test`.`t2`.`i` = `test`.`t3`.`i`)) where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2840SELECT * FROM t1 WHERE (t1.i) IN
2841(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2842i
28432
28441
2845EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2846(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2847id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
28481	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
28492	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
28502	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
2851Warnings:
2852Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2853SELECT * FROM t1 WHERE (t1.i) IN
2854(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2855i
28562
28571
2858EXPLAIN SELECT * FROM t1 WHERE (11) IN
2859(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2860id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
28611	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
28622	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2863Warnings:
2864Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2865SELECT * FROM t1 WHERE (11) IN
2866(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2867i
2868EXPLAIN SELECT * FROM t1 WHERE (11) IN
2869(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2870id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
28711	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
28722	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2873Warnings:
2874Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2875Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t3` where 0))
2876SELECT * FROM t1 WHERE (11) IN
2877(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2878i
2879EXPLAIN SELECT * FROM t1 WHERE (11) IN
2880(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2881id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
28821	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
28832	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
28842	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
2885Warnings:
2886Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2887SELECT * FROM t1 WHERE (11) IN
2888(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2889i
2890EXPLAIN SELECT * FROM t1 WHERE (11) IN
2891(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2892id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
28931	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
28942	SUBQUERY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
28952	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
2896Warnings:
2897Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2898SELECT * FROM t1 WHERE (11) IN
2899(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2900i
2901INSERT INTO t3 VALUES (0);
2902DELETE FROM t3;
2903INSERT INTO t2 VALUES (1);
2904SELECT (SELECT COUNT(*) from t1) AS c1,
2905(SELECT COUNT(*) from t2) AS c2,
2906(SELECT COUNT(*) from t3) AS c3;
2907c1	c2	c3
29082	2	0
2909EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2910(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2911id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29121	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
29132	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2914Warnings:
2915Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` join `test`.`t3` where multiple equal(`test`.`t2`.`i`, NULL) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2916SELECT * FROM t1 WHERE (t1.i) IN
2917(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
2918i
2919PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2920(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
2921EXECUTE stmt;
2922i
2923EXECUTE stmt;
2924i
2925DEALLOCATE PREPARE stmt;
2926EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2927(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2928id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29291	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
29302	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2931Warnings:
2932Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t2` join `test`.`t3` where multiple equal(`test`.`t2`.`i`, NULL) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2933SELECT * FROM t1 WHERE (t1.i) IN
2934(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2935i
2936PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
2937(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
2938EXECUTE stmt;
2939i
2940EXECUTE stmt;
2941i
2942DEALLOCATE PREPARE stmt;
2943EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2944(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2945id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29461	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
29472	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2948Warnings:
2949Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select NULL from `test`.`t3` left join `test`.`t2` on(multiple equal(`test`.`t2`.`i`, NULL)) where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2950SELECT * FROM t1 WHERE (t1.i) IN
2951(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2952i
2953EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
2954(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2955id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29561	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
29572	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
29582	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	0	0.00	Using join buffer (Block Nested Loop)
2959Warnings:
2960Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
2961SELECT * FROM t1 WHERE (t1.i) IN
2962(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2963i
2964EXPLAIN SELECT * FROM t1 WHERE (11) IN
2965(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2966id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29671	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
29682	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2969Warnings:
2970Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2971SELECT * FROM t1 WHERE (11) IN
2972(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
2973i
2974EXPLAIN SELECT * FROM t1 WHERE (11) IN
2975(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2976id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29771	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
29782	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2979Warnings:
2980Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
2981Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where (`test`.`t1`.`i` and multiple equal(<cache>(11), NULL, `test`.`t2`.`i`))))
2982SELECT * FROM t1 WHERE (11) IN
2983(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
2984i
2985EXPLAIN SELECT * FROM t1 WHERE (11) IN
2986(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2987id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29881	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
29892	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
2990Warnings:
2991Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
2992SELECT * FROM t1 WHERE (11) IN
2993(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
2994i
2995EXPLAIN SELECT * FROM t1 WHERE (11) IN
2996(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
2997id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29981	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
29992	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
30002	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	0	0.00	Using where; Using join buffer (Block Nested Loop)
3001Warnings:
3002Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
3003SELECT * FROM t1 WHERE (11) IN
3004(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3005i
3006INSERT INTO t3 VALUES (2);
3007SELECT (SELECT COUNT(*) from t1) AS c1,
3008(SELECT COUNT(*) from t2) AS c2,
3009(SELECT COUNT(*) from t3) AS c3;
3010c1	c2	c3
30112	2	1
3012EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
3013(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
3014id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30151	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
30162	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
30172	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
3018Warnings:
3019Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where (`test`.`t2`.`i` = '2') ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
3020SELECT * FROM t1 WHERE (t1.i) IN
3021(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
3022i
30232
3024PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
3025(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
3026EXECUTE stmt;
3027i
30282
3029EXECUTE stmt;
3030i
30312
3032DEALLOCATE PREPARE stmt;
3033EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
3034(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
3035id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30361	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
30372	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
30382	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
3039Warnings:
3040Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where (`test`.`t2`.`i` = '2') ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
3041SELECT * FROM t1 WHERE (t1.i) IN
3042(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
3043i
30442
3045PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
3046(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
3047EXECUTE stmt;
3048i
30492
3050EXECUTE stmt;
3051i
30522
3053DEALLOCATE PREPARE stmt;
3054EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
3055(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
3056id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30571	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
30582	SUBQUERY	t3	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
30592	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
3060Warnings:
3061Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select '2' from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
3062SELECT * FROM t1 WHERE (t1.i) IN
3063(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
3064i
30652
3066EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
3067(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3068id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30691	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
30702	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
30712	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using join buffer (Block Nested Loop)
3072Warnings:
3073Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
3074SELECT * FROM t1 WHERE (t1.i) IN
3075(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3076i
30772
3078EXPLAIN SELECT * FROM t1 WHERE (11) IN
3079(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
3080id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30811	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
30822	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
3083Warnings:
3084Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
3085SELECT * FROM t1 WHERE (11) IN
3086(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
3087i
3088EXPLAIN SELECT * FROM t1 WHERE (11) IN
3089(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
3090id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30911	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
30922	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
3093Warnings:
3094Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
3095Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` where 0))
3096SELECT * FROM t1 WHERE (11) IN
3097(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
3098i
3099EXPLAIN SELECT * FROM t1 WHERE (11) IN
3100(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
3101id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
31021	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
31032	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
3104Warnings:
3105Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
3106SELECT * FROM t1 WHERE (11) IN
3107(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
3108i
3109EXPLAIN SELECT * FROM t1 WHERE (11) IN
3110(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3111id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
31121	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
31132	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
31142	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
3115Warnings:
3116Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
3117SELECT * FROM t1 WHERE (11) IN
3118(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3119i
3120INSERT INTO t3 VALUES (1);
3121SELECT (SELECT COUNT(*) from t1) AS c1,
3122(SELECT COUNT(*) from t2) AS c2,
3123(SELECT COUNT(*) from t3) AS c3;
3124c1	c2	c3
31252	2	2
3126EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
3127(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
3128id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
31291	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
31302	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
31312	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
3132Warnings:
3133Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where (`test`.`t3`.`i` = `test`.`t2`.`i`) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
3134SELECT * FROM t1 WHERE (t1.i) IN
3135(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i);
3136i
31372
31381
3139PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
3140(SELECT t3.i FROM t2 INNER JOIN t3 ON t2.i=t3.i)";
3141EXECUTE stmt;
3142i
31432
31441
3145EXECUTE stmt;
3146i
31472
31481
3149DEALLOCATE PREPARE stmt;
3150EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
3151(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
3152id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
31531	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
31542	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
31552	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
3156Warnings:
3157Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` join `test`.`t3` where (`test`.`t3`.`i` = `test`.`t2`.`i`) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
3158SELECT * FROM t1 WHERE (t1.i) IN
3159(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
3160i
31612
31621
3163PREPARE stmt FROM "SELECT * FROM t1 WHERE (t1.i) IN
3164(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i)";
3165EXECUTE stmt;
3166i
31672
31681
3169EXECUTE stmt;
3170i
31712
31721
3173DEALLOCATE PREPARE stmt;
3174EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
3175(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
3176id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
31771	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
31782	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
31792	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
3180Warnings:
3181Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` left join `test`.`t2` on((`test`.`t2`.`i` = `test`.`t3`.`i`)) where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
3182SELECT * FROM t1 WHERE (t1.i) IN
3183(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
3184i
31852
31861
3187EXPLAIN SELECT * FROM t1 WHERE (t1.i) IN
3188(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3189id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
31901	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
31912	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
31922	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (Block Nested Loop)
3193Warnings:
3194Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t2` straight_join `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
3195SELECT * FROM t1 WHERE (t1.i) IN
3196(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3197i
31982
31991
3200EXPLAIN SELECT * FROM t1 WHERE (11) IN
3201(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
3202id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
32031	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
32042	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
32052	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
3206Warnings:
3207Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
3208SELECT * FROM t1 WHERE (11) IN
3209(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
3210i
3211EXPLAIN SELECT * FROM t1 WHERE (11) IN
3212(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
3213id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
32141	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
32152	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
32162	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
3217Warnings:
3218Note	1276	Field or reference 'test.t1.i' of SELECT #2 was resolved in SELECT #1
3219Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(11,<exists>(/* select#2 */ select 1 from `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`i` = <cache>(11)) and (`test`.`t3`.`i` = <cache>(11)) and `test`.`t1`.`i`)))
3220SELECT * FROM t1 WHERE (11) IN
3221(SELECT t3.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i WHERE t1.i);
3222i
3223EXPLAIN SELECT * FROM t1 WHERE (11) IN
3224(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
3225id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
32261	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
32272	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
32282	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
3229Warnings:
3230Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
3231SELECT * FROM t1 WHERE (11) IN
3232(SELECT t3.i FROM t2 RIGHT JOIN t3 ON t2.i=t3.i);
3233i
3234EXPLAIN SELECT * FROM t1 WHERE (11) IN
3235(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3236id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
32371	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
32382	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
32392	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
3240Warnings:
3241Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where 0
3242SELECT * FROM t1 WHERE (11) IN
3243(SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
3244i
3245INSERT INTO t3 VALUES (0);
3246DELETE FROM t3;
3247INSERT INTO t2 VALUES (0);
3248DELETE FROM t2;
3249INSERT INTO t1 VALUES (0);
3250DROP TABLE t1, t2, t3;
3251create table x1(k int primary key, d1 int, d2 int);
3252create table x2(k int primary key, d1 int, d2 int);
3253insert into x1 values
3254(10,   10,   10),
3255(20,   20,   20),
3256(21,   20,   null),
3257(30,   null, 30),
3258(40,   40,   40);
3259insert into x2 values
3260(10,   10,   10),
3261(20,   20,   20),
3262(21,   20,   null),
3263(30,   null, 30);
3264select *
3265from x1
3266where (d1, d2) in (select d1, d2
3267from x2);
3268k	d1	d2
326910	10	10
327020	20	20
3271select *
3272from x1
3273where (d1, d2) in (select d1, d2
3274from x2) is true;
3275k	d1	d2
327610	10	10
327720	20	20
3278select *
3279from x1
3280where (d1, d2) in (select d1, d2
3281from x2) is false;
3282k	d1	d2
328340	40	40
3284select *
3285from x1
3286where (d1, d2) in (select d1, d2
3287from x2) is unknown;
3288k	d1	d2
328921	20	NULL
329030	NULL	30
3291select *
3292from x1
3293where d1 in (select d1
3294from x2
3295where x1.d2=x2.d2);
3296k	d1	d2
329710	10	10
329820	20	20
3299select *
3300from x1
3301where d1 in (select d1
3302from x2
3303where x1.d2=x2.d2) is true;
3304k	d1	d2
330510	10	10
330620	20	20
3307select *
3308from x1
3309where d1 in (select d1
3310from x2
3311where x1.d2=x2.d2) is false;
3312k	d1	d2
331321	20	NULL
331440	40	40
3315select *
3316from x1
3317where d1 in (select d1
3318from x2
3319where x1.d2=x2.d2) is unknown;
3320k	d1	d2
332130	NULL	30
3322select *
3323from x1
3324where 1 in (select 1
3325from x2
3326where x1.d1=x2.d1 and x1.d2=x2.d2);
3327k	d1	d2
332810	10	10
332920	20	20
3330select *
3331from x1
3332where 1 in (select 1
3333from x2
3334where x1.d1=x2.d1 and x1.d2=x2.d2) is true;
3335k	d1	d2
333610	10	10
333720	20	20
3338select *
3339from x1
3340where 1 in (select 1
3341from x2
3342where x1.d1=x2.d1 and x1.d2=x2.d2) is false;
3343k	d1	d2
334421	20	NULL
334530	NULL	30
334640	40	40
3347select *
3348from x1
3349where 1 in (select 1
3350from x2
3351where x1.d1=x2.d1 and x1.d2=x2.d2) is unknown;
3352k	d1	d2
3353select *
3354from x1
3355where exists (select *
3356from x2
3357where x1.d1=x2.d1 and x1.d2=x2.d2);
3358k	d1	d2
335910	10	10
336020	20	20
3361drop table x1;
3362drop table x2;
3363CREATE TABLE t1 (
3364a int(11) NOT NULL,
3365b int(11) NOT NULL,
3366c datetime default NULL,
3367PRIMARY KEY  (a),
3368KEY idx_bc (b,c)
3369);
3370INSERT INTO t1 VALUES
3371(406989,67,'2006-02-23 17:08:46'), (150078,67,'2005-10-26 11:17:45'),
3372(406993,67,'2006-02-27 11:20:57'), (245655,67,'2005-12-08 15:59:08'),
3373(406994,67,'2006-02-27 11:26:46'), (256,67,NULL),
3374(398341,67,'2006-02-20 04:48:44'), (254,67,NULL),(1120,67,NULL),
3375(406988,67,'2006-02-23 17:07:22'), (255,67,NULL),
3376(398340,67,'2006-02-20 04:38:53'),(406631,67,'2006-02-23 10:49:42'),
3377(245653,67,'2005-12-08 15:59:07'),(406992,67,'2006-02-24 16:47:18'),
3378(245654,67,'2005-12-08 15:59:08'),(406995,67,'2006-02-28 11:55:00'),
3379(127261,67,'2005-10-13 12:17:58'),(406991,67,'2006-02-24 16:42:32'),
3380(245652,67,'2005-12-08 15:58:27'),(398545,67,'2006-02-20 04:53:13'),
3381(154504,67,'2005-10-28 11:53:01'),(9199,67,NULL),(1,67,'2006-02-23 15:01:35'),
3382(223456,67,NULL),(4101,67,NULL),(1133,67,NULL),
3383(406990,67,'2006-02-23 18:01:45'),(148815,67,'2005-10-25 15:34:17'),
3384(148812,67,'2005-10-25 15:30:01'),(245651,67,'2005-12-08 15:58:27'),
3385(154503,67,'2005-10-28 11:52:38');
3386create table t11 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc;
3387create table t12 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc;
3388create table t21 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 asc;
3389create table t22 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc;
3390update t22 set c = '2005-12-08 15:58:27' where a = 255;
3391explain select t21.* from t21,t22 where t21.a = t22.a and
3392t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a;
3393id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
33941	PRIMARY	t22	NULL	ALL	NULL	NULL	NULL	NULL	26	10.00	Using where; Using temporary; Using filesort
33951	PRIMARY	t21	NULL	ALL	NULL	NULL	NULL	NULL	26	10.00	Using where; Using join buffer (Block Nested Loop)
33962	SUBQUERY	t11	NULL	ALL	NULL	NULL	NULL	NULL	8	12.50	Using where
33972	SUBQUERY	t12	NULL	ALL	NULL	NULL	NULL	NULL	8	12.50	Using where; Using join buffer (Block Nested Loop)
3398Warnings:
3399Note	1003	/* select#1 */ select `test`.`t21`.`a` AS `a`,`test`.`t21`.`b` AS `b`,`test`.`t21`.`c` AS `c` from `test`.`t21` join `test`.`t22` where ((`test`.`t21`.`a` = `test`.`t22`.`a`) and <in_optimizer>(`test`.`t22`.`a`,`test`.`t22`.`a` in ( <materialize> (/* select#2 */ select `test`.`t12`.`a` from `test`.`t11` join `test`.`t12` where ((`test`.`t12`.`a` = `test`.`t11`.`a`) and (`test`.`t11`.`a` in (255,256)) and isnull(`test`.`t11`.`c`)) ), <primary_index_lookup>(`test`.`t22`.`a` in <temporary table> on <auto_key> where ((`test`.`t22`.`a` = `materialized-subquery`.`a`))))) and isnull(`test`.`t22`.`c`)) order by `test`.`t21`.`a`
3400explain format=json select * from t1 where a in (select a from t11);
3401EXPLAIN
3402{
3403  "query_block": {
3404    "select_id": 1,
3405    "cost_info": {
3406      "query_cost": "8.51"
3407    },
3408    "table": {
3409      "table_name": "t1",
3410      "access_type": "ALL",
3411      "rows_examined_per_scan": 32,
3412      "rows_produced_per_join": 32,
3413      "filtered": "100.00",
3414      "cost_info": {
3415        "read_cost": "2.11",
3416        "eval_cost": "6.40",
3417        "prefix_cost": "8.51",
3418        "data_read_per_join": "512"
3419      },
3420      "used_columns": [
3421        "a",
3422        "b",
3423        "c"
3424      ],
3425      "attached_condition": "<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t11`.`a` from `test`.`t11` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))",
3426      "attached_subqueries": [
3427        {
3428          "table": {
3429            "table_name": "<materialized_subquery>",
3430            "access_type": "eq_ref",
3431            "key": "<auto_key>",
3432            "key_length": "4",
3433            "rows_examined_per_scan": 1,
3434            "materialized_from_subquery": {
3435              "using_temporary_table": true,
3436              "dependent": true,
3437              "cacheable": false,
3438              "query_block": {
3439                "select_id": 2,
3440                "cost_info": {
3441                  "query_cost": "3.63"
3442                },
3443                "table": {
3444                  "table_name": "t11",
3445                  "access_type": "ALL",
3446                  "rows_examined_per_scan": 8,
3447                  "rows_produced_per_join": 8,
3448                  "filtered": "100.00",
3449                  "cost_info": {
3450                    "read_cost": "2.03",
3451                    "eval_cost": "1.60",
3452                    "prefix_cost": "3.63",
3453                    "data_read_per_join": "128"
3454                  },
3455                  "used_columns": [
3456                    "a"
3457                  ]
3458                }
3459              }
3460            }
3461          }
3462        }
3463      ]
3464    }
3465  }
3466}
3467Warnings:
3468Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t11`.`a` from `test`.`t11` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
3469select t21.* from t21,t22 where t21.a = t22.a and
3470t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a;
3471a	b	c
3472256	67	NULL
3473drop table t1, t11, t12, t21, t22;
3474create table t1(a int);
3475insert into t1 values (0),(1);
3476explain
3477select (select max(y.a) from t1 y where a in (select a from t1 z) and a < x.a) as subq from t1 x;
3478id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
34791	PRIMARY	x	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
34802	DEPENDENT SUBQUERY	y	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
34813	SUBQUERY	z	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
3482Warnings:
3483Note	1276	Field or reference 'test.x.a' of SELECT #2 was resolved in SELECT #1
3484Note	1003	/* select#1 */ select (/* select#2 */ select max(`test`.`y`.`a`) from `test`.`t1` `y` where (<in_optimizer>(`test`.`y`.`a`,`test`.`y`.`a` in ( <materialize> (/* select#3 */ select `test`.`z`.`a` from `test`.`t1` `z` where 1 ), <primary_index_lookup>(`test`.`y`.`a` in <temporary table> on <auto_key> where ((`test`.`y`.`a` = `materialized-subquery`.`a`))))) and (`test`.`y`.`a` < `test`.`x`.`a`))) AS `subq` from `test`.`t1` `x`
3485select (select max(y.a) from t1 y where a in (select a from t1 z) and a < x.a) as subq from t1 x;
3486subq
3487NULL
34880
3489drop table t1;
3490create table t0 (a int);
3491insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3492create table t1 as select * from t0;
3493insert into t1 select a+10 from t0;
3494insert into t0 values(2);
3495explain select * from t1 where 2 in (select a from t0);
3496id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
34971	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	NULL
34982	SUBQUERY	t0	NULL	ALL	NULL	NULL	NULL	NULL	11	10.00	Using where
3499Warnings:
3500Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1
3501select * from t1 where 2 in (select a from t0);
3502a
35030
35041
35052
35063
35074
35085
35096
35107
35118
35129
351310
351411
351512
351613
351714
351815
351916
352017
352118
352219
3523explain select * from (select a from t0) x where a in (select a from t1);
3524id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
35251	PRIMARY	t0	NULL	ALL	NULL	NULL	NULL	NULL	11	100.00	Using where
35263	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	NULL
3527Warnings:
3528Note	1003	/* select#1 */ select `test`.`t0`.`a` AS `a` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`a`,`test`.`t0`.`a` in ( <materialize> (/* select#3 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t0`.`a` in <temporary table> on <auto_key> where ((`test`.`t0`.`a` = `materialized-subquery`.`a`)))))
3529explain format=json select * from (select a from t0) x where a in (select a from t1);
3530EXPLAIN
3531{
3532  "query_block": {
3533    "select_id": 1,
3534    "cost_info": {
3535      "query_cost": "4.22"
3536    },
3537    "table": {
3538      "table_name": "t0",
3539      "access_type": "ALL",
3540      "rows_examined_per_scan": 11,
3541      "rows_produced_per_join": 11,
3542      "filtered": "100.00",
3543      "cost_info": {
3544        "read_cost": "2.02",
3545        "eval_cost": "2.20",
3546        "prefix_cost": "4.22",
3547        "data_read_per_join": "88"
3548      },
3549      "used_columns": [
3550        "a"
3551      ],
3552      "attached_condition": "<in_optimizer>(`test`.`t0`.`a`,`test`.`t0`.`a` in ( <materialize> (/* select#3 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t0`.`a` in <temporary table> on <auto_key> where ((`test`.`t0`.`a` = `materialized-subquery`.`a`)))))",
3553      "attached_subqueries": [
3554        {
3555          "table": {
3556            "table_name": "<materialized_subquery>",
3557            "access_type": "eq_ref",
3558            "key": "<auto_key>",
3559            "key_length": "5",
3560            "rows_examined_per_scan": 1,
3561            "materialized_from_subquery": {
3562              "using_temporary_table": true,
3563              "dependent": true,
3564              "cacheable": false,
3565              "query_block": {
3566                "select_id": 3,
3567                "cost_info": {
3568                  "query_cost": "6.03"
3569                },
3570                "table": {
3571                  "table_name": "t1",
3572                  "access_type": "ALL",
3573                  "rows_examined_per_scan": 20,
3574                  "rows_produced_per_join": 20,
3575                  "filtered": "100.00",
3576                  "cost_info": {
3577                    "read_cost": "2.03",
3578                    "eval_cost": "4.00",
3579                    "prefix_cost": "6.03",
3580                    "data_read_per_join": "160"
3581                  },
3582                  "used_columns": [
3583                    "a"
3584                  ]
3585                }
3586              }
3587            }
3588          }
3589        }
3590      ]
3591    }
3592  }
3593}
3594Warnings:
3595Note	1003	/* select#1 */ select `test`.`t0`.`a` AS `a` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`a`,`test`.`t0`.`a` in ( <materialize> (/* select#3 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t0`.`a` in <temporary table> on <auto_key> where ((`test`.`t0`.`a` = `materialized-subquery`.`a`)))))
3596drop table t0, t1;
3597create table t0 (a int);
3598insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3599create table t1 (kp1 int, kp2 int, c int, filler char(100), key(kp1, kp2));
3600insert into t1 select A.a+10*(B.a+10*C.a), 0, 0, 'filler' from t0 A, t0 B, t0 C;
3601insert into t1 select * from t1 where kp1 < 20;
3602create table t3 (a int);
3603insert into t3 select A.a + 10*B.a from t0 A, t0 B;
3604explain select * from t3 where a in (select kp1 from t1 where kp1<20);
3605id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
36061	PRIMARY	t3	NULL	ALL	NULL	NULL	NULL	NULL	100	100.00	Using where
36072	SUBQUERY	t1	NULL	range	kp1	kp1	5	NULL	48	100.00	Using where; Using index
3608Warnings:
3609Note	1003	/* select#1 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`kp1` from `test`.`t1` where (`test`.`t1`.`kp1` < 20) ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`kp1`)))))
3610select * from t3 where a in (select kp1 from t1 where kp1<20);
3611a
36120
36131
36142
36153
36164
36175
36186
36197
36208
36219
362210
362311
362412
362513
362614
362715
362816
362917
363018
363119
3632explain select * from t3 where a in (select kp1 from t1 where kp1<20) and a<20;
3633id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
36341	PRIMARY	t3	NULL	ALL	NULL	NULL	NULL	NULL	100	33.33	Using where
36352	SUBQUERY	t1	NULL	range	kp1	kp1	5	NULL	48	100.00	Using where; Using index
3636Warnings:
3637Note	1003	/* select#1 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where (<in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`kp1` from `test`.`t1` where (`test`.`t1`.`kp1` < 20) ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`kp1`))))) and (`test`.`t3`.`a` < 20))
3638select * from t3 where a in (select kp1 from t1 where kp1<20) and a<20;
3639a
36400
36411
36422
36433
36444
36455
36466
36477
36488
36499
365010
365111
365212
365313
365414
365515
365616
365717
365818
365919
3660create table t4 (pk int primary key);
3661insert into t4 select a from t3;
3662explain select * from t3 where a in
3663(select t1.kp1 from t1,t4 where kp1<20 and t4.pk=t1.c);
3664id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
36651	PRIMARY	t3	NULL	ALL	NULL	NULL	NULL	NULL	100	100.00	Using where
36662	SUBQUERY	t1	NULL	range	kp1	kp1	5	NULL	48	100.00	Using where
36672	SUBQUERY	t4	NULL	eq_ref	PRIMARY	PRIMARY	4	test.t1.c	1	100.00	Using index
3668Warnings:
3669Note	1003	/* select#1 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`kp1` from `test`.`t1` join `test`.`t4` where ((`test`.`t4`.`pk` = `test`.`t1`.`c`) and (`test`.`t1`.`kp1` < 20)) ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`kp1`)))))
3670select * from t3 where a in
3671(select t1.kp1 from t1,t4 where kp1<20 and t4.pk=t1.c);
3672a
36730
36741
36752
36763
36774
36785
36796
36807
36818
36829
368310
368411
368512
368613
368714
368815
368916
369017
369118
369219
3693drop table t1, t3, t4;
3694create table t1 (a int);
3695insert into t1 values (0),(0),(0),(1),(1),(1),(2),(2),(2),(3),(3),(3);
3696set @save_max_heap_table_size=@@max_heap_table_size;
3697set @@max_heap_table_size= 16384;
3698# Attempt to make one test that overflows the heap table when a
3699# non-duplicate row is inserted and one test that overflows the
3700# heap table when a duplicate record is inserted. Debugging showed
3701# that these situations occurred with max_heap_table_size=16384
3702# and optimizer_join_cache_level equals 1 and 0, respectively.
3703# Finally execute a test that does not overflow the heap table.
3704explain
3705select count(*) from t0 a, t0 b, t0 c
3706where c.a in (select a from t1 d);
3707id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
37081	PRIMARY	a	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
37091	PRIMARY	b	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using join buffer (Block Nested Loop)
37101	PRIMARY	c	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where; Using join buffer (Block Nested Loop)
37112	SUBQUERY	d	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	NULL
3712Warnings:
3713Note	1003	/* select#1 */ select count(0) AS `count(*)` from `test`.`t0` `a` join `test`.`t0` `b` join `test`.`t0` `c` where <in_optimizer>(`test`.`c`.`a`,`test`.`c`.`a` in ( <materialize> (/* select#2 */ select `test`.`d`.`a` from `test`.`t1` `d` where 1 ), <primary_index_lookup>(`test`.`c`.`a` in <temporary table> on <auto_key> where ((`test`.`c`.`a` = `materialized-subquery`.`a`)))))
3714flush status;
3715select count(*) from t0 a, t0 b, t0 c
3716where c.a in (select a from t1 d);
3717count(*)
3718400
3719show status like 'Created_tmp_disk_tables';
3720Variable_name	Value
3721Created_tmp_disk_tables	0
3722set @@max_heap_table_size= @save_max_heap_table_size;
3723flush status;
3724select count(*) from t0 a, t0 b, t0 c
3725where c.a in (select a from t1 d);
3726count(*)
3727400
3728show status like 'Created_tmp_disk_tables';
3729Variable_name	Value
3730Created_tmp_disk_tables	0
3731drop table t0, t1;
3732create table t0 (a int);
3733insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3734create table t2(a int);
3735insert into t2 values (1),(2);
3736create table t3 ( a int , filler char(100), key(a));
3737insert into t3 select A.a + 10*B.a, 'filler' from t0 A, t0 B;
3738explain select * from t3 where a in (select a from t2) and (a > 5 or a < 10);
3739id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
37401	PRIMARY	t3	NULL	ALL	a	NULL	NULL	NULL	100	100.00	Using where
37412	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
3742Warnings:
3743Note	1003	/* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`filler` AS `filler` from `test`.`t3` where (<in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`a`))))) and ((`test`.`t3`.`a` > 5) or (`test`.`t3`.`a` < 10)))
3744select * from t3 where a in (select a from t2);
3745a	filler
37461	filler
37472	filler
3748drop table t0, t2, t3;
3749create table t1 (a date);
3750insert into t1 values ('2008-01-01'),('2008-01-01'),('2008-02-01'),('2008-02-01');
3751create table t2 (a int);
3752insert into t2 values (1),(2);
3753create table t3 (a char(10));
3754insert into t3 select * from t1;
3755insert into t3 values (1),(2);
3756explain select * from t2 where a in (select a from t1);
3757id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
37581	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
37592	DEPENDENT SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	25.00	Using where
3760Warnings:
3761Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))
3762explain select * from t2 where a in (select a from t2);
3763id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
37641	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
37652	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
3766Warnings:
3767Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
3768explain select * from t2 where a in (select a from t3);
3769id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
37701	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
37712	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
3772Warnings:
3773Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select 1 from `test`.`t3` where (<cache>(`test`.`t2`.`a`) = `test`.`t3`.`a`)))
3774explain select * from t1 where a in (select a from t3);
3775id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
37761	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
37772	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
3778Warnings:
3779Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select 1 from `test`.`t3` where (<cache>(`test`.`t1`.`a`) = `test`.`t3`.`a`)))
3780drop table t1, t2, t3;
3781create table t1 (a decimal);
3782insert into t1 values (1),(2);
3783explain select * from t1 where a in (select a from t1);
3784id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
37851	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
37862	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
3787Warnings:
3788Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
3789drop table t1;
3790create table t1 (a int);
3791insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3792create table t2 as select * from t1;
3793create table t3 (a int, b int, filler char(100), key(a));
3794insert into t3 select A.a + 10*B.a, A.a + 10*B.a, 'filler' from t1 A, t1 B, t1 C;
3795explain select * from t1, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30) and t1.a =3;
3796id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
37971	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	10	10.00	Using where
37981	PRIMARY	t3	NULL	ALL	a	NULL	NULL	NULL	1000	79.30	Using where; Using join buffer (Block Nested Loop)
37992	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
3800Warnings:
3801Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`filler` AS `filler` from `test`.`t1` join `test`.`t3` where ((`test`.`t1`.`a` = 3) and <in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`a`))))) and ((`test`.`t3`.`a` < 10) or (`test`.`t3`.`a` > 30)))
3802explain format=json select * from t1, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30) and t1.a =3;
3803EXPLAIN
3804{
3805  "query_block": {
3806    "select_id": 1,
3807    "cost_info": {
3808      "query_cost": "232.63"
3809    },
3810    "nested_loop": [
3811      {
3812        "table": {
3813          "table_name": "t1",
3814          "access_type": "ALL",
3815          "rows_examined_per_scan": 10,
3816          "rows_produced_per_join": 1,
3817          "filtered": "10.00",
3818          "cost_info": {
3819            "read_cost": "3.82",
3820            "eval_cost": "0.20",
3821            "prefix_cost": "4.02",
3822            "data_read_per_join": "8"
3823          },
3824          "used_columns": [
3825            "a"
3826          ],
3827          "attached_condition": "(`test`.`t1`.`a` = 3)"
3828        }
3829      },
3830      {
3831        "table": {
3832          "table_name": "t3",
3833          "access_type": "ALL",
3834          "possible_keys": [
3835            "a"
3836          ],
3837          "rows_examined_per_scan": 1000,
3838          "rows_produced_per_join": 793,
3839          "filtered": "79.30",
3840          "using_join_buffer": "Block Nested Loop",
3841          "cost_info": {
3842            "read_cost": "70.01",
3843            "eval_cost": "158.60",
3844            "prefix_cost": "232.63",
3845            "data_read_per_join": "86K"
3846          },
3847          "used_columns": [
3848            "a",
3849            "b",
3850            "filler"
3851          ],
3852          "attached_condition": "(<in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`a`))))) and ((`test`.`t3`.`a` < 10) or (`test`.`t3`.`a` > 30)))",
3853          "attached_subqueries": [
3854            {
3855              "table": {
3856                "table_name": "<materialized_subquery>",
3857                "access_type": "eq_ref",
3858                "key": "<auto_key>",
3859                "key_length": "5",
3860                "rows_examined_per_scan": 1,
3861                "materialized_from_subquery": {
3862                  "using_temporary_table": true,
3863                  "dependent": true,
3864                  "cacheable": false,
3865                  "query_block": {
3866                    "select_id": 2,
3867                    "cost_info": {
3868                      "query_cost": "4.02"
3869                    },
3870                    "table": {
3871                      "table_name": "t2",
3872                      "access_type": "ALL",
3873                      "rows_examined_per_scan": 10,
3874                      "rows_produced_per_join": 10,
3875                      "filtered": "100.00",
3876                      "cost_info": {
3877                        "read_cost": "2.02",
3878                        "eval_cost": "2.00",
3879                        "prefix_cost": "4.02",
3880                        "data_read_per_join": "80"
3881                      },
3882                      "used_columns": [
3883                        "a"
3884                      ]
3885                    }
3886                  }
3887                }
3888              }
3889            }
3890          ]
3891        }
3892      }
3893    ]
3894  }
3895}
3896Warnings:
3897Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`filler` AS `filler` from `test`.`t1` join `test`.`t3` where ((`test`.`t1`.`a` = 3) and <in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`a`))))) and ((`test`.`t3`.`a` < 10) or (`test`.`t3`.`a` > 30)))
3898explain select straight_join * from t1 a, t1 b where a.a in (select a from t2);
3899id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39001	PRIMARY	a	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
39011	PRIMARY	b	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using join buffer (Block Nested Loop)
39022	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
3903Warnings:
3904Note	1003	/* select#1 */ select straight_join `test`.`a`.`a` AS `a`,`test`.`b`.`a` AS `a` from `test`.`t1` `a` join `test`.`t1` `b` where <in_optimizer>(`test`.`a`.`a`,`test`.`a`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`a`.`a` in <temporary table> on <auto_key> where ((`test`.`a`.`a` = `materialized-subquery`.`a`)))))
3905explain select * from t2 where a in (select straight_join a.a from t1 a, t1 b);
3906id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39071	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
39082	SUBQUERY	a	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
39092	SUBQUERY	b	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using join buffer (Block Nested Loop)
3910Warnings:
3911Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select straight_join `test`.`a`.`a` from `test`.`t1` `a` join `test`.`t1` `b` where 1 ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
3912explain select * from t2 where a in (select straight_join a.a from t1 a, t1 b);
3913id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39141	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
39152	SUBQUERY	a	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
39162	SUBQUERY	b	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using join buffer (Block Nested Loop)
3917Warnings:
3918Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select straight_join `test`.`a`.`a` from `test`.`t1` `a` join `test`.`t1` `b` where 1 ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
3919explain select straight_join * from t2 x, t2 y
3920where x.a in (select straight_join a.a from t1 a, t1 b);
3921id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39221	PRIMARY	x	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
39231	PRIMARY	y	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using join buffer (Block Nested Loop)
39242	SUBQUERY	a	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
39252	SUBQUERY	b	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using join buffer (Block Nested Loop)
3926Warnings:
3927Note	1003	/* select#1 */ select straight_join `test`.`x`.`a` AS `a`,`test`.`y`.`a` AS `a` from `test`.`t2` `x` join `test`.`t2` `y` where <in_optimizer>(`test`.`x`.`a`,`test`.`x`.`a` in ( <materialize> (/* select#2 */ select straight_join `test`.`a`.`a` from `test`.`t1` `a` join `test`.`t1` `b` where 1 ), <primary_index_lookup>(`test`.`x`.`a` in <temporary table> on <auto_key> where ((`test`.`x`.`a` = `materialized-subquery`.`a`)))))
3928create table t0 (a int, b int);
3929insert into t0 values(1,1);
3930explain select * from t0, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30);
3931id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39321	PRIMARY	t0	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
39331	PRIMARY	t3	NULL	ALL	a	NULL	NULL	NULL	1000	79.30	Using where
39342	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
3935Warnings:
3936Note	1003	/* select#1 */ select '1' AS `a`,'1' AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`filler` AS `filler` from `test`.`t3` where (<in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`a`))))) and ((`test`.`t3`.`a` < 10) or (`test`.`t3`.`a` > 30)))
3937create table t4 as select a as x, a as y from t1;
3938explain select * from t0, t3 where (t3.a, t3.b) in (select x,y from t4) and (t3.a < 10 or t3.a >30);
3939id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39401	PRIMARY	t0	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
39411	PRIMARY	t3	NULL	ALL	a	NULL	NULL	NULL	1000	79.30	Using where
39422	SUBQUERY	t4	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
3943Warnings:
3944Note	1003	/* select#1 */ select '1' AS `a`,'1' AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`filler` AS `filler` from `test`.`t3` where (<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`b`),(`test`.`t3`.`a`,`test`.`t3`.`b`) in ( <materialize> (/* select#2 */ select `test`.`t4`.`x`,`test`.`t4`.`y` from `test`.`t4` where 1 ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`x`) and (`test`.`t3`.`b` = `materialized-subquery`.`y`))))) and ((`test`.`t3`.`a` < 10) or (`test`.`t3`.`a` > 30)))
3945drop table t0,t1,t2,t3,t4;
3946create table t0 (a int);
3947insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3948create table t1 (a int, b int, filler char(100), key(a,b));
3949insert into t1 select A.a, B.a, 'filler' from t0 A, t0 B;
3950create table t2 as select * from t1;
3951explain select * from t2 where a in (select b from t1 where a=3);
3952id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39531	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	100	100.00	Using where
39542	SUBQUERY	t1	NULL	ref	a	a	5	const	8	100.00	Using index
3955Warnings:
3956Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`filler` AS `filler` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`b` from `test`.`t1` where (`test`.`t1`.`a` = 3) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`b`)))))
3957explain select * from t2 where (b,a) in (select a,b from t1 where a=3);
3958id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39591	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	100	100.00	Using where
39602	SUBQUERY	t1	NULL	ref	a	a	5	const	8	100.00	Using index
3961Warnings:
3962Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`filler` AS `filler` from `test`.`t2` where <in_optimizer>((`test`.`t2`.`b`,`test`.`t2`.`a`),(`test`.`t2`.`b`,`test`.`t2`.`a`) in ( <materialize> (/* select#2 */ select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` where (`test`.`t1`.`a` = 3) ), <primary_index_lookup>(`test`.`t2`.`b` in <temporary table> on <auto_key> where ((`test`.`t2`.`b` = `materialized-subquery`.`a`) and (`test`.`t2`.`a` = `materialized-subquery`.`b`)))))
3963drop table t1,t2;
3964create table t1 (a int, b int);
3965insert into t1 select a,a from t0;
3966create table t2 (a int, b int);
3967insert into t2 select A.a + 10*B.a, A.a + 10*B.a from t0 A, t0 B;
3968explain select * from t1 where (a,b) in (select a,b from t2);
3969id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
39701	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
39712	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	100	100.00	NULL
3972Warnings:
3973Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),(`test`.`t1`.`a`,`test`.`t1`.`b`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`a`,`test`.`t2`.`b` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`) and (`test`.`t1`.`b` = `materialized-subquery`.`b`)))))
3974drop table t0, t1, t2;
3975#
3976# Bug#19695490: CRASH IN CREATE_REF_FOR_KEY ON SELECT + JOIN + UTF8 COLUMN
3977#                + DATETIME INDEX.
3978#
3979CREATE TABLE t1 (
3980field1 varchar(255) CHARACTER SET utf8,
3981field2 varchar(255) CHARACTER SET utf8
3982);
3983INSERT INTO t1 VALUES
3984('time','time'),
3985('lpjdzvkp','lpjdzvkp'),
3986('dzvkpai', 'dzvkpai');
3987CREATE TABLE t2 ( col_varchar varchar(10));
3988CREATE TABLE t3 (
3989pk int(11) NOT NULL,
3990col_varchar_255_utf8_key varchar(255) CHARACTER SET utf8,
3991col_varchar_10_utf8_key varchar(10) CHARACTER SET utf8,
3992PRIMARY KEY (pk)
3993);
3994INSERT INTO t3 VALUES (22,'come','h'),
3995(23,'time','aaa'),
3996(24,'lpjdzvkp','ababa'),
3997(25,'d','GGDD');
3998SELECT * FROM t1 WHERE (field1, field2) IN (
3999SELECT table1.col_varchar_255_utf8_key AS field1,
4000table1.col_varchar_255_utf8_key AS field2
4001FROM t3 AS table1 LEFT JOIN t2 AS table2
4002ON table1.col_varchar_10_utf8_key <=
4003table2.col_varchar
4004WHERE table1.pk >= 6);
4005field1	field2
4006time	time
4007lpjdzvkp	lpjdzvkp
4008DROP TABLE t1,t2,t3;
4009create table t0 (a decimal(4,2));
4010insert into t0 values (10.24), (22.11);
4011create table t1 as select * from t0;
4012insert into t1 select * from t0;
4013explain select * from t0 where a in (select a from t1);
4014id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
40151	PRIMARY	t0	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
40162	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
4017Warnings:
4018Note	1003	/* select#1 */ select `test`.`t0`.`a` AS `a` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`a`,`test`.`t0`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t0`.`a` in <temporary table> on <auto_key> where ((`test`.`t0`.`a` = `materialized-subquery`.`a`)))))
4019select * from t0 where a in (select a from t1);
4020a
402110.24
402222.11
4023drop table t0, t1;
4024create table t0(a date);
4025insert into t0 values ('2008-01-01'),('2008-02-02');
4026create table t1 as select * from t0;
4027insert into t1 select * from t0;
4028explain select * from t0 where a in (select a from t1);
4029id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
40301	PRIMARY	t0	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
40312	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
4032Warnings:
4033Note	1003	/* select#1 */ select `test`.`t0`.`a` AS `a` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`a`,`test`.`t0`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t0`.`a` in <temporary table> on <auto_key> where ((`test`.`t0`.`a` = `materialized-subquery`.`a`)))))
4034select * from t0 where a in (select a from t1);
4035a
40362008-01-01
40372008-02-02
4038drop table t0, t1;
4039create table t0(a int);
4040insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
4041create table t1 as select a as a, a as b, a as c from t0 where a < 3;
4042create table t2 as select a as a, a as b from t0 where a < 3;
4043insert into t2 select * from t2;
4044explain select * from t1 where (a,b,c) in (select x.a, y.a, z.a from t2 x, t2 y, t2 z where x.b=33);
4045id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
40461	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
40472	SUBQUERY	x	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
40482	SUBQUERY	y	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using join buffer (Block Nested Loop)
40492	SUBQUERY	z	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using join buffer (Block Nested Loop)
4050Warnings:
4051Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`,`test`.`t1`.`c`),(`test`.`t1`.`a`,`test`.`t1`.`b`,`test`.`t1`.`c`) in ( <materialize> (/* select#2 */ select `test`.`x`.`a`,`test`.`y`.`a`,`test`.`z`.`a` from `test`.`t2` `x` join `test`.`t2` `y` join `test`.`t2` `z` where (`test`.`x`.`b` = 33) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`) and (`test`.`t1`.`b` = `materialized-subquery`.`a`) and (`test`.`t1`.`c` = `materialized-subquery`.`a`)))))
4052drop table t0,t1,t2;
4053set @save_join_buffer_size = @@join_buffer_size;
4054set join_buffer_size= 8192;
4055create table t0 (a int);
4056insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
4057create table t1 (a int, filler1 binary(200), filler2 binary(200));
4058insert into t1 select a, 'filler123456', 'filler123456' from t0;
4059insert into t1 select a+10, 'filler123456', 'filler123456' from t0;
4060create table t2 as select * from t1;
4061insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
4062insert into t1 values (2, 'duplicate ok', 'duplicate ok');
4063insert into t1 values (18, 'duplicate ok', 'duplicate ok');
4064insert into t2 values (3, 'duplicate ok', 'duplicate ok');
4065insert into t2 values (19, 'duplicate ok', 'duplicate ok');
4066explain select
4067a, mid(filler1, 1,10), length(filler1)=length(filler2) as z
4068from t1 ot where a in (select a from t2 it);
4069id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
40701	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	32	100.00	Using where
40712	SUBQUERY	it	NULL	ALL	NULL	NULL	NULL	NULL	22	100.00	NULL
4072Warnings:
4073Note	1003	/* select#1 */ select `test`.`ot`.`a` AS `a`,substr(`test`.`ot`.`filler1`,1,10) AS `mid(filler1, 1,10)`,(length(`test`.`ot`.`filler1`) = length(`test`.`ot`.`filler2`)) AS `z` from `test`.`t1` `ot` where <in_optimizer>(`test`.`ot`.`a`,`test`.`ot`.`a` in ( <materialize> (/* select#2 */ select `test`.`it`.`a` from `test`.`t2` `it` where 1 ), <primary_index_lookup>(`test`.`ot`.`a` in <temporary table> on <auto_key> where ((`test`.`ot`.`a` = `materialized-subquery`.`a`)))))
4074select
4075a, mid(filler1, 1,10), length(filler1)=length(filler2) as z
4076from t1 ot where a in (select a from t2 it);
4077a	mid(filler1, 1,10)	z
40780	filler1234	1
40791	filler1234	1
408010	filler1234	1
408111	filler1234	1
408212	filler1234	1
408313	filler1234	1
408414	filler1234	1
408515	filler1234	1
408616	filler1234	1
408717	filler1234	1
408818	duplicate 	1
408918	filler1234	1
409019	filler1234	1
40912	duplicate 	1
40922	filler1234	1
40933	filler1234	1
40944	filler1234	1
40955	filler1234	1
40966	filler1234	1
40977	filler1234	1
40988	filler1234	1
40999	filler1234	1
4100explain select
4101a, mid(filler1, 1,10), length(filler1)=length(filler2)
4102from t2 ot where a in (select a from t1 it);
4103id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
41041	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	22	100.00	Using where
41052	SUBQUERY	it	NULL	ALL	NULL	NULL	NULL	NULL	32	100.00	NULL
4106Warnings:
4107Note	1003	/* select#1 */ select `test`.`ot`.`a` AS `a`,substr(`test`.`ot`.`filler1`,1,10) AS `mid(filler1, 1,10)`,(length(`test`.`ot`.`filler1`) = length(`test`.`ot`.`filler2`)) AS `length(filler1)=length(filler2)` from `test`.`t2` `ot` where <in_optimizer>(`test`.`ot`.`a`,`test`.`ot`.`a` in ( <materialize> (/* select#2 */ select `test`.`it`.`a` from `test`.`t1` `it` where 1 ), <primary_index_lookup>(`test`.`ot`.`a` in <temporary table> on <auto_key> where ((`test`.`ot`.`a` = `materialized-subquery`.`a`)))))
4108select
4109a, mid(filler1, 1,10), length(filler1)=length(filler2)
4110from t2 ot where a in (select a from t1 it);
4111a	mid(filler1, 1,10)	length(filler1)=length(filler2)
41120	filler1234	1
41131	filler1234	1
411410	filler1234	1
411511	filler1234	1
411612	filler1234	1
411713	filler1234	1
411814	filler1234	1
411915	filler1234	1
412016	filler1234	1
412117	filler1234	1
412218	filler1234	1
412319	duplicate 	1
412419	filler1234	1
41252	filler1234	1
41263	duplicate 	1
41273	filler1234	1
41284	filler1234	1
41295	filler1234	1
41306	filler1234	1
41317	filler1234	1
41328	filler1234	1
41339	filler1234	1
4134insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
4135insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
4136explain select
4137a, mid(filler1, 1,10), length(filler1)=length(filler2) as z
4138from t1 ot where a in (select a from t2 it);
4139id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
41401	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	52	100.00	Using where
41412	SUBQUERY	it	NULL	ALL	NULL	NULL	NULL	NULL	22	100.00	NULL
4142Warnings:
4143Note	1003	/* select#1 */ select `test`.`ot`.`a` AS `a`,substr(`test`.`ot`.`filler1`,1,10) AS `mid(filler1, 1,10)`,(length(`test`.`ot`.`filler1`) = length(`test`.`ot`.`filler2`)) AS `z` from `test`.`t1` `ot` where <in_optimizer>(`test`.`ot`.`a`,`test`.`ot`.`a` in ( <materialize> (/* select#2 */ select `test`.`it`.`a` from `test`.`t2` `it` where 1 ), <primary_index_lookup>(`test`.`ot`.`a` in <temporary table> on <auto_key> where ((`test`.`ot`.`a` = `materialized-subquery`.`a`)))))
4144select
4145a, mid(filler1, 1,10), length(filler1)=length(filler2) as z
4146from t1 ot where a in (select a from t2 it);
4147a	mid(filler1, 1,10)	z
41480	filler1234	1
41491	filler1234	1
415010	filler1234	1
415111	filler1234	1
415212	filler1234	1
415313	filler1234	1
415414	filler1234	1
415515	filler1234	1
415616	filler1234	1
415717	filler1234	1
415818	duplicate 	1
415918	filler1234	1
416019	filler1234	1
41612	duplicate 	1
41622	filler1234	1
41633	filler1234	1
41644	filler1234	1
41655	filler1234	1
41666	filler1234	1
41677	filler1234	1
41688	filler1234	1
41699	filler1234	1
4170explain select
4171a, mid(filler1, 1,10), length(filler1)=length(filler2)
4172from t2 ot where a in (select a from t1 it);
4173id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
41741	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	22	100.00	Using where
41752	SUBQUERY	it	NULL	ALL	NULL	NULL	NULL	NULL	52	100.00	NULL
4176Warnings:
4177Note	1003	/* select#1 */ select `test`.`ot`.`a` AS `a`,substr(`test`.`ot`.`filler1`,1,10) AS `mid(filler1, 1,10)`,(length(`test`.`ot`.`filler1`) = length(`test`.`ot`.`filler2`)) AS `length(filler1)=length(filler2)` from `test`.`t2` `ot` where <in_optimizer>(`test`.`ot`.`a`,`test`.`ot`.`a` in ( <materialize> (/* select#2 */ select `test`.`it`.`a` from `test`.`t1` `it` where 1 ), <primary_index_lookup>(`test`.`ot`.`a` in <temporary table> on <auto_key> where ((`test`.`ot`.`a` = `materialized-subquery`.`a`)))))
4178select
4179a, mid(filler1, 1,10), length(filler1)=length(filler2)
4180from t2 ot where a in (select a from t1 it);
4181a	mid(filler1, 1,10)	length(filler1)=length(filler2)
41820	filler1234	1
41831	filler1234	1
418410	filler1234	1
418511	filler1234	1
418612	filler1234	1
418713	filler1234	1
418814	filler1234	1
418915	filler1234	1
419016	filler1234	1
419117	filler1234	1
419218	filler1234	1
419319	duplicate 	1
419419	filler1234	1
41952	filler1234	1
41963	duplicate 	1
41973	filler1234	1
41984	filler1234	1
41995	filler1234	1
42006	filler1234	1
42017	filler1234	1
42028	filler1234	1
42039	filler1234	1
4204set @@join_buffer_size = @save_join_buffer_size;
4205drop table t1, t2;
4206create table t1 (a int, b int, key(a));
4207create table t2 (a int, b int, key(a));
4208create table t3 (a int, b int, key(a));
4209insert into t1 select a,a from t0;
4210insert into t2 select a,a from t0;
4211insert into t3 select a,a from t0;
4212t2 and t3 must be use 'ref', not 'ALL':
4213explain select *
4214from t0 where a in
4215(select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a);
4216id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
42171	PRIMARY	t0	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
42182	SUBQUERY	t1	NULL	index	a	a	5	NULL	10	100.00	Using index
42192	SUBQUERY	t2	NULL	ref	a	a	5	test.t1.a	1	100.00	Using index
42202	SUBQUERY	t3	NULL	ref	a	a	5	test.t1.a	1	100.00	Using index
4221Warnings:
4222Note	1003	/* select#1 */ select `test`.`t0`.`a` AS `a` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`a`,`test`.`t0`.`a` in ( <materialize> (/* select#2 */ select (`test`.`t2`.`a` + `test`.`t3`.`a`) from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`a`)) ), <primary_index_lookup>(`test`.`t0`.`a` in <temporary table> on <auto_key> where ((`test`.`t0`.`a` = `materialized-subquery`.`t2.a+t3.a`)))))
4223drop table t0, t1,t2,t3;
4224
4225Test that neither MaterializeLookup strategy for semijoin,
4226nor subquery materialization is used when BLOBs are involved
4227(except when arguments of some functions).
4228
4229set @prefix_len = 6;
4230set @blob_len = 16;
4231set @suffix_len = @blob_len - @prefix_len;
4232create table t1_16 (a1 blob(16), a2 blob(16));
4233create table t2_16 (b1 blob(16), b2 blob(16));
4234create table t3_16 (c1 blob(16), c2 blob(16));
4235insert into t1_16 values
4236(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
4237insert into t1_16 values
4238(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4239insert into t1_16 values
4240(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4241insert into t2_16 values
4242(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4243insert into t2_16 values
4244(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4245insert into t2_16 values
4246(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4247insert into t3_16 values
4248(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4249insert into t3_16 values
4250(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4251insert into t3_16 values
4252(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4253insert into t3_16 values
4254(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
4255explain extended select left(a1,7), left(a2,7)
4256from t1_16
4257where a1 in (select b1 from t2_16 where b1 > '0');
4258id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
42591	PRIMARY	t1_16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
42602	DEPENDENT SUBQUERY	t2_16	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4261Warnings:
4262Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4263Note	1003	/* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))
4264select left(a1,7), left(a2,7)
4265from t1_16
4266where a1 in (select b1 from t2_16 where b1 > '0');
4267left(a1,7)	left(a2,7)
42681 - 01x	2 - 01x
42691 - 02x	2 - 02x
4270explain extended select left(a1,7), left(a2,7)
4271from t1_16
4272where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
4273id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
42741	PRIMARY	t1_16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
42752	DEPENDENT SUBQUERY	t2_16	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4276Warnings:
4277Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4278Note	1003	/* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(/* select#2 */ select 1,1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`) and (<cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`))))
4279select left(a1,7), left(a2,7)
4280from t1_16
4281where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
4282left(a1,7)	left(a2,7)
42831 - 01x	2 - 01x
42841 - 02x	2 - 02x
4285explain extended select left(a1,7), left(a2,7)
4286from t1_16
4287where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
4288id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
42891	PRIMARY	t1_16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
42902	SUBQUERY	t2_16	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4291Warnings:
4292Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4293Note	1003	/* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (/* select#2 */ select substr(`test`.`t2_16`.`b1`,1,16) from `test`.`t2_16` where (`test`.`t2_16`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_16`.`a1` = `materialized-subquery`.`substring(b1,1,16)`)))))
4294select left(a1,7), left(a2,7)
4295from t1_16
4296where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
4297left(a1,7)	left(a2,7)
42981 - 01x	2 - 01x
42991 - 02x	2 - 02x
4300explain extended select left(a1,7), left(a2,7)
4301from t1_16
4302where a1 in (select group_concat(b1) from t2_16 group by b2);
4303id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43041	PRIMARY	t1_16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
43052	DEPENDENT SUBQUERY	t2_16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4306Warnings:
4307Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4308Note	1003	/* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` group by `test`.`t2_16`.`b2` having (<cache>(`test`.`t1_16`.`a1`) = <ref_null_helper>(group_concat(`test`.`t2_16`.`b1` separator ',')))))
4309select left(a1,7), left(a2,7)
4310from t1_16
4311where a1 in (select group_concat(b1) from t2_16 group by b2);
4312left(a1,7)	left(a2,7)
43131 - 01x	2 - 01x
43141 - 02x	2 - 02x
4315set @@group_concat_max_len = 256;
4316explain extended select left(a1,7), left(a2,7)
4317from t1_16
4318where a1 in (select group_concat(b1) from t2_16 group by b2);
4319id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43201	PRIMARY	t1_16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
43212	SUBQUERY	t2_16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4322Warnings:
4323Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4324Note	1003	/* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` having 1 ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_16`.`a1` = `materialized-subquery`.`group_concat(b1)`)))))
4325select left(a1,7), left(a2,7)
4326from t1_16
4327where a1 in (select group_concat(b1) from t2_16 group by b2);
4328left(a1,7)	left(a2,7)
43291 - 01x	2 - 01x
43301 - 02x	2 - 02x
4331create table t1 (a1 char(8), a2 char(8));
4332create table t2 (b1 char(8), b2 char(8));
4333create table t3 (c1 char(8), c2 char(8));
4334insert into t1 values ('1 - 00', '2 - 00');
4335insert into t1 values ('1 - 01', '2 - 01');
4336insert into t1 values ('1 - 02', '2 - 02');
4337insert into t2 values ('1 - 01', '2 - 01');
4338insert into t2 values ('1 - 01', '2 - 01');
4339insert into t2 values ('1 - 02', '2 - 02');
4340insert into t2 values ('1 - 02', '2 - 02');
4341insert into t2 values ('1 - 03', '2 - 03');
4342insert into t3 values ('1 - 01', '2 - 01');
4343insert into t3 values ('1 - 02', '2 - 02');
4344insert into t3 values ('1 - 03', '2 - 03');
4345insert into t3 values ('1 - 04', '2 - 04');
4346insert into t3 values ('1 - 05', '2 - 05');
4347insert into t3 values ('1 - 06', '2 - 06');
4348insert into t3 values ('1 - 07', '2 - 07');
4349insert into t3 values ('1 - 08', '2 - 08');
4350explain extended
4351select * from t1
4352where concat(a1,'x') IN
4353(select left(a1,8) from t1_16
4354where (a1, a2) IN
4355(select t2_16.b1, t2_16.b2 from t2_16, t2
4356where t2.b2 = substring(t2_16.b2,1,6) and
4357t2.b1 IN (select c1 from t3 where c2 > '0')));
4358id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43591	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
43602	DEPENDENT SUBQUERY	t1_16	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
43613	DEPENDENT SUBQUERY	t2_16	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
43623	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	5	20.00	Using where; Using join buffer (Block Nested Loop)
43634	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	8	33.33	Using where
4364Warnings:
4365Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4366Note	1003	/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(concat(`test`.`t1`.`a1`,'x'),<exists>(/* select#2 */ select 1 from `test`.`t1_16` where (<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(/* select#3 */ select 1,1 from `test`.`t2_16` join `test`.`t2` where ((`test`.`t2`.`b2` = substr(`test`.`t2_16`.`b2`,1,6)) and <in_optimizer>(`test`.`t2`.`b1`,`test`.`t2`.`b1` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c1` from `test`.`t3` where (`test`.`t3`.`c2` > '0') ), <primary_index_lookup>(`test`.`t2`.`b1` in <temporary table> on <auto_key> where ((`test`.`t2`.`b1` = `materialized-subquery`.`c1`))))) and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`) and (<cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`)))) and (<cache>(concat(`test`.`t1`.`a1`,'x')) = left(`test`.`t1_16`.`a1`,8)))))
4367drop table t1_16, t2_16, t3_16, t1, t2, t3;
4368set @blob_len = 512;
4369set @suffix_len = @blob_len - @prefix_len;
4370create table t1_512 (a1 blob(512), a2 blob(512));
4371create table t2_512 (b1 blob(512), b2 blob(512));
4372create table t3_512 (c1 blob(512), c2 blob(512));
4373insert into t1_512 values
4374(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
4375insert into t1_512 values
4376(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4377insert into t1_512 values
4378(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4379insert into t2_512 values
4380(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4381insert into t2_512 values
4382(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4383insert into t2_512 values
4384(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4385insert into t3_512 values
4386(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4387insert into t3_512 values
4388(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4389insert into t3_512 values
4390(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4391insert into t3_512 values
4392(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
4393explain extended select left(a1,7), left(a2,7)
4394from t1_512
4395where a1 in (select b1 from t2_512 where b1 > '0');
4396id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43971	PRIMARY	t1_512	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
43982	DEPENDENT SUBQUERY	t2_512	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4399Warnings:
4400Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4401Note	1003	/* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>(`test`.`t1_512`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_512` where ((`test`.`t2_512`.`b1` > '0') and (<cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`))))
4402select left(a1,7), left(a2,7)
4403from t1_512
4404where a1 in (select b1 from t2_512 where b1 > '0');
4405left(a1,7)	left(a2,7)
44061 - 01x	2 - 01x
44071 - 02x	2 - 02x
4408explain extended select left(a1,7), left(a2,7)
4409from t1_512
4410where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
4411id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44121	PRIMARY	t1_512	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
44132	DEPENDENT SUBQUERY	t2_512	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4414Warnings:
4415Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4416Note	1003	/* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>((`test`.`t1_512`.`a1`,`test`.`t1_512`.`a2`),<exists>(/* select#2 */ select 1,1 from `test`.`t2_512` where ((`test`.`t2_512`.`b1` > '0') and (<cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`) and (<cache>(`test`.`t1_512`.`a2`) = `test`.`t2_512`.`b2`))))
4417select left(a1,7), left(a2,7)
4418from t1_512
4419where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
4420left(a1,7)	left(a2,7)
44211 - 01x	2 - 01x
44221 - 02x	2 - 02x
4423explain extended select left(a1,7), left(a2,7)
4424from t1_512
4425where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
4426id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44271	PRIMARY	t1_512	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
44282	SUBQUERY	t2_512	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4429Warnings:
4430Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4431Note	1003	/* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select substr(`test`.`t2_512`.`b1`,1,512) from `test`.`t2_512` where (`test`.`t2_512`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_512`.`a1` = `materialized-subquery`.`substring(b1,1,512)`)))))
4432select left(a1,7), left(a2,7)
4433from t1_512
4434where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
4435left(a1,7)	left(a2,7)
44361 - 01x	2 - 01x
44371 - 02x	2 - 02x
4438explain extended select left(a1,7), left(a2,7)
4439from t1_512
4440where a1 in (select group_concat(b1) from t2_512 group by b2);
4441id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44421	PRIMARY	t1_512	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
44432	SUBQUERY	t2_512	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4444Warnings:
4445Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4446Note	1003	/* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` having 1 ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_512`.`a1` = `materialized-subquery`.`group_concat(b1)`)))))
4447select left(a1,7), left(a2,7)
4448from t1_512
4449where a1 in (select group_concat(b1) from t2_512 group by b2);
4450left(a1,7)	left(a2,7)
4451Warnings:
4452Warning	1260	Row 1 was cut by GROUP_CONCAT()
4453Warning	1260	Row 2 was cut by GROUP_CONCAT()
4454Warning	1260	Row 3 was cut by GROUP_CONCAT()
4455set @@group_concat_max_len = 256;
4456explain extended select left(a1,7), left(a2,7)
4457from t1_512
4458where a1 in (select group_concat(b1) from t2_512 group by b2);
4459id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44601	PRIMARY	t1_512	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
44612	SUBQUERY	t2_512	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4462Warnings:
4463Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4464Note	1003	/* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` having 1 ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_512`.`a1` = `materialized-subquery`.`group_concat(b1)`)))))
4465select left(a1,7), left(a2,7)
4466from t1_512
4467where a1 in (select group_concat(b1) from t2_512 group by b2);
4468left(a1,7)	left(a2,7)
4469Warnings:
4470Warning	1260	Row 1 was cut by GROUP_CONCAT()
4471Warning	1260	Row 2 was cut by GROUP_CONCAT()
4472Warning	1260	Row 3 was cut by GROUP_CONCAT()
4473drop table t1_512, t2_512, t3_512;
4474set @blob_len = 513;
4475set @suffix_len = @blob_len - @prefix_len;
4476create table t1_513 (a1 blob(513), a2 blob(513));
4477create table t2_513 (b1 blob(513), b2 blob(513));
4478create table t3_513 (c1 blob(513), c2 blob(513));
4479insert into t1_513 values
4480(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
4481insert into t1_513 values
4482(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4483insert into t1_513 values
4484(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4485insert into t2_513 values
4486(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4487insert into t2_513 values
4488(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4489insert into t2_513 values
4490(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4491insert into t3_513 values
4492(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4493insert into t3_513 values
4494(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4495insert into t3_513 values
4496(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4497insert into t3_513 values
4498(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
4499explain extended select left(a1,7), left(a2,7)
4500from t1_513
4501where a1 in (select b1 from t2_513 where b1 > '0');
4502id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45031	PRIMARY	t1_513	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
45042	DEPENDENT SUBQUERY	t2_513	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4505Warnings:
4506Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4507Note	1003	/* select#1 */ select left(`test`.`t1_513`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_513`.`a2`,7) AS `left(a2,7)` from `test`.`t1_513` where <in_optimizer>(`test`.`t1_513`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_513` where ((`test`.`t2_513`.`b1` > '0') and (<cache>(`test`.`t1_513`.`a1`) = `test`.`t2_513`.`b1`))))
4508select left(a1,7), left(a2,7)
4509from t1_513
4510where a1 in (select b1 from t2_513 where b1 > '0');
4511left(a1,7)	left(a2,7)
45121 - 01x	2 - 01x
45131 - 02x	2 - 02x
4514explain extended select left(a1,7), left(a2,7)
4515from t1_513
4516where (a1,a2) in (select b1, b2 from t2_513 where b1 > '0');
4517id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45181	PRIMARY	t1_513	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
45192	DEPENDENT SUBQUERY	t2_513	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4520Warnings:
4521Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4522Note	1003	/* select#1 */ select left(`test`.`t1_513`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_513`.`a2`,7) AS `left(a2,7)` from `test`.`t1_513` where <in_optimizer>((`test`.`t1_513`.`a1`,`test`.`t1_513`.`a2`),<exists>(/* select#2 */ select 1,1 from `test`.`t2_513` where ((`test`.`t2_513`.`b1` > '0') and (<cache>(`test`.`t1_513`.`a1`) = `test`.`t2_513`.`b1`) and (<cache>(`test`.`t1_513`.`a2`) = `test`.`t2_513`.`b2`))))
4523select left(a1,7), left(a2,7)
4524from t1_513
4525where (a1,a2) in (select b1, b2 from t2_513 where b1 > '0');
4526left(a1,7)	left(a2,7)
45271 - 01x	2 - 01x
45281 - 02x	2 - 02x
4529explain extended select left(a1,7), left(a2,7)
4530from t1_513
4531where a1 in (select substring(b1,1,513) from t2_513 where b1 > '0');
4532id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45331	PRIMARY	t1_513	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
45342	DEPENDENT SUBQUERY	t2_513	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4535Warnings:
4536Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4537Note	1003	/* select#1 */ select left(`test`.`t1_513`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_513`.`a2`,7) AS `left(a2,7)` from `test`.`t1_513` where <in_optimizer>(`test`.`t1_513`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_513` where ((`test`.`t2_513`.`b1` > '0') and (<cache>(`test`.`t1_513`.`a1`) = substr(`test`.`t2_513`.`b1`,1,513)))))
4538select left(a1,7), left(a2,7)
4539from t1_513
4540where a1 in (select substring(b1,1,513) from t2_513 where b1 > '0');
4541left(a1,7)	left(a2,7)
45421 - 01x	2 - 01x
45431 - 02x	2 - 02x
4544explain extended select left(a1,7), left(a2,7)
4545from t1_513
4546where a1 in (select group_concat(b1) from t2_513 group by b2);
4547id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45481	PRIMARY	t1_513	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
45492	SUBQUERY	t2_513	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4550Warnings:
4551Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4552Note	1003	/* select#1 */ select left(`test`.`t1_513`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_513`.`a2`,7) AS `left(a2,7)` from `test`.`t1_513` where <in_optimizer>(`test`.`t1_513`.`a1`,`test`.`t1_513`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_513`.`b1` separator ',') from `test`.`t2_513` group by `test`.`t2_513`.`b2` having 1 ), <primary_index_lookup>(`test`.`t1_513`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_513`.`a1` = `materialized-subquery`.`group_concat(b1)`)))))
4553select left(a1,7), left(a2,7)
4554from t1_513
4555where a1 in (select group_concat(b1) from t2_513 group by b2);
4556left(a1,7)	left(a2,7)
4557Warnings:
4558Warning	1260	Row 1 was cut by GROUP_CONCAT()
4559Warning	1260	Row 2 was cut by GROUP_CONCAT()
4560Warning	1260	Row 3 was cut by GROUP_CONCAT()
4561drop table t1_513, t2_513, t3_513;
4562set @blob_len = 1024;
4563set @suffix_len = @blob_len - @prefix_len;
4564create table t1_1024 (a1 blob(1024), a2 blob(1024));
4565create table t2_1024 (b1 blob(1024), b2 blob(1024));
4566create table t3_1024 (c1 blob(1024), c2 blob(1024));
4567insert into t1_1024 values
4568(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
4569insert into t1_1024 values
4570(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4571insert into t1_1024 values
4572(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4573insert into t2_1024 values
4574(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4575insert into t2_1024 values
4576(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4577insert into t2_1024 values
4578(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4579insert into t3_1024 values
4580(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4581insert into t3_1024 values
4582(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4583insert into t3_1024 values
4584(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4585insert into t3_1024 values
4586(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
4587explain extended select left(a1,7), left(a2,7)
4588from t1_1024
4589where a1 in (select b1 from t2_1024 where b1 > '0');
4590id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45911	PRIMARY	t1_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
45922	DEPENDENT SUBQUERY	t2_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4593Warnings:
4594Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4595Note	1003	/* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`))))
4596select left(a1,7), left(a2,7)
4597from t1_1024
4598where a1 in (select b1 from t2_1024 where b1 > '0');
4599left(a1,7)	left(a2,7)
46001 - 01x	2 - 01x
46011 - 02x	2 - 02x
4602explain extended select left(a1,7), left(a2,7)
4603from t1_1024
4604where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
4605id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46061	PRIMARY	t1_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
46072	DEPENDENT SUBQUERY	t2_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4608Warnings:
4609Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4610Note	1003	/* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>((`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a2`),<exists>(/* select#2 */ select 1,1 from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`) and (<cache>(`test`.`t1_1024`.`a2`) = `test`.`t2_1024`.`b2`))))
4611select left(a1,7), left(a2,7)
4612from t1_1024
4613where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
4614left(a1,7)	left(a2,7)
46151 - 01x	2 - 01x
46161 - 02x	2 - 02x
4617explain extended select left(a1,7), left(a2,7)
4618from t1_1024
4619where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
4620id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46211	PRIMARY	t1_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
46222	DEPENDENT SUBQUERY	t2_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4623Warnings:
4624Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4625Note	1003	/* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = substr(`test`.`t2_1024`.`b1`,1,1024)))))
4626select left(a1,7), left(a2,7)
4627from t1_1024
4628where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
4629left(a1,7)	left(a2,7)
46301 - 01x	2 - 01x
46311 - 02x	2 - 02x
4632explain extended select left(a1,7), left(a2,7)
4633from t1_1024
4634where a1 in (select group_concat(b1) from t2_1024 group by b2);
4635id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46361	PRIMARY	t1_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
46372	SUBQUERY	t2_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4638Warnings:
4639Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4640Note	1003	/* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` having 1 ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_1024`.`a1` = `materialized-subquery`.`group_concat(b1)`)))))
4641select left(a1,7), left(a2,7)
4642from t1_1024
4643where a1 in (select group_concat(b1) from t2_1024 group by b2);
4644left(a1,7)	left(a2,7)
4645Warnings:
4646Warning	1260	Row 1 was cut by GROUP_CONCAT()
4647Warning	1260	Row 2 was cut by GROUP_CONCAT()
4648Warning	1260	Row 3 was cut by GROUP_CONCAT()
4649set @@group_concat_max_len = 256;
4650explain extended select left(a1,7), left(a2,7)
4651from t1_1024
4652where a1 in (select group_concat(b1) from t2_1024 group by b2);
4653id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46541	PRIMARY	t1_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
46552	SUBQUERY	t2_1024	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4656Warnings:
4657Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4658Note	1003	/* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` having 1 ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_1024`.`a1` = `materialized-subquery`.`group_concat(b1)`)))))
4659select left(a1,7), left(a2,7)
4660from t1_1024
4661where a1 in (select group_concat(b1) from t2_1024 group by b2);
4662left(a1,7)	left(a2,7)
4663Warnings:
4664Warning	1260	Row 1 was cut by GROUP_CONCAT()
4665Warning	1260	Row 2 was cut by GROUP_CONCAT()
4666Warning	1260	Row 3 was cut by GROUP_CONCAT()
4667drop table t1_1024, t2_1024, t3_1024;
4668set @blob_len = 1025;
4669set @suffix_len = @blob_len - @prefix_len;
4670create table t1_1025 (a1 blob(1025), a2 blob(1025));
4671create table t2_1025 (b1 blob(1025), b2 blob(1025));
4672create table t3_1025 (c1 blob(1025), c2 blob(1025));
4673insert into t1_1025 values
4674(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
4675insert into t1_1025 values
4676(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4677insert into t1_1025 values
4678(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4679insert into t2_1025 values
4680(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4681insert into t2_1025 values
4682(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4683insert into t2_1025 values
4684(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4685insert into t3_1025 values
4686(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
4687insert into t3_1025 values
4688(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
4689insert into t3_1025 values
4690(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
4691insert into t3_1025 values
4692(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
4693explain extended select left(a1,7), left(a2,7)
4694from t1_1025
4695where a1 in (select b1 from t2_1025 where b1 > '0');
4696id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46971	PRIMARY	t1_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
46982	DEPENDENT SUBQUERY	t2_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4699Warnings:
4700Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4701Note	1003	/* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`))))
4702select left(a1,7), left(a2,7)
4703from t1_1025
4704where a1 in (select b1 from t2_1025 where b1 > '0');
4705left(a1,7)	left(a2,7)
47061 - 01x	2 - 01x
47071 - 02x	2 - 02x
4708explain extended select left(a1,7), left(a2,7)
4709from t1_1025
4710where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
4711id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47121	PRIMARY	t1_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
47132	DEPENDENT SUBQUERY	t2_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4714Warnings:
4715Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4716Note	1003	/* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>((`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a2`),<exists>(/* select#2 */ select 1,1 from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`) and (<cache>(`test`.`t1_1025`.`a2`) = `test`.`t2_1025`.`b2`))))
4717select left(a1,7), left(a2,7)
4718from t1_1025
4719where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
4720left(a1,7)	left(a2,7)
47211 - 01x	2 - 01x
47221 - 02x	2 - 02x
4723explain extended select left(a1,7), left(a2,7)
4724from t1_1025
4725where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
4726id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47271	PRIMARY	t1_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
47282	DEPENDENT SUBQUERY	t2_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where
4729Warnings:
4730Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4731Note	1003	/* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = substr(`test`.`t2_1025`.`b1`,1,1025)))))
4732select left(a1,7), left(a2,7)
4733from t1_1025
4734where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
4735left(a1,7)	left(a2,7)
47361 - 01x	2 - 01x
47371 - 02x	2 - 02x
4738explain extended select left(a1,7), left(a2,7)
4739from t1_1025
4740where a1 in (select group_concat(b1) from t2_1025 group by b2);
4741id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47421	PRIMARY	t1_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
47432	SUBQUERY	t2_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4744Warnings:
4745Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4746Note	1003	/* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` having 1 ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_1025`.`a1` = `materialized-subquery`.`group_concat(b1)`)))))
4747select left(a1,7), left(a2,7)
4748from t1_1025
4749where a1 in (select group_concat(b1) from t2_1025 group by b2);
4750left(a1,7)	left(a2,7)
4751Warnings:
4752Warning	1260	Row 1 was cut by GROUP_CONCAT()
4753Warning	1260	Row 2 was cut by GROUP_CONCAT()
4754Warning	1260	Row 3 was cut by GROUP_CONCAT()
4755set @@group_concat_max_len = 256;
4756explain extended select left(a1,7), left(a2,7)
4757from t1_1025
4758where a1 in (select group_concat(b1) from t2_1025 group by b2);
4759id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47601	PRIMARY	t1_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
47612	SUBQUERY	t2_1025	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
4762Warnings:
4763Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
4764Note	1003	/* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` having 1 ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on <auto_key> where ((`test`.`t1_1025`.`a1` = `materialized-subquery`.`group_concat(b1)`)))))
4765select left(a1,7), left(a2,7)
4766from t1_1025
4767where a1 in (select group_concat(b1) from t2_1025 group by b2);
4768left(a1,7)	left(a2,7)
4769Warnings:
4770Warning	1260	Row 1 was cut by GROUP_CONCAT()
4771Warning	1260	Row 2 was cut by GROUP_CONCAT()
4772Warning	1260	Row 3 was cut by GROUP_CONCAT()
4773drop table t1_1025, t2_1025, t3_1025;
4774#
4775# WL#5561: Enable semi join transformation with outer join.
4776#
4777CREATE TABLE ot1(a INT);
4778CREATE TABLE ot2(a INT);
4779CREATE TABLE ot3(a INT);
4780CREATE TABLE it1(a INT);
4781CREATE TABLE it2(a INT);
4782CREATE TABLE it3(a INT);
4783INSERT INTO ot1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
4784INSERT INTO ot2 VALUES(0),(2),(4),(6);
4785INSERT INTO ot3 VALUES(0),(3),(6);
4786INSERT INTO it1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
4787INSERT INTO it2 VALUES(0),(2),(4),(6);
4788INSERT INTO it3 VALUES(0),(3),(6);
4789# Test cases, Subquery Pattern 1
4790# Example SQ1.1:
4791explain SELECT *
4792FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4793WHERE ot1.a IN (SELECT a FROM it3);
4794id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47951	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	Using where
47961	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
47972	SUBQUERY	it3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
4798Warnings:
4799Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` left join `test`.`ot2` on((`test`.`ot2`.`a` = `test`.`ot1`.`a`)) where <in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#2 */ select `test`.`it3`.`a` from `test`.`it3` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`)))))
4800SELECT *
4801FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4802WHERE ot1.a IN (SELECT a FROM it3);
4803a	a
48040	0
48053	NULL
48066	6
4807# Example SQ1.2:
4808explain SELECT *
4809FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4810WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
4811id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48121	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
48131	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
48142	SUBQUERY	it3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
4815Warnings:
4816Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` left join `test`.`ot2` on((`test`.`ot2`.`a` = `test`.`ot1`.`a`)) where <in_optimizer>(coalesce(`test`.`ot2`.`a`,0),coalesce(`test`.`ot2`.`a`,0) in ( <materialize> (/* select#2 */ select `test`.`it3`.`a` from `test`.`it3` where 1 ), <primary_index_lookup>(coalesce(`test`.`ot2`.`a`,0) in <temporary table> on <auto_key> where ((coalesce(`test`.`ot2`.`a`,0) = `materialized-subquery`.`a`)))))
4817SELECT *
4818FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4819WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
4820a	a
48210	0
48221	NULL
48233	NULL
48245	NULL
48256	6
48267	NULL
4827# Example SQ1.3:
4828explain SELECT *
4829FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4830WHERE (ot1.a,ot2.a) IN (SELECT a, a FROM it3);
4831id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48321	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
48331	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	12.50	Using where; Using join buffer (Block Nested Loop)
48342	SUBQUERY	it3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
4835Warnings:
4836Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` join `test`.`ot2` where ((`test`.`ot1`.`a` = `test`.`ot2`.`a`) and <in_optimizer>((`test`.`ot1`.`a`,`test`.`ot2`.`a`),(`test`.`ot1`.`a`,`test`.`ot2`.`a`) in ( <materialize> (/* select#2 */ select `test`.`it3`.`a`,`test`.`it3`.`a` from `test`.`it3` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`) and (`test`.`ot2`.`a` = `materialized-subquery`.`a`))))))
4837SELECT *
4838FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4839WHERE (ot1.a,ot2.a) IN (SELECT a, a FROM it3);
4840a	a
48410	0
48426	6
4843# More test cases
4844SELECT *
4845FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0
4846WHERE ot1.a IN (SELECT a FROM it3);
4847a	a
48480	0
48493	NULL
48506	6
4851SELECT *
4852FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0
4853WHERE ot1.a IN (SELECT a+0 FROM it3);
4854a	a
48550	0
48563	NULL
48576	6
4858SELECT *
4859FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0
4860WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
4861a	a
48620	0
48631	NULL
48643	NULL
48655	NULL
48666	6
48677	NULL
4868SELECT *
4869FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4870WHERE COALESCE(ot2.a,0) IN (SELECT a+0 FROM it3);
4871a	a
48720	0
48731	NULL
48743	NULL
48755	NULL
48766	6
48777	NULL
4878SELECT *
4879FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0
4880WHERE (ot1.a,ot2.a) IN (SELECT a, a FROM it3);
4881a	a
48820	0
48836	6
4884SELECT *
4885FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4886LEFT JOIN ot3 ON ot1.a=ot3.a
4887WHERE ot1.a IN (SELECT a FROM it3);
4888a	a	a
48890	0	0
48903	NULL	3
48916	6	6
4892SELECT *
4893FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4894LEFT JOIN ot3 ON ot1.a=ot3.a
4895WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
4896a	a	a
48970	0	0
48981	NULL	NULL
48993	NULL	3
49005	NULL	NULL
49016	6	6
49027	NULL	NULL
4903SELECT *
4904FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4905LEFT JOIN ot3 ON ot1.a=ot3.a
4906WHERE COALESCE(ot3.a,0) IN (SELECT a FROM it3);
4907a	a	a
49080	0	0
49091	NULL	NULL
49102	2	NULL
49113	NULL	3
49124	4	NULL
49135	NULL	NULL
49146	6	6
49157	NULL	NULL
4916SELECT *
4917FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4918LEFT JOIN ot3 ON ot2.a=ot3.a
4919WHERE ot1.a IN (SELECT a FROM it3);
4920a	a	a
49210	0	0
49223	NULL	NULL
49236	6	6
4924SELECT *
4925FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4926LEFT JOIN ot3 ON ot2.a=ot3.a
4927WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
4928a	a	a
49290	0	0
49301	NULL	NULL
49313	NULL	NULL
49325	NULL	NULL
49336	6	6
49347	NULL	NULL
4935SELECT *
4936FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a
4937LEFT JOIN ot3 ON ot2.a=ot3.a
4938WHERE COALESCE(ot3.a,0) IN (SELECT a FROM it3);
4939a	a	a
49400	0	0
49411	NULL	NULL
49422	2	NULL
49433	NULL	NULL
49444	4	NULL
49455	NULL	NULL
49466	6	6
49477	NULL	NULL
4948# Test cases, Subquery Pattern 2
4949# Example SQ2.1:
4950explain SELECT *
4951FROM ot1 JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3);
4952id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
49531	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
49541	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	12.50	Using where; Using join buffer (Block Nested Loop)
49552	SUBQUERY	it3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
4956Warnings:
4957Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` join `test`.`ot2` where ((`test`.`ot1`.`a` = `test`.`ot2`.`a`) and <in_optimizer>(`test`.`ot2`.`a`,`test`.`ot2`.`a` in ( <materialize> (/* select#2 */ select `test`.`it3`.`a` from `test`.`it3` where 1 ), <primary_index_lookup>(`test`.`ot2`.`a` in <temporary table> on <auto_key> where ((`test`.`ot2`.`a` = `materialized-subquery`.`a`))))))
4958SELECT *
4959FROM ot1 JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3);
4960a	a
49610	0
49626	6
4963# Example SQ2.2:
4964explain SELECT *
4965FROM ot1 JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it2)
4966AND ot2.a IN (SELECT a FROM it3);
4967id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
49681	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
49691	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	12.50	Using where; Using join buffer (Block Nested Loop)
49703	SUBQUERY	it3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
49712	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
4972Warnings:
4973Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` join `test`.`ot2` where ((`test`.`ot1`.`a` = `test`.`ot2`.`a`) and <in_optimizer>(`test`.`ot2`.`a`,`test`.`ot2`.`a` in ( <materialize> (/* select#2 */ select `test`.`it2`.`a` from `test`.`it2` where 1 ), <primary_index_lookup>(`test`.`ot2`.`a` in <temporary table> on <auto_key> where ((`test`.`ot2`.`a` = `materialized-subquery`.`a`))))) and <in_optimizer>(`test`.`ot2`.`a`,`test`.`ot2`.`a` in ( <materialize> (/* select#3 */ select `test`.`it3`.`a` from `test`.`it3` where 1 ), <primary_index_lookup>(`test`.`ot2`.`a` in <temporary table> on <auto_key> where ((`test`.`ot2`.`a` = `materialized-subquery`.`a`))))))
4974SELECT *
4975FROM ot1 JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it2)
4976AND ot2.a IN (SELECT a FROM it3);
4977a	a
49780	0
49796	6
4980# More test cases
4981SELECT *
4982FROM ot1 JOIN ot2 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it3);
4983a	a
49840	0
49856	6
4986SELECT *
4987FROM ot1 JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it3);
4988a	a
49890	0
49906	6
4991SELECT *
4992FROM ot1 JOIN ot2 ON ot1.a=ot2.a+0 AND ot2.a IN (SELECT a FROM it3);
4993a	a
49940	0
49956	6
4996SELECT *
4997FROM ot1 JOIN ot2 ON ot1.a=ot2.a AND ot2.a IN (SELECT a+0 FROM it3);
4998a	a
49990	0
50006	6
5001SELECT *
5002FROM ot1 JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it2)
5003AND ot2.a IN (SELECT a+0 FROM it3);
5004a	a
50050	0
50066	6
5007SELECT *
5008FROM ot1 JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3)
5009JOIN ot3 ON ot2.a=ot3.a AND ot3.a IN (SELECT a FROM it3);
5010a	a	a
50110	0	0
50126	6	6
5013# Test cases, Subquery Pattern 3
5014# Example SQ3.1:
5015explain SELECT *
5016FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3);
5017id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
50181	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
50191	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
50202	SUBQUERY	it3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
5021Warnings:
5022Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` left join `test`.`ot2` on(((`test`.`ot2`.`a` = `test`.`ot1`.`a`) and <in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#2 */ select `test`.`it3`.`a` from `test`.`it3` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`))))))) where 1
5023SELECT *
5024FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3);
5025a	a
50260	0
50271	NULL
50282	NULL
50293	NULL
50304	NULL
50315	NULL
50326	6
50337	NULL
5034# Example SQ3.2:
5035explain SELECT *
5036FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot2.a IN (SELECT a FROM it2);
5037id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
50381	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
50391	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
50402	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
5041Warnings:
5042Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` left join `test`.`ot2` on(((`test`.`ot2`.`a` = `test`.`ot1`.`a`) and <in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#2 */ select `test`.`it2`.`a` from `test`.`it2` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`))))))) where 1
5043SELECT *
5044FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot2.a IN (SELECT a FROM it2);
5045a	a
50460	0
50471	NULL
50482	2
50493	NULL
50504	4
50515	NULL
50526	6
50537	NULL
5054# Example SQ3.3
5055explain SELECT *
5056FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1)
5057AND ot2.a IN (SELECT a FROM it2);
5058id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
50591	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
50601	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
50613	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
50622	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
5063Warnings:
5064Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` left join `test`.`ot2` on(((`test`.`ot2`.`a` = `test`.`ot1`.`a`) and <in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#2 */ select `test`.`it1`.`a` from `test`.`it1` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`))))) and <in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#3 */ select `test`.`it2`.`a` from `test`.`it2` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`))))))) where 1
5065SELECT *
5066FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1)
5067AND ot2.a IN (SELECT a FROM it2);
5068a	a
50690	0
50701	NULL
50712	2
50723	NULL
50734	4
50745	NULL
50756	6
50767	NULL
5077# Example SQ3.4
5078explain SELECT *
5079FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND
5080(ot1.a, ot2.a) IN (SELECT it1.a, it2.a
5081FROM it1 JOIN it2 ON it1.a=it2.a);
5082id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
50831	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
50841	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
50852	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
50862	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	8	12.50	Using where; Using join buffer (Block Nested Loop)
5087Warnings:
5088Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` left join `test`.`ot2` on(((`test`.`ot2`.`a` = `test`.`ot1`.`a`) and <in_optimizer>((`test`.`ot1`.`a`,`test`.`ot2`.`a`),(`test`.`ot1`.`a`,`test`.`ot2`.`a`) in ( <materialize> (/* select#2 */ select `test`.`it1`.`a`,`test`.`it2`.`a` from `test`.`it1` join `test`.`it2` where (`test`.`it1`.`a` = `test`.`it2`.`a`) ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`) and (`test`.`ot2`.`a` = `materialized-subquery`.`a`))))))) where 1
5089SELECT *
5090FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND
5091(ot1.a, ot2.a) IN (SELECT it1.a, it2.a
5092FROM it1 JOIN it2 ON it1.a=it2.a);
5093a	a
50940	0
50951	NULL
50962	2
50973	NULL
50984	4
50995	NULL
51006	6
51017	NULL
5102# More test cases
5103SELECT *
5104FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it3);
5105a	a
51060	0
51071	NULL
51082	NULL
51093	NULL
51104	NULL
51115	NULL
51126	6
51137	NULL
5114SELECT *
5115FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it3);
5116a	a
51170	0
51181	NULL
51192	NULL
51203	NULL
51214	NULL
51225	NULL
51236	6
51247	NULL
5125SELECT *
5126FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0 AND ot2.a IN (SELECT a FROM it2);
5127a	a
51280	0
51291	NULL
51302	2
51313	NULL
51324	4
51335	NULL
51346	6
51357	NULL
5136SELECT *
5137FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot2.a IN (SELECT a+0 FROM it2);
5138a	a
51390	0
51401	NULL
51412	2
51423	NULL
51434	4
51445	NULL
51456	6
51467	NULL
5147SELECT *
5148FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a+0 FROM it1)
5149AND ot2.a IN (SELECT a+0 FROM it2);
5150a	a
51510	0
51521	NULL
51532	2
51543	NULL
51554	4
51565	NULL
51576	6
51587	NULL
5159SELECT *
5160FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0 AND
5161(ot1.a, ot2.a) IN (SELECT it1.a+0, it2.a+0
5162FROM it1 JOIN it2 ON it1.a=it2.a);
5163a	a
51640	0
51651	NULL
51662	2
51673	NULL
51684	4
51695	NULL
51706	6
51717	NULL
5172SELECT *
5173FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3)
5174LEFT JOIN ot3 ON ot2.a=ot3.a AND ot3.a IN (SELECT a FROM it3);
5175a	a	a
51760	0	0
51771	NULL	NULL
51782	NULL	NULL
51793	NULL	NULL
51804	NULL	NULL
51815	NULL	NULL
51826	6	6
51837	NULL	NULL
5184SELECT *
5185FROM ot1 LEFT JOIN ot2 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it3)
5186LEFT JOIN ot3 ON ot2.a=ot3.a+0 AND ot3.a IN (SELECT a FROM it3);
5187a	a	a
51880	0	0
51891	NULL	NULL
51902	NULL	NULL
51913	NULL	NULL
51924	NULL	NULL
51935	NULL	NULL
51946	6	6
51957	NULL	NULL
5196# Test cases, Subquery Pattern 4
5197# Example SQ4.1:
5198explain SELECT *
5199FROM   ot1
5200LEFT JOIN
5201(ot2 JOIN ot3 ON ot2.a=ot3.a)
5202ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5203id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
52041	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
52051	PRIMARY	ot3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (Block Nested Loop)
52061	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
52072	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
5208Warnings:
5209Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a`,`test`.`ot3`.`a` AS `a` from `test`.`ot1` left join (`test`.`ot2` join `test`.`ot3`) on(((`test`.`ot3`.`a` = `test`.`ot1`.`a`) and (`test`.`ot2`.`a` = `test`.`ot1`.`a`) and <in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#2 */ select `test`.`it1`.`a` from `test`.`it1` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`))))))) where 1
5210SELECT *
5211FROM   ot1
5212LEFT JOIN
5213(ot2 JOIN ot3 ON ot2.a=ot3.a)
5214ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5215a	a	a
52160	0	0
52171	NULL	NULL
52182	NULL	NULL
52193	NULL	NULL
52204	NULL	NULL
52215	NULL	NULL
52226	6	6
52237	NULL	NULL
5224# Example SQ4.2:
5225explain SELECT *
5226FROM   ot1
5227JOIN
5228(ot2 JOIN ot3 ON ot2.a=ot3.a)
5229ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5230id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
52311	PRIMARY	ot3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
52321	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	25.00	Using where; Using join buffer (Block Nested Loop)
52331	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	12.50	Using where; Using join buffer (Block Nested Loop)
52342	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
5235Warnings:
5236Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a`,`test`.`ot3`.`a` AS `a` from `test`.`ot1` join `test`.`ot2` join `test`.`ot3` where ((`test`.`ot2`.`a` = `test`.`ot3`.`a`) and (`test`.`ot1`.`a` = `test`.`ot3`.`a`) and <in_optimizer>(`test`.`ot3`.`a`,`test`.`ot3`.`a` in ( <materialize> (/* select#2 */ select `test`.`it1`.`a` from `test`.`it1` where 1 ), <primary_index_lookup>(`test`.`ot3`.`a` in <temporary table> on <auto_key> where ((`test`.`ot3`.`a` = `materialized-subquery`.`a`))))))
5237SELECT *
5238FROM   ot1
5239JOIN
5240(ot2 JOIN ot3 ON ot2.a=ot3.a)
5241ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5242a	a	a
52430	0	0
52446	6	6
5245# Example SQ4.3:
5246explain SELECT *
5247FROM   ot1
5248JOIN
5249(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5250ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5251id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
52521	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
52531	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	12.50	Using where; Using join buffer (Block Nested Loop)
52541	PRIMARY	ot3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (Block Nested Loop)
52552	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
5256Warnings:
5257Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a`,`test`.`ot3`.`a` AS `a` from `test`.`ot1` join `test`.`ot2` left join `test`.`ot3` on((`test`.`ot3`.`a` = `test`.`ot2`.`a`)) where ((`test`.`ot1`.`a` = `test`.`ot2`.`a`) and <in_optimizer>(`test`.`ot2`.`a`,`test`.`ot2`.`a` in ( <materialize> (/* select#2 */ select `test`.`it1`.`a` from `test`.`it1` where 1 ), <primary_index_lookup>(`test`.`ot2`.`a` in <temporary table> on <auto_key> where ((`test`.`ot2`.`a` = `materialized-subquery`.`a`))))))
5258SELECT *
5259FROM   ot1
5260JOIN
5261(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5262ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5263a	a	a
52640	0	0
52652	2	NULL
52664	4	NULL
52676	6	6
5268# Example SQ4.4:
5269explain SELECT *
5270FROM   ot1
5271LEFT JOIN
5272(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5273ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5274id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
52751	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
52761	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
52771	PRIMARY	ot3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (Block Nested Loop)
52782	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
5279Warnings:
5280Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a`,`test`.`ot3`.`a` AS `a` from `test`.`ot1` left join (`test`.`ot2` left join `test`.`ot3` on((`test`.`ot3`.`a` = `test`.`ot1`.`a`))) on(((`test`.`ot2`.`a` = `test`.`ot1`.`a`) and <in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#2 */ select `test`.`it1`.`a` from `test`.`it1` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`))))))) where 1
5281SELECT *
5282FROM   ot1
5283LEFT JOIN
5284(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5285ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5286a	a	a
52870	0	0
52881	NULL	NULL
52892	2	NULL
52903	NULL	NULL
52914	4	NULL
52925	NULL	NULL
52936	6	6
52947	NULL	NULL
5295# More test cases
5296SELECT *
5297FROM   ot1
5298LEFT JOIN
5299(ot2 JOIN ot3 ON ot2.a=ot3.a+0)
5300ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5301a	a	a
53020	0	0
53031	NULL	NULL
53042	NULL	NULL
53053	NULL	NULL
53064	NULL	NULL
53075	NULL	NULL
53086	6	6
53097	NULL	NULL
5310SELECT *
5311FROM   ot1
5312LEFT JOIN
5313(ot2 JOIN ot3 ON ot2.a=ot3.a)
5314ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it1);
5315a	a	a
53160	0	0
53171	NULL	NULL
53182	NULL	NULL
53193	NULL	NULL
53204	NULL	NULL
53215	NULL	NULL
53226	6	6
53237	NULL	NULL
5324SELECT *
5325FROM   ot1
5326LEFT JOIN
5327(ot2 JOIN ot3 ON ot2.a=ot3.a)
5328ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it1);
5329a	a	a
53300	0	0
53311	NULL	NULL
53322	NULL	NULL
53333	NULL	NULL
53344	NULL	NULL
53355	NULL	NULL
53366	6	6
53377	NULL	NULL
5338SELECT *
5339FROM   ot1
5340JOIN
5341(ot2 JOIN ot3 ON ot2.a=ot3.a+0)
5342ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5343a	a	a
53440	0	0
53456	6	6
5346SELECT *
5347FROM   ot1
5348JOIN
5349(ot2 JOIN ot3 ON ot2.a=ot3.a)
5350ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it1);
5351a	a	a
53520	0	0
53536	6	6
5354SELECT *
5355FROM   ot1
5356JOIN
5357(ot2 JOIN ot3 ON ot2.a=ot3.a)
5358ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it1);
5359a	a	a
53600	0	0
53616	6	6
5362SELECT *
5363FROM   ot1
5364JOIN
5365(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a+0)
5366ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5367a	a	a
53680	0	0
53692	2	NULL
53704	4	NULL
53716	6	6
5372SELECT *
5373FROM   ot1
5374JOIN
5375(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5376ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it1);
5377a	a	a
53780	0	0
53792	2	NULL
53804	4	NULL
53816	6	6
5382SELECT *
5383FROM   ot1
5384JOIN
5385(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5386ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it1);
5387a	a	a
53880	0	0
53892	2	NULL
53904	4	NULL
53916	6	6
5392SELECT *
5393FROM   ot1
5394LEFT JOIN
5395(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a+0)
5396ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5397a	a	a
53980	0	0
53991	NULL	NULL
54002	2	NULL
54013	NULL	NULL
54024	4	NULL
54035	NULL	NULL
54046	6	6
54057	NULL	NULL
5406SELECT *
5407FROM   ot1
5408LEFT JOIN
5409(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5410ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it1);
5411a	a	a
54120	0	0
54131	NULL	NULL
54142	2	NULL
54153	NULL	NULL
54164	4	NULL
54175	NULL	NULL
54186	6	6
54197	NULL	NULL
5420SELECT *
5421FROM   ot1
5422LEFT JOIN
5423(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5424ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it1);
5425a	a	a
54260	0	0
54271	NULL	NULL
54282	2	NULL
54293	NULL	NULL
54304	4	NULL
54315	NULL	NULL
54326	6	6
54337	NULL	NULL
5434SELECT *
5435FROM   ot1
5436LEFT JOIN
5437(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a)
5438ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1)
5439LEFT JOIN
5440ot1 AS ot4
5441ON ot2.a=ot4.a;
5442a	a	a	a
54430	0	0	0
54441	NULL	NULL	NULL
54452	2	NULL	2
54463	NULL	NULL	NULL
54474	4	NULL	4
54485	NULL	NULL	NULL
54496	6	6	6
54507	NULL	NULL	NULL
5451SELECT *
5452FROM   ot1
5453LEFT JOIN
5454(ot2 LEFT JOIN ot3 ON ot2.a=ot3.a
5455LEFT JOIN ot1 AS ot4 ON ot3.a=ot4.a)
5456ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
5457a	a	a	a
54580	0	0	0
54591	NULL	NULL	NULL
54602	2	NULL	NULL
54613	NULL	NULL	NULL
54624	4	NULL	NULL
54635	NULL	NULL	NULL
54646	6	6	6
54657	NULL	NULL	NULL
5466DROP TABLE ot1,ot2,ot3,it1,it2,it3;
5467CREATE TABLE t (
5468a INTEGER DEFAULT NULL
5469) ENGINE=InnoDB;
5470INSERT INTO t VALUES (1);
5471CREATE TABLE t2 (
5472a INTEGER DEFAULT NULL
5473) ENGINE=InnoDB;
5474INSERT INTO t2 VALUES (1),(1);
5475CREATE TABLE t4 (
5476a INTEGER DEFAULT NULL
5477) ENGINE=InnoDB;
5478INSERT INTO t4 VALUES (1),(1);
5479CREATE TABLE v (
5480a INTEGER DEFAULT NULL
5481) ENGINE=InnoDB;
5482INSERT INTO v VALUES (1),(1);
5483explain SELECT *
5484FROM t AS t1
5485LEFT JOIN
5486(t2
5487LEFT JOIN t AS t3
5488ON t3.a IN (SELECT a FROM t AS it)
5489JOIN t4
5490ON t4.a=100
5491)
5492ON TRUE
5493WHERE t1.a IN (SELECT * FROM v AS it2);
5494id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
54951	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
54961	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
54971	PRIMARY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
54981	PRIMARY	t4	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
54993	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
55002	SUBQUERY	it	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
5501Warnings:
5502Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a` AS `a`,`test`.`t4`.`a` AS `a` from `test`.`t` `t1` left join (`test`.`t2` left join `test`.`t` `t3` on(<in_optimizer>(`test`.`t3`.`a`,`test`.`t3`.`a` in ( <materialize> (/* select#2 */ select `test`.`it`.`a` from `test`.`t` `it` where 1 ), <primary_index_lookup>(`test`.`t3`.`a` in <temporary table> on <auto_key> where ((`test`.`t3`.`a` = `materialized-subquery`.`a`)))))) join `test`.`t4`) on(((`test`.`t4`.`a` = 100) and TRUE)) where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#3 */ select `test`.`it2`.`a` from `test`.`v` `it2` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
5503SELECT *
5504FROM t AS t1
5505LEFT JOIN
5506(t2
5507LEFT JOIN t AS t3
5508ON t3.a IN (SELECT a FROM t AS it)
5509JOIN t4
5510ON t4.a=100
5511)
5512ON TRUE
5513WHERE t1.a IN (SELECT * FROM v AS it2);
5514a	a	a	a
55151	NULL	NULL	NULL
5516DROP TABLE t,t2,t4,v;
5517# End of WL#5561
5518#
5519# Bug#48868: Left outer join in subquery causes segmentation fault in
5520#            make_join_select.
5521#
5522CREATE TABLE t1 (i INTEGER);
5523INSERT INTO t1 VALUES (1);
5524INSERT INTO t1 VALUES (2);
5525CREATE TABLE t2 (i INTEGER);
5526INSERT INTO t2 VALUES(1);
5527CREATE TABLE t3 (i INTEGER);
5528INSERT INTO t3 VALUES (1);
5529INSERT INTO t3 VALUES (2);
5530SELECT * FROM t1 WHERE (t1.i) IN
5531(SELECT t2.i FROM t2 LEFT JOIN t3 ON t2.i=t3.i);
5532i
55331
5534DROP TABLE t1, t2, t3;
5535
5536Bug#37899: Wrongly checked optimization prerequisite caused failed
5537assertion.
5538
5539CREATE TABLE t1 (
5540`pk` int(11),
5541`varchar_nokey` varchar(5)
5542);
5543INSERT INTO t1 VALUES
5544(1,'qk'),(2,'j'),(3,'aew');
5545SELECT *
5546FROM t1
5547WHERE varchar_nokey IN (
5548SELECT
5549varchar_nokey
5550FROM
5551t1
5552) XOR pk = 30;
5553pk	varchar_nokey
55541	qk
55552	j
55563	aew
5557drop table t1;
5558#
5559# BUG#41842: Semi-join materialization strategy crashes when the upper query has HAVING
5560#
5561CREATE TABLE t1 (
5562pk int(11) NOT NULL AUTO_INCREMENT,
5563int_nokey int(11) NOT NULL,
5564time_key time NOT NULL,
5565datetime_key datetime NOT NULL,
5566datetime_nokey datetime NOT NULL,
5567varchar_key varchar(1) NOT NULL,
5568varchar_nokey varchar(1) NOT NULL,
5569PRIMARY KEY (pk),
5570KEY time_key (time_key),
5571KEY datetime_key (datetime_key),
5572KEY varchar_key (varchar_key)
5573) ENGINE=MyISaM;
5574INSERT INTO t1 VALUES
5575(1,0, '00:16:10','2008-09-03 14:25:40','2008-09-03 14:25:40','h','h'),
5576(2,7, '00:00:00','2001-01-13 00:00:00','2001-01-13 00:00:00','',''),
5577(3,0, '00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','x','x'),
5578(4,2, '16:29:24','2000-10-16 01:39:08','2000-10-16 01:39:08','w','w'),
5579(5,1, '09:23:32','0000-00-00 00:00:00','0000-00-00 00:00:00','p','p'),
5580(6,3, '00:00:00','2007-12-02 00:00:00','2007-12-02 00:00:00','o','o'),
5581(7,3, '00:00:00','2008-09-11 00:00:00','2008-09-11 00:00:00','',''),
5582(8,0, '13:59:04','0000-00-00 00:00:00','0000-00-00 00:00:00','s','s'),
5583(9,7, '09:01:06','0000-00-00 00:00:00','0000-00-00 00:00:00','d','d'),
5584(10,5,'00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','n','n'),
5585(11,0,'21:06:46','0000-00-00 00:00:00','0000-00-00 00:00:00','o','o'),
5586(12,2,'00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','',''),
5587(13,6,'14:45:34','2003-07-28 02:34:08','2003-07-28 02:34:08','w','w'),
5588(14,1,'15:04:12','0000-00-00 00:00:00','0000-00-00 00:00:00','o','o'),
5589(15,0,'00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','x','x'),
5590(16,0,'15:55:23','2004-03-17 00:32:27','2004-03-17 00:32:27','p','p'),
5591(17,1,'16:30:00','2004-12-27 19:20:00','2004-12-27 19:20:00','d','d'),
5592(18,0,'00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','h','h'),
5593(19,0,'14:13:26','2008-11-09 05:53:48','2008-11-09 05:53:48','o','o'),
5594(20,0,'00:00:00','2009-10-11 06:58:04','2009-10-11 06:58:04','k','k');
5595Warnings:
5596Warning	1264	Out of range value for column 'datetime_key' at row 3
5597Warning	1264	Out of range value for column 'datetime_nokey' at row 3
5598Warning	1264	Out of range value for column 'datetime_key' at row 5
5599Warning	1264	Out of range value for column 'datetime_nokey' at row 5
5600Warning	1264	Out of range value for column 'datetime_key' at row 8
5601Warning	1264	Out of range value for column 'datetime_nokey' at row 8
5602Warning	1264	Out of range value for column 'datetime_key' at row 9
5603Warning	1264	Out of range value for column 'datetime_nokey' at row 9
5604Warning	1264	Out of range value for column 'datetime_key' at row 10
5605Warning	1264	Out of range value for column 'datetime_nokey' at row 10
5606Warning	1264	Out of range value for column 'datetime_key' at row 11
5607Warning	1264	Out of range value for column 'datetime_nokey' at row 11
5608Warning	1264	Out of range value for column 'datetime_key' at row 12
5609Warning	1264	Out of range value for column 'datetime_nokey' at row 12
5610Warning	1264	Out of range value for column 'datetime_key' at row 14
5611Warning	1264	Out of range value for column 'datetime_nokey' at row 14
5612Warning	1264	Out of range value for column 'datetime_key' at row 15
5613Warning	1264	Out of range value for column 'datetime_nokey' at row 15
5614Warning	1264	Out of range value for column 'datetime_key' at row 18
5615Warning	1264	Out of range value for column 'datetime_nokey' at row 18
5616CREATE TABLE t2 (
5617pk int(11) NOT NULL AUTO_INCREMENT,
5618int_nokey int(11) NOT NULL,
5619time_key time NOT NULL,
5620datetime_key datetime NOT NULL,
5621datetime_nokey datetime NOT NULL,
5622varchar_key varchar(1) NOT NULL,
5623varchar_nokey varchar(1) NOT NULL,
5624PRIMARY KEY (pk),
5625KEY time_key (time_key),
5626KEY datetime_key (datetime_key),
5627KEY varchar_key (varchar_key)
5628);
5629INSERT IGNORE INTO t2 VALUES
5630(10,0,'19:39:13','0000-00-00 00:00:00','0000-00-00 00:00:00','g','g'),
5631(11,8,'03:43:53','0000-00-00 00:00:00','0000-00-00 00:00:00','b','b');
5632Warnings:
5633Warning	1264	Out of range value for column 'datetime_key' at row 1
5634Warning	1264	Out of range value for column 'datetime_nokey' at row 1
5635Warning	1264	Out of range value for column 'datetime_key' at row 2
5636Warning	1264	Out of range value for column 'datetime_nokey' at row 2
5637SELECT OUTR.datetime_nokey AS X FROM t1 AS OUTR
5638WHERE
5639OUTR.varchar_nokey IN (SELECT
5640INNR . varchar_nokey AS Y
5641FROM t2 AS INNR
5642WHERE
5643INNR . datetime_key >= INNR . time_key OR
5644INNR . pk = INNR . int_nokey
5645)
5646AND OUTR . varchar_nokey <= 'w'
5647HAVING X > '2012-12-12';
5648X
5649drop table t1, t2;
5650
5651Bug#46797 "Crash in fix_semijoin_strategies_for_picked_join_order
5652with semijoin=on"
5653
5654CREATE TABLE t1 (
5655varchar_key varchar(1) DEFAULT NULL,
5656KEY varchar_key (varchar_key)
5657);
5658CREATE TABLE t2 (
5659varchar_key varchar(1) DEFAULT NULL,
5660KEY varchar_key (varchar_key)
5661);
5662INSERT INTO t2 VALUES
5663(NULL),(NULL),(NULL),(NULL),('a'),('a'),('a'),('b'),('b'),('b'),('b'),('c'),
5664('c'),('c'),('c'),('c'),('c'),('c'),('d'),('d'),('d'),('d'),('d'),('d'),('e'),
5665('e'),('e'),('e'),('e'),('e'),('f'),('f'),('f'),('g'),('g'),('h'),('h'),('h'),
5666('h'),('i'),('j'),('j'),('j'),('k'),('k'),('l'),('l'),('m'),('m'),('m'),('m'),
5667('n'),('n'),('n'),('o'),('o'),('o'),('p'),('p'),('p'),('q'),('q'),('q'),('r'),
5668('r'),('r'),('r'),('s'),('s'),('s'),('s'),('t'),('t'),('t'),('t'),('u'),('u'),
5669('u'),('u'),('v'),('v'),('v'),('v'),('w'),('w'),('w'),('w'),('w'),('w'),('x'),
5670('x'),('x'),('y'),('y'),('y'),('y'),('z'),('z'),('z'),('z');
5671CREATE TABLE t3 (
5672varchar_key varchar(1) DEFAULT NULL,
5673KEY varchar_key (varchar_key)
5674) ENGINE=MyISAM DEFAULT CHARSET=latin1;
5675INSERT INTO t3 VALUES
5676(NULL),('c'),('d'),('e'),('f'),('h'),('j'),('k'),('k'),('m'),('m'),('m'),
5677('n'),('o'),('r'),('t'),('t'),('u'),('w'),('y');
5678SELECT varchar_key FROM t3
5679WHERE (SELECT varchar_key FROM t3
5680WHERE (varchar_key,varchar_key)
5681IN (SELECT t1.varchar_key, t2 .varchar_key
5682FROM t1 RIGHT JOIN t2 ON t1.varchar_key
5683)
5684);
5685varchar_key
5686DROP TABLE t1, t2, t3;
5687#
5688# Bug#46556 Returning incorrect, empty results for some IN subqueries
5689#           w/semijoin=on
5690#
5691CREATE TABLE t0 (
5692pk INTEGER,
5693vkey VARCHAR(1),
5694vnokey VARCHAR(1),
5695PRIMARY KEY (pk),
5696KEY vkey(vkey)
5697);
5698INSERT INTO t0
5699VALUES (1,'g','g'), (2,'v','v'), (3,'t','t'), (4,'u','u'), (5,'n','n');
5700EXPLAIN EXTENDED SELECT vkey FROM t0 WHERE pk IN
5701(SELECT t1.pk FROM t0 t1 JOIN t0 t2 ON t2.vkey = t1.vnokey);
5702id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
57031	PRIMARY	t0	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
57042	SUBQUERY	t1	NULL	ALL	PRIMARY	NULL	NULL	NULL	5	100.00	NULL
57052	SUBQUERY	t2	NULL	index	vkey	vkey	4	NULL	5	20.00	Using where; Using index; Using join buffer (Block Nested Loop)
5706Warnings:
5707Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
5708Note	1003	/* select#1 */ select `test`.`t0`.`vkey` AS `vkey` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`pk`,`test`.`t0`.`pk` in ( <materialize> (/* select#2 */ select `test`.`t1`.`pk` from `test`.`t0` `t1` join `test`.`t0` `t2` where (`test`.`t2`.`vkey` = `test`.`t1`.`vnokey`) ), <primary_index_lookup>(`test`.`t0`.`pk` in <temporary table> on <auto_key> where ((`test`.`t0`.`pk` = `materialized-subquery`.`pk`)))))
5709SELECT vkey FROM t0 WHERE pk IN
5710(SELECT t1.pk FROM t0 t1 JOIN t0 t2 ON t2.vkey = t1.vnokey);
5711vkey
5712g
5713v
5714t
5715u
5716n
5717DROP TABLE t0;
5718# End of bug#46556
5719
5720Bug#48834: Procedure with view + subquery + semijoin=on
5721crashes on second call.
5722
5723CREATE TABLE t1 ( t1field integer, primary key (t1field));
5724CREATE TABLE t2 ( t2field integer, primary key (t2field));
5725CREATE VIEW v1 AS
5726SELECT t1field as v1field
5727FROM t1 A
5728WHERE A.t1field IN (SELECT t1field FROM t2 );
5729CREATE VIEW v2 AS
5730SELECT t2field as v2field
5731FROM t2 A
5732WHERE A.t2field IN (SELECT t2field FROM t2 );
5733CREATE PROCEDURE p1 ()
5734BEGIN
5735SELECT v1field
5736FROM v1
5737WHERE v1field IN ( SELECT v2field as vf_inner FROM v2 );
5738END|
5739INSERT INTO t1 VALUES (1),(2),(3);
5740INSERT INTO t2 VALUES (2),(3),(4);
5741CALL p1;
5742v1field
57432
57443
5745CALL p1;
5746v1field
57472
57483
5749DROP TABLE t1,t2;
5750DROP VIEW v1,v2;
5751DROP PROCEDURE p1;
5752# End of BUG#48834
5753#
5754# Bug#46692 "Crash occurring on queries with nested FROM subqueries
5755# using materialization."
5756#
5757CREATE TABLE t1 (
5758pk INTEGER PRIMARY KEY,
5759int_key INTEGER,
5760KEY int_key(int_key)
5761);
5762INSERT INTO t1 VALUES (10,186),(11,NULL),(12,2),(13,3),(14,0),(15,133),(16,1);
5763CREATE TABLE t2 (
5764pk INTEGER PRIMARY KEY,
5765int_key INTEGER,
5766KEY int_key(int_key)
5767);
5768INSERT INTO t2 VALUES (1,7),(2,2);
5769SELECT * FROM t1 WHERE (140, 4) IN
5770(SELECT t2.int_key, t2 .pk FROM t2 STRAIGHT_JOIN t1 ON t2.int_key);
5771pk	int_key
5772DROP TABLE t1, t2;
5773#
5774# Bug#42353 "SELECT ... WHERE oe IN (SELECT w/ LEFT JOIN) query
5775# causes crash."
5776#
5777CREATE TABLE t1 (
5778pk INTEGER PRIMARY KEY,
5779int_nokey INTEGER,
5780int_key INTEGER,
5781date_key DATE,
5782datetime_nokey DATETIME,
5783varchar_nokey VARCHAR(1)
5784);
5785CREATE TABLE t2 (
5786date_nokey DATE
5787);
5788CREATE TABLE t3 (
5789pk INTEGER PRIMARY KEY,
5790int_nokey INTEGER,
5791date_key date,
5792varchar_key VARCHAR(1),
5793varchar_nokey VARCHAR(1),
5794KEY date_key (date_key)
5795);
5796SELECT date_key FROM t1
5797WHERE (int_key, int_nokey)
5798IN (SELECT  t3.int_nokey, t3.pk
5799FROM t2 LEFT JOIN t3 ON (t2.date_nokey < t3.date_key)
5800WHERE t3.varchar_key <= t3.varchar_nokey OR t3.int_nokey <= t3.pk
5801)
5802AND (varchar_nokey <> 'f' OR NOT int_key < 7);
5803date_key
5804#
5805# Bug#45933 "Crash in optimize_semijoin_nests on JOIN in subquery
5806# + AND in outer query".
5807#
5808INSERT INTO t1 VALUES (10,7,5,'2009-06-16','2002-04-10 14:25:30','w'),
5809(11,7,0,'0000-00-00','0000-00-00 00:00:00','s'),
5810(12,4,0,'2003-07-14','2006-09-14 04:01:02','y'),
5811(13,0,4,'2002-07-25','0000-00-00 00:00:00','c'),
5812(14,1,8,'2007-07-03','0000-00-00 00:00:00','q'),
5813(15,6,5,'2001-11-12','0000-00-00 00:00:00',''),
5814(16,2,9,'0000-00-00','0000-00-00 00:00:00','j'),
5815(29,9,1,'0000-00-00','2003-08-11 00:00:00','m');
5816Warnings:
5817Warning	1264	Out of range value for column 'date_key' at row 2
5818Warning	1264	Out of range value for column 'datetime_nokey' at row 2
5819Warning	1264	Out of range value for column 'datetime_nokey' at row 4
5820Warning	1264	Out of range value for column 'datetime_nokey' at row 5
5821Warning	1264	Out of range value for column 'datetime_nokey' at row 6
5822Warning	1264	Out of range value for column 'date_key' at row 7
5823Warning	1264	Out of range value for column 'datetime_nokey' at row 7
5824Warning	1264	Out of range value for column 'date_key' at row 8
5825INSERT IGNORE INTO t3 VALUES (1,9,'0000-00-00','b','b'),
5826(2,2,'2002-09-17','h','h');
5827Warnings:
5828Warning	1264	Out of range value for column 'date_key' at row 1
5829SELECT t1.varchar_nokey FROM t1 JOIN t3 ON t1.datetime_nokey
5830WHERE t1.varchar_nokey
5831IN (SELECT varchar_nokey FROM t1
5832WHERE (pk)
5833IN (SELECT t3.int_nokey
5834FROM t3 LEFT JOIN t1 ON t1.varchar_nokey
5835WHERE t3.date_key BETWEEN '2008-06-07' AND '2006-06-26'
5836           )
5837);
5838varchar_nokey
5839DROP TABLE t1, t2, t3;
5840#
5841# Bug#45219 "Crash on SELECT DISTINCT query containing a
5842# LEFT JOIN in subquery"
5843#
5844CREATE TABLE t1 (
5845pk INTEGER NOT NULL,
5846int_nokey INTEGER NOT NULL,
5847datetime_key DATETIME NOT NULL,
5848varchar_key VARCHAR(1) NOT NULL,
5849PRIMARY KEY (pk),
5850KEY datetime_key (datetime_key),
5851KEY varchar_key (varchar_key)
5852);
5853INSERT IGNORE INTO t1 VALUES
5854(1,9,'0000-00-00 00:00:00','p'),(2,0,'2002-02-09 07:38:13','v'),
5855(3,8,'2001-05-03 12:08:14','t'),(4,3,'0000-00-00 00:00:00','u'),
5856(5,7,'2009-07-28 03:43:30','n'),(6,0,'2009-08-04 00:00:00','l'),
5857(7,1,'0000-00-00 00:00:00','h'),(8,9,'0000-00-00 00:00:00','u'),
5858(9,0,'2005-08-02 17:16:54','n'),(10,9,'2002-12-21 00:00:00','j'),
5859(11,0,'2005-08-15 12:37:35','k'),(12,5,'0000-00-00 00:00:00','e'),
5860(13,0,'2006-03-10 00:00:00','i'),(14,8,'2005-05-16 11:02:36','u'),
5861(15,8,'2008-11-02 00:00:00','n'),(16,5,'2006-03-15 00:00:00','b'),
5862(17,1,'0000-00-00 00:00:00','x'),(18,7,'0000-00-00 00:00:00',''),
5863(19,0,'2008-12-17 20:15:40','q'),(20,9,'0000-00-00 00:00:00','u');
5864Warnings:
5865Warning	1264	Out of range value for column 'datetime_key' at row 1
5866Warning	1264	Out of range value for column 'datetime_key' at row 4
5867Warning	1264	Out of range value for column 'datetime_key' at row 7
5868Warning	1264	Out of range value for column 'datetime_key' at row 8
5869Warning	1264	Out of range value for column 'datetime_key' at row 12
5870Warning	1264	Out of range value for column 'datetime_key' at row 17
5871Warning	1264	Out of range value for column 'datetime_key' at row 18
5872Warning	1264	Out of range value for column 'datetime_key' at row 20
5873CREATE TABLE t2 LIKE t1;
5874INSERT INTO t2 VALUES
5875(10,0,'2006-07-07 07:26:28','q'),(11,5,'2002-09-23 00:00:00','m'),
5876(12,7,'0000-00-00 00:00:00','j'),(13,1,'2006-06-07 00:00:00','z'),
5877(14,8,'2000-09-16 12:15:34','a'),(15,2,'2007-08-05 15:47:52',''),
5878(16,1,'0000-00-00 00:00:00','e'),(17,8,'2005-12-02 19:34:26','t'),
5879(18,5,'0000-00-00 00:00:00','q'),(19,4,'0000-00-00 00:00:00','b'),
5880(20,5,'2007-12-28 00:00:00','w'),(21,3,'2004-08-02 11:48:43','m'),
5881(22,0,'0000-00-00 00:00:00','x'),(23,8,'2004-04-19 12:18:43',''),
5882(24,0,'2009-04-27 00:00:00','w'),(25,4,'2006-10-20 14:52:15','x'),
5883(26,0,'0000-00-00 00:00:00','e'),(27,0,'2002-03-22 11:48:37','e'),
5884(28,2,'0000-00-00 00:00:00','p'),(29,0,'2001-01-04 03:55:07','x');
5885Warnings:
5886Warning	1264	Out of range value for column 'datetime_key' at row 3
5887Warning	1264	Out of range value for column 'datetime_key' at row 7
5888Warning	1264	Out of range value for column 'datetime_key' at row 9
5889Warning	1264	Out of range value for column 'datetime_key' at row 10
5890Warning	1264	Out of range value for column 'datetime_key' at row 13
5891Warning	1264	Out of range value for column 'datetime_key' at row 17
5892Warning	1264	Out of range value for column 'datetime_key' at row 19
5893CREATE TABLE t3 LIKE t1;
5894INSERT INTO t3 VALUES
5895(10,8,'2007-08-19 08:08:38','i'),(11,0,'2000-05-21 03:51:51','');
5896SELECT DISTINCT datetime_key FROM t1
5897WHERE (int_nokey, pk)
5898IN (SELECT t3.pk, t3.pk FROM t2 LEFT JOIN t3 ON t3.varchar_key)
5899AND pk = 9;
5900datetime_key
5901DROP TABLE t1, t2, t3;
5902#
5903# Bug#46550 Azalea returning duplicate results for some IN subqueries
5904# w/ semijoin=on
5905#
5906DROP TABLE IF EXISTS t0, t1, t2;
5907CREATE TABLE t0 (
5908int_key int(11) DEFAULT NULL,
5909varchar_key varchar(1) DEFAULT NULL,
5910varchar_nokey varchar(1) DEFAULT NULL,
5911KEY int_key (int_key),
5912KEY varchar_key (varchar_key,int_key)
5913);
5914INSERT INTO t0 VALUES
5915(1,'m','m'),
5916(40,'h','h'),
5917(1,'r','r'),
5918(1,'h','h'),
5919(9,'x','x'),
5920(NULL,'q','q'),
5921(NULL,'k','k'),
5922(7,'l','l'),
5923(182,'k','k'),
5924(202,'a','a'),
5925(7,'x','x'),
5926(6,'j','j'),
5927(119,'z','z'),
5928(4,'d','d'),
5929(5,'h','h'),
5930(1,'u','u'),
5931(3,'q','q'),
5932(7,'a','a'),
5933(3,'e','e'),
5934(6,'l','l');
5935CREATE TABLE t1 (
5936int_key int(11) DEFAULT NULL,
5937varchar_key varchar(1) DEFAULT NULL,
5938varchar_nokey varchar(1) DEFAULT NULL,
5939KEY int_key (int_key),
5940KEY varchar_key (varchar_key,int_key)
5941);
5942INSERT INTO t1 VALUES (7,NULL,NULL),(4,'x','x');
5943CREATE TABLE t2 (
5944int_key int(11) DEFAULT NULL,
5945varchar_key varchar(1) DEFAULT NULL,
5946varchar_nokey varchar(1) DEFAULT NULL,
5947KEY int_key (int_key),
5948KEY varchar_key (varchar_key,int_key)
5949);
5950INSERT INTO t2 VALUES (123,NULL,NULL);
5951SELECT int_key
5952FROM t0
5953WHERE varchar_nokey  IN (
5954SELECT t1 .varchar_key  from t1
5955);
5956int_key
59579
59587
5959SELECT t0.int_key
5960FROM t0
5961WHERE t0.varchar_nokey  IN (
5962SELECT t1_1 .varchar_key
5963FROM t1 AS t1_1  JOIN t1 AS t1_2 ON t1_1 .int_key
5964);
5965int_key
59669
59677
5968EXPLAIN
5969SELECT t0.int_key
5970FROM t0
5971WHERE t0.varchar_nokey  IN (
5972SELECT t1_1 .varchar_key
5973FROM t1 AS t1_1  JOIN t1 AS t1_2 ON t1_1 .int_key
5974);
5975id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
59761	PRIMARY	t0	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where
59772	SUBQUERY	t1_1	NULL	index	varchar_key	varchar_key	9	NULL	2	50.00	Using where; Using index
59782	SUBQUERY	t1_2	NULL	index	NULL	int_key	5	NULL	2	100.00	Using index; Using join buffer (Block Nested Loop)
5979Warnings:
5980Note	1003	/* select#1 */ select `test`.`t0`.`int_key` AS `int_key` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`varchar_nokey`,`test`.`t0`.`varchar_nokey` in ( <materialize> (/* select#2 */ select `test`.`t1_1`.`varchar_key` from `test`.`t1` `t1_1` join `test`.`t1` `t1_2` where `test`.`t1_1`.`int_key` ), <primary_index_lookup>(`test`.`t0`.`varchar_nokey` in <temporary table> on <auto_key> where ((`test`.`t0`.`varchar_nokey` = `materialized-subquery`.`varchar_key`)))))
5981SELECT t0.int_key
5982FROM t0, t2
5983WHERE t0.varchar_nokey  IN (
5984SELECT t1_1 .varchar_key
5985FROM t1 AS t1_1  JOIN t1 AS t1_2 ON t1_1 .int_key
5986);
5987int_key
59889
59897
5990EXPLAIN
5991SELECT t0.int_key
5992FROM t0, t2
5993WHERE t0.varchar_nokey  IN (
5994SELECT t1_1 .varchar_key
5995FROM t1 AS t1_1  JOIN t1 AS t1_2 ON t1_1 .int_key
5996);
5997id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
59981	PRIMARY	t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
59991	PRIMARY	t0	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where
60002	SUBQUERY	t1_1	NULL	index	varchar_key	varchar_key	9	NULL	2	50.00	Using where; Using index
60012	SUBQUERY	t1_2	NULL	index	NULL	int_key	5	NULL	2	100.00	Using index; Using join buffer (Block Nested Loop)
6002Warnings:
6003Note	1003	/* select#1 */ select `test`.`t0`.`int_key` AS `int_key` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`varchar_nokey`,`test`.`t0`.`varchar_nokey` in ( <materialize> (/* select#2 */ select `test`.`t1_1`.`varchar_key` from `test`.`t1` `t1_1` join `test`.`t1` `t1_2` where `test`.`t1_1`.`int_key` ), <primary_index_lookup>(`test`.`t0`.`varchar_nokey` in <temporary table> on <auto_key> where ((`test`.`t0`.`varchar_nokey` = `materialized-subquery`.`varchar_key`)))))
6004DROP TABLE t0, t1, t2;
6005# End of bug#46550
6006
6007Bug #48073 Subquery on char columns from view crashes Mysql
6008
6009DROP TABLE IF EXISTS t1, t2;
6010DROP VIEW IF EXISTS v1;
6011CREATE TABLE t1 (
6012city VARCHAR(50) NOT NULL,
6013country_id SMALLINT UNSIGNED NOT NULL
6014);
6015INSERT INTO t1 VALUES
6016('Batna',2),
6017('Bchar',2),
6018('Skikda',2),
6019('Tafuna',3),
6020('Algeria',2) ;
6021CREATE TABLE t2 (
6022country_id SMALLINT UNSIGNED NOT NULL,
6023country VARCHAR(50) NOT NULL
6024);
6025INSERT INTO t2 VALUES
6026(2,'Algeria'),
6027(3,'American Samoa') ;
6028CREATE VIEW v1 AS
6029SELECT country_id, country
6030FROM t2
6031WHERE LEFT(country,1) = "A"
6032;
6033SELECT city, country_id
6034FROM t1
6035WHERE city IN (
6036SELECT country
6037FROM t2
6038WHERE LEFT(country, 1) = "A"
6039);
6040city	country_id
6041Algeria	2
6042SELECT city, country_id
6043FROM t1
6044WHERE city IN (
6045SELECT country
6046FROM v1
6047);
6048city	country_id
6049Algeria	2
6050drop table t1, t2;
6051drop view v1;
6052# End of bug#48073
6053
6054Bug#49097 subquery with view generates wrong result with
6055non-prepared statement
6056
6057DROP TABLE IF EXISTS t1, t2;
6058DROP VIEW IF EXISTS v1;
6059CREATE TABLE t1 (
6060city VARCHAR(50) NOT NULL,
6061country_id SMALLINT UNSIGNED NOT NULL
6062);
6063INSERT INTO t1 VALUES
6064('Batna',2),
6065('Bchar',2),
6066('Skikda',2),
6067('Tafuna',3),
6068('Algeria',2) ;
6069CREATE TABLE t2 (
6070country_id SMALLINT UNSIGNED NOT NULL,
6071country VARCHAR(50) NOT NULL
6072);
6073INSERT INTO t2 VALUES
6074(2,'Algeria'),
6075(3,'XAmerican Samoa') ;
6076CREATE VIEW v1 AS
6077SELECT country_id, country
6078FROM t2
6079WHERE LEFT(country,1) = "A"
6080;
6081SELECT city, country_id
6082FROM t1
6083WHERE country_id IN (
6084SELECT country_id
6085FROM t2
6086WHERE LEFT(country,1) = "A"
6087);
6088city	country_id
6089Batna	2
6090Bchar	2
6091Skikda	2
6092Algeria	2
6093SELECT city, country_id
6094FROM t1
6095WHERE country_id IN (
6096SELECT country_id
6097FROM v1
6098);
6099city	country_id
6100Batna	2
6101Bchar	2
6102Skikda	2
6103Algeria	2
6104PREPARE stmt FROM
6105"
6106SELECT city, country_id
6107FROM t1
6108WHERE country_id IN (
6109  SELECT country_id
6110  FROM v1
6111);
6112";
6113execute stmt;
6114city	country_id
6115Batna	2
6116Bchar	2
6117Skikda	2
6118Algeria	2
6119deallocate prepare stmt;
6120drop table t1, t2;
6121drop view v1;
6122# End of Bug#49097
6123#
6124# Bug#49198 Wrong result for second call of procedure
6125#           with view in subselect.
6126#
6127CREATE TABLE t1 (t1field integer, primary key (t1field));
6128CREATE TABLE t2 (t2field integer, primary key (t2field));
6129CREATE TABLE t3 (t3field integer, primary key (t3field));
6130CREATE VIEW v2 AS SELECT * FROM t2;
6131CREATE VIEW v3 AS SELECT * FROM t3;
6132INSERT INTO t1 VALUES(1),(2);
6133INSERT INTO t2 VALUES(1),(2);
6134INSERT INTO t3 VALUES(1),(2);
6135PREPARE stmt FROM
6136"
6137SELECT t1field
6138FROM t1
6139WHERE t1field IN (SELECT * FROM v2);
6140";
6141EXECUTE stmt;
6142t1field
61431
61442
6145EXECUTE stmt;
6146t1field
61471
61482
6149PREPARE stmt FROM
6150"
6151EXPLAIN
6152SELECT t1field
6153FROM t1
6154WHERE t1field IN (SELECT * FROM v2)
6155  AND t1field IN (SELECT * FROM v3)
6156";
6157EXECUTE stmt;
6158id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
61591	PRIMARY	t1	NULL	index	NULL	PRIMARY	4	NULL	2	100.00	Using where; Using index
61603	SUBQUERY	t3	NULL	index	PRIMARY	PRIMARY	4	NULL	2	100.00	Using index
61612	SUBQUERY	t2	NULL	index	PRIMARY	PRIMARY	4	NULL	2	100.00	Using index
6162Warnings:
6163Note	1003	/* select#1 */ select `test`.`t1`.`t1field` AS `t1field` from `test`.`t1` where (<in_optimizer>(`test`.`t1`.`t1field`,`test`.`t1`.`t1field` in ( <materialize> (/* select#2 */ select `test`.`t2`.`t2field` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`t1field` in <temporary table> on <auto_key> where ((`test`.`t1`.`t1field` = `materialized-subquery`.`t2field`))))) and <in_optimizer>(`test`.`t1`.`t1field`,`test`.`t1`.`t1field` in ( <materialize> (/* select#3 */ select `test`.`t3`.`t3field` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`t1field` in <temporary table> on <auto_key> where ((`test`.`t1`.`t1field` = `materialized-subquery`.`t3field`))))))
6164EXECUTE stmt;
6165id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
61661	PRIMARY	t1	NULL	index	NULL	PRIMARY	4	NULL	2	100.00	Using where; Using index
61673	SUBQUERY	t3	NULL	index	PRIMARY	PRIMARY	4	NULL	2	100.00	Using index
61682	SUBQUERY	t2	NULL	index	PRIMARY	PRIMARY	4	NULL	2	100.00	Using index
6169Warnings:
6170Note	1003	/* select#1 */ select `test`.`t1`.`t1field` AS `t1field` from `test`.`t1` where (<in_optimizer>(`test`.`t1`.`t1field`,`test`.`t1`.`t1field` in ( <materialize> (/* select#2 */ select `test`.`t2`.`t2field` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`t1field` in <temporary table> on <auto_key> where ((`test`.`t1`.`t1field` = `materialized-subquery`.`t2field`))))) and <in_optimizer>(`test`.`t1`.`t1field`,`test`.`t1`.`t1field` in ( <materialize> (/* select#3 */ select `test`.`t3`.`t3field` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`t1field` in <temporary table> on <auto_key> where ((`test`.`t1`.`t1field` = `materialized-subquery`.`t3field`))))))
6171DROP TABLE t1, t2, t3;
6172DROP VIEW v2, v3;
6173# End of Bug#49198
6174#
6175# Bug#48623 Multiple subqueries are optimized incorrectly
6176#
6177CREATE TABLE ot(val VARCHAR(10));
6178CREATE TABLE it1(val VARCHAR(10));
6179CREATE TABLE it2(val VARCHAR(10));
6180INSERT INTO ot  VALUES('aaa'), ('bbb'), ('eee'), ('mmm'), ('ppp');
6181INSERT INTO it1 VALUES('aaa'), ('aaa'), ('bbb'), ('eee'), ('mmm'), ('ppp');
6182INSERT INTO it2 VALUES('aaa'), ('bbb'), ('eee'), ('mmm'), ('ppp');
6183EXPLAIN
6184SELECT *
6185FROM ot
6186WHERE ot.val IN (SELECT it1.val FROM it1
6187WHERE  it1.val LIKE 'a%' OR it1.val LIKE 'e%')
6188AND ot.val IN (SELECT it2.val FROM it2
6189WHERE  it2.val LIKE 'a%' OR it2.val LIKE 'e%');
6190id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
61911	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
61923	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	5	36.00	Using where
61932	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	6	30.56	Using where
6194Warnings:
6195Note	1003	/* select#1 */ select `test`.`ot`.`val` AS `val` from `test`.`ot` where (<in_optimizer>(`test`.`ot`.`val`,`test`.`ot`.`val` in ( <materialize> (/* select#2 */ select `test`.`it1`.`val` from `test`.`it1` where ((`test`.`it1`.`val` like 'a%') or (`test`.`it1`.`val` like 'e%')) ), <primary_index_lookup>(`test`.`ot`.`val` in <temporary table> on <auto_key> where ((`test`.`ot`.`val` = `materialized-subquery`.`val`))))) and <in_optimizer>(`test`.`ot`.`val`,`test`.`ot`.`val` in ( <materialize> (/* select#3 */ select `test`.`it2`.`val` from `test`.`it2` where ((`test`.`it2`.`val` like 'a%') or (`test`.`it2`.`val` like 'e%')) ), <primary_index_lookup>(`test`.`ot`.`val` in <temporary table> on <auto_key> where ((`test`.`ot`.`val` = `materialized-subquery`.`val`))))))
6196SELECT *
6197FROM ot
6198WHERE ot.val IN (SELECT it1.val FROM it1
6199WHERE  it1.val LIKE 'a%' OR it1.val LIKE 'e%')
6200AND ot.val IN (SELECT it2.val FROM it2
6201WHERE  it2.val LIKE 'a%' OR it2.val LIKE 'e%');
6202val
6203aaa
6204eee
6205DROP TABLE ot;
6206DROP TABLE it1;
6207DROP TABLE it2;
6208# End of Bug#48623
6209#
6210# Bug #51487 Assertion failure when semi-join flattening occurs
6211#            for a subquery in HAVING
6212#
6213CREATE TABLE t1 (a INT, b INT);
6214INSERT INTO t1 VALUES (1,10),(2,11),(1,13);
6215CREATE TABLE t2 AS SELECT * FROM t1;
6216CREATE TABLE t3 AS SELECT * FROM t1;
6217SELECT COUNT(*) FROM t1
6218GROUP BY t1.a
6219HAVING t1.a IN (SELECT t3.a FROM t3
6220WHERE t3.b IN (SELECT b FROM t2 WHERE t2.a=t1.a));
6221COUNT(*)
62222
62231
6224DROP TABLE t1, t2, t3;
6225# End of Bug#51487
6226#
6227# BUG#38075: Wrong result: rows matching a subquery with outer join not returned
6228#
6229DROP TABLE IF EXISTS ot1, it1, it2;
6230CREATE TABLE it2 (
6231int_key int(11) NOT NULL,
6232datetime_key datetime NOT NULL,
6233KEY int_key (int_key),
6234KEY datetime_key (datetime_key)
6235);
6236INSERT INTO it2 VALUES
6237(5,'2002-04-10 14:25:30'), (0,'0000-00-00 00:00:00'),
6238(0,'2006-09-14 04:01:02'), (4,'0000-00-00 00:00:00'),
6239(8,'0000-00-00 00:00:00'), (5,'0000-00-00 00:00:00'),
6240(9,'0000-00-00 00:00:00'), (8,'2007-04-01 11:04:17'),
6241(1,'0000-00-00 00:00:00'), (7,'2009-01-12 00:00:00'),
6242(0,'2009-06-05 00:00:00'), (3,'2006-02-14 18:06:35'),
6243(5,'2006-02-21 07:08:16'), (0,'0000-00-00 00:00:00'),
6244(7,'0000-00-00 00:00:00'), (0,'0000-00-00 00:00:00'),
6245(0,'2007-02-13 00:00:00'), (1,'0000-00-00 00:00:00'),
6246(0,'0000-00-00 00:00:00'), (1,'2003-08-11 00:00:00');
6247Warnings:
6248Warning	1264	Out of range value for column 'datetime_key' at row 2
6249Warning	1264	Out of range value for column 'datetime_key' at row 4
6250Warning	1264	Out of range value for column 'datetime_key' at row 5
6251Warning	1264	Out of range value for column 'datetime_key' at row 6
6252Warning	1264	Out of range value for column 'datetime_key' at row 7
6253Warning	1264	Out of range value for column 'datetime_key' at row 9
6254Warning	1264	Out of range value for column 'datetime_key' at row 14
6255Warning	1264	Out of range value for column 'datetime_key' at row 15
6256Warning	1264	Out of range value for column 'datetime_key' at row 16
6257Warning	1264	Out of range value for column 'datetime_key' at row 18
6258Warning	1264	Out of range value for column 'datetime_key' at row 19
6259CREATE TABLE ot1 (
6260int_nokey int(11) NOT NULL,
6261int_key int(11) NOT NULL,
6262KEY int_key (int_key)
6263);
6264INSERT INTO ot1 VALUES
6265(5,0), (3,0), (0,2), (3,0), (1,3), (0,0), (1,7), (7,0), (1,7), (0,7),
6266(0,9), (8,2), (4,4), (9,3), (0,9), (2,5), (0,5), (8,0), (5,8), (1,5);
6267CREATE TABLE it1 (
6268int_nokey int(11) NOT NULL,
6269int_key int(11) NOT NULL,
6270KEY int_key (int_key)
6271);
6272INSERT INTO it1 VALUES
6273(9,5), (0,4);
6274SELECT int_key FROM ot1
6275WHERE int_nokey IN (SELECT it2.int_key
6276FROM it1 LEFT JOIN it2 ON it2.datetime_key);
6277int_key
62780
62790
62800
62810
62820
62830
62842
62852
62863
62875
62885
62897
62907
62917
62928
62939
62949
6295EXPLAIN
6296SELECT int_key FROM ot1
6297WHERE int_nokey IN (SELECT it2.int_key
6298FROM it1 LEFT JOIN it2 ON it2.datetime_key);
6299id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
63001	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where
63012	SUBQUERY	it1	NULL	index	NULL	int_key	4	NULL	2	100.00	Using index
63022	SUBQUERY	it2	NULL	ALL	int_key	NULL	NULL	NULL	20	90.00	Using where; Using join buffer (Block Nested Loop)
6303Warnings:
6304Note	1003	/* select#1 */ select `test`.`ot1`.`int_key` AS `int_key` from `test`.`ot1` where <in_optimizer>(`test`.`ot1`.`int_nokey`,`test`.`ot1`.`int_nokey` in ( <materialize> (/* select#2 */ select `test`.`it2`.`int_key` from `test`.`it1` join `test`.`it2` where `test`.`it2`.`datetime_key` ), <primary_index_lookup>(`test`.`ot1`.`int_nokey` in <temporary table> on <auto_key> where ((`test`.`ot1`.`int_nokey` = `materialized-subquery`.`int_key`)))))
6305DROP TABLE ot1, it1, it2;
6306# End of BUG#38075
6307#
6308# BUG#50089: Second call of procedure with view in subselect crashes server
6309#
6310CREATE TABLE t1(t1field INTEGER, PRIMARY KEY(t1field));
6311CREATE VIEW v1 AS
6312SELECT t1field AS v1field
6313FROM t1 a
6314WHERE a.t1field IN (SELECT t1field FROM t1);
6315INSERT INTO t1 VALUES(1),(2);
6316SELECT t1field
6317FROM t1
6318WHERE t1field IN (SELECT v1field FROM v1);
6319t1field
63201
63212
6322EXPLAIN
6323SELECT t1field
6324FROM t1
6325WHERE t1field IN (SELECT v1field FROM v1);
6326id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
63271	PRIMARY	t1	NULL	index	NULL	PRIMARY	4	NULL	2	100.00	Using where; Using index
63282	SUBQUERY	a	NULL	index	PRIMARY	PRIMARY	4	NULL	2	100.00	Using where; Using index
63294	SUBQUERY	t1	NULL	index	PRIMARY	PRIMARY	4	NULL	2	100.00	Using index
6330Warnings:
6331Note	1003	/* select#1 */ select `t1`.`t1field` AS `t1field` from `test`.`t1` where <in_optimizer>(`t1`.`t1field`,`t1`.`t1field` in ( <materialize> (/* select#2 */ select `test`.`a`.`t1field` from `test`.`t1` `a` where <in_optimizer>(`test`.`a`.`t1field`,`test`.`a`.`t1field` in ( <materialize> (/* select#4 */ select `test`.`t1`.`t1field` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`a`.`t1field` in <temporary table> on <auto_key> where ((`test`.`a`.`t1field` = `materialized-subquery`.`t1field`))))) ), <primary_index_lookup>(`t1`.`t1field` in <temporary table> on <auto_key> where ((`t1`.`t1field` = `materialized-subquery`.`v1field`)))))
6332SELECT t1.t1field
6333FROM t1 LEFT JOIN t1 AS t2 ON t1.t1field IN (SELECT v1field FROM v1);
6334t1field
63351
63361
63372
63382
6339EXPLAIN
6340SELECT t1field
6341FROM t1
6342WHERE t1field IN (SELECT v1field FROM v1);
6343id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
63441	PRIMARY	t1	NULL	index	NULL	PRIMARY	4	NULL	2	100.00	Using where; Using index
63452	SUBQUERY	a	NULL	index	PRIMARY	PRIMARY	4	NULL	2	100.00	Using where; Using index
63464	SUBQUERY	t1	NULL	index	PRIMARY	PRIMARY	4	NULL	2	100.00	Using index
6347Warnings:
6348Note	1003	/* select#1 */ select `t1`.`t1field` AS `t1field` from `test`.`t1` where <in_optimizer>(`t1`.`t1field`,`t1`.`t1field` in ( <materialize> (/* select#2 */ select `test`.`a`.`t1field` from `test`.`t1` `a` where <in_optimizer>(`test`.`a`.`t1field`,`test`.`a`.`t1field` in ( <materialize> (/* select#4 */ select `test`.`t1`.`t1field` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`a`.`t1field` in <temporary table> on <auto_key> where ((`test`.`a`.`t1field` = `materialized-subquery`.`t1field`))))) ), <primary_index_lookup>(`t1`.`t1field` in <temporary table> on <auto_key> where ((`t1`.`t1field` = `materialized-subquery`.`v1field`)))))
6349CREATE PROCEDURE p1()
6350BEGIN
6351SELECT t1field
6352FROM t1
6353WHERE t1field IN (SELECT v1field FROM v1);
6354END|
6355CALL p1;
6356t1field
63571
63582
6359CALL p1;
6360t1field
63611
63622
6363PREPARE stmt FROM
6364"
6365SELECT t1field
6366FROM t1
6367WHERE t1field IN (SELECT v1field FROM v1);
6368";
6369EXECUTE stmt;
6370t1field
63711
63722
6373EXECUTE stmt;
6374t1field
63751
63762
6377DROP PROCEDURE p1;
6378DROP VIEW v1;
6379DROP TABLE t1;
6380# End of BUG#50089
6381#
6382# Bug#45191: Incorrectly initialized semi-join led to a wrong result.
6383#
6384CREATE TABLE staff (EMPNUM   CHAR(3) NOT NULL,
6385EMPNAME  CHAR(20), GRADE DECIMAL(4), CITY CHAR(15));
6386CREATE TABLE proj (PNUM CHAR(3) NOT NULL,
6387PNAME    CHAR(20), PTYPE CHAR(6),
6388BUDGET   DECIMAL(9),
6389CITY     CHAR(15));
6390CREATE TABLE works (EMPNUM CHAR(3) NOT NULL,
6391PNUM CHAR(3) NOT NULL, HOURS DECIMAL(5));
6392INSERT INTO staff VALUES ('E1','Alice',12,'Deale');
6393INSERT INTO staff VALUES ('E2','Betty',10,'Vienna');
6394INSERT INTO staff VALUES ('E3','Carmen',13,'Vienna');
6395INSERT INTO staff VALUES ('E4','Don',12,'Deale');
6396INSERT INTO staff VALUES ('E5','Ed',13,'Akron');
6397INSERT INTO proj VALUES  ('P1','MXSS','Design',10000,'Deale');
6398INSERT INTO proj VALUES  ('P2','CALM','Code',30000,'Vienna');
6399INSERT INTO proj VALUES  ('P3','SDP','Test',30000,'Tampa');
6400INSERT INTO proj VALUES  ('P4','SDP','Design',20000,'Deale');
6401INSERT INTO proj VALUES  ('P5','IRM','Test',10000,'Vienna');
6402INSERT INTO proj VALUES  ('P6','PAYR','Design',50000,'Deale');
6403INSERT INTO works VALUES  ('E1','P1',40);
6404INSERT INTO works VALUES  ('E1','P2',20);
6405INSERT INTO works VALUES  ('E1','P3',80);
6406INSERT INTO works VALUES  ('E1','P4',20);
6407INSERT INTO works VALUES  ('E1','P5',12);
6408INSERT INTO works VALUES  ('E1','P6',12);
6409INSERT INTO works VALUES  ('E2','P1',40);
6410INSERT INTO works VALUES  ('E2','P2',80);
6411INSERT INTO works VALUES  ('E3','P2',20);
6412INSERT INTO works VALUES  ('E4','P2',20);
6413INSERT INTO works VALUES  ('E4','P4',40);
6414INSERT INTO works VALUES  ('E4','P5',80);
6415explain SELECT EMPNUM, EMPNAME
6416FROM staff
6417WHERE EMPNUM IN
6418(SELECT EMPNUM  FROM works
6419WHERE PNUM IN
6420(SELECT PNUM  FROM proj));
6421id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
64221	PRIMARY	staff	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
64232	SUBQUERY	works	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
64243	SUBQUERY	proj	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
6425Warnings:
6426Note	1003	/* select#1 */ select `test`.`staff`.`EMPNUM` AS `EMPNUM`,`test`.`staff`.`EMPNAME` AS `EMPNAME` from `test`.`staff` where <in_optimizer>(`test`.`staff`.`EMPNUM`,`test`.`staff`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`works`.`EMPNUM` from `test`.`works` where <in_optimizer>(`test`.`works`.`PNUM`,`test`.`works`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`proj`.`PNUM` from `test`.`proj` where 1 ), <primary_index_lookup>(`test`.`works`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`works`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`staff`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`staff`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6427SELECT EMPNUM, EMPNAME
6428FROM staff
6429WHERE EMPNUM IN
6430(SELECT EMPNUM  FROM works
6431WHERE PNUM IN
6432(SELECT PNUM  FROM proj));
6433EMPNUM	EMPNAME
6434E1	Alice
6435E2	Betty
6436E3	Carmen
6437E4	Don
6438drop table staff,works,proj;
6439# End of bug#45191
6440#
6441# BUG#36896: Server crash on SELECT FROM DUAL
6442#
6443create table t1 (a int);
6444select 1 as res from dual where (1) in (select * from t1);
6445res
6446drop table t1;
6447
6448BUG#40118 Crash when running Batched Key Access and requiring one match for each key
6449
6450create table t0(a int);
6451insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
6452create table t1 (a int, key(a));
6453insert into t1 select * from t0;
6454alter table t1 add b int not null, add filler char(200);
6455insert into t1 select * from t1;
6456insert into t1 select * from t1;
6457select * from t0 where t0.a in (select t1.a from t1 where t1.b=0);
6458a
64590
64601
64612
64623
64634
64645
64656
64667
64678
64689
6469drop table t0, t1;
6470#
6471# BUG#32665 Query with dependent subquery is too slow
6472#
6473create table t1 (
6474idIndividual int primary key
6475);
6476insert into t1 values (1),(2);
6477create table t2 (
6478idContact int primary key,
6479contactType int,
6480idObj int
6481);
6482insert into t2 values (1,1,1),(2,2,2),(3,3,3);
6483create table t3 (
6484idAddress int primary key,
6485idContact int,
6486postalStripped varchar(100)
6487);
6488insert into t3 values (1,1, 'foo'), (2,2,'bar');
6489The following must be converted to a semi-join:
6490explain extended SELECT a.idIndividual FROM t1 a
6491WHERE a.idIndividual IN
6492(	SELECT c.idObj FROM t3 cona
6493INNER JOIN t2 c ON c.idContact=cona.idContact
6494WHERE cona.postalStripped='T2H3B2'
6495	);
6496id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
64971	PRIMARY	a	NULL	index	NULL	PRIMARY	4	NULL	2	100.00	Using where; Using index
64982	SUBQUERY	cona	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
64992	SUBQUERY	c	NULL	eq_ref	PRIMARY	PRIMARY	4	test.cona.idContact	1	100.00	NULL
6500Warnings:
6501Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
6502Note	1003	/* select#1 */ select `test`.`a`.`idIndividual` AS `idIndividual` from `test`.`t1` `a` where <in_optimizer>(`test`.`a`.`idIndividual`,`test`.`a`.`idIndividual` in ( <materialize> (/* select#2 */ select `test`.`c`.`idObj` from `test`.`t3` `cona` join `test`.`t2` `c` where ((`test`.`c`.`idContact` = `test`.`cona`.`idContact`) and (`test`.`cona`.`postalStripped` = 'T2H3B2')) ), <primary_index_lookup>(`test`.`a`.`idIndividual` in <temporary table> on <auto_key> where ((`test`.`a`.`idIndividual` = `materialized-subquery`.`idObj`)))))
6503drop table t1,t2,t3;
6504CREATE TABLE t1 (one int, two int, flag char(1));
6505CREATE TABLE t2 (one int, two int, flag char(1));
6506INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
6507INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
6508SELECT * FROM t1
6509WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t2 WHERE flag = 'N');
6510one	two	flag
65115	6	N
65127	8	N
6513SELECT * FROM t1
6514WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t1 WHERE flag = 'N');
6515one	two	flag
65165	6	N
65177	8	N
6518insert into t2 values (null,null,'N');
6519insert into t2 values (null,3,'0');
6520insert into t2 values (null,5,'0');
6521insert into t2 values (10,null,'0');
6522insert into t1 values (10,3,'0');
6523insert into t1 values (10,5,'0');
6524insert into t1 values (10,10,'0');
6525SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as 'test' from t1;
6526one	two	test
65271	2	NULL
65282	3	NULL
65293	4	NULL
65305	6	1
65317	8	1
653210	3	NULL
653310	5	NULL
653410	10	NULL
6535SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
6536one	two
65375	6
65387	8
6539SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N' group by one,two) as 'test' from t1;
6540one	two	test
65411	2	NULL
65422	3	NULL
65433	4	NULL
65445	6	1
65457	8	1
654610	3	NULL
654710	5	NULL
654810	10	NULL
6549SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
6550one	two	test
65511	2	0
65522	3	NULL
65533	4	0
65545	6	0
65557	8	0
655610	3	NULL
655710	5	NULL
655810	10	NULL
6559SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
6560one	two	test
65611	2	0
65622	3	NULL
65633	4	0
65645	6	0
65657	8	0
656610	3	NULL
656710	5	NULL
656810	10	NULL
6569explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
6570id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
65711	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
65722	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
6573Warnings:
6574Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
6575Note	1003	/* select#1 */ select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and <if>(outer_field_is_not_null, ((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)), true) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)), true)) having (<if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`one`), true) and <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`two`), true)))) AS `test` from `test`.`t1`
6576explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
6577id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
65781	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	Using where
65792	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
6580Warnings:
6581Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
6582Note	1003	/* select#1 */ select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),(`test`.`t1`.`one`,`test`.`t1`.`two`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where (`test`.`t2`.`flag` = 'N') ), <primary_index_lookup>(`test`.`t1`.`one` in <temporary table> on <auto_key> where ((`test`.`t1`.`one` = `materialized-subquery`.`one`) and (`test`.`t1`.`two` = `materialized-subquery`.`two`)))))
6583explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
6584id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
65851	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
65862	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
6587Warnings:
6588Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
6589Note	1003	/* select#1 */ select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and <if>(outer_field_is_not_null, ((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)), true) and <if>(outer_field_is_not_null, ((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)), true)) having (<if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`one`), true) and <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`two`), true)))) AS `test` from `test`.`t1`
6590DROP TABLE t1,t2;
6591CREATE TABLE t1 (a char(5), b char(5));
6592INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
6593SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb'));
6594a	b
6595aaa	aaa
6596DROP TABLE t1;
6597CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
6598INSERT INTO t1 VALUES ('a', 'aa');
6599INSERT INTO t1 VALUES ('a', 'aaa');
6600SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
6601a	b
6602CREATE INDEX I1 ON t1 (a);
6603CREATE INDEX I2 ON t1 (b);
6604EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
6605id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
66061	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
66072	SUBQUERY	t1	NULL	index	I1	I1	2	NULL	2	100.00	Using index
6608Warnings:
6609Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`b`,`test`.`t1`.`b` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`t1`.`b` in <temporary table> on <auto_key> where ((`test`.`t1`.`b` = `materialized-subquery`.`a`)))))
6610SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
6611a	b
6612CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10));
6613INSERT INTO t2 SELECT * FROM t1;
6614CREATE INDEX I1 ON t2 (a);
6615CREATE INDEX I2 ON t2 (b);
6616EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
6617id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
66181	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
66192	SUBQUERY	t2	NULL	index	I1	I1	4	NULL	2	100.00	Using index
6620Warnings:
6621Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`b`,`test`.`t2`.`b` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t2`.`b` in <temporary table> on <auto_key> where ((`test`.`t2`.`b` = `materialized-subquery`.`a`)))))
6622SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
6623a	b
6624EXPLAIN
6625SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
6626id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
66271	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
66282	SUBQUERY	t1	NULL	index	I1	I1	2	NULL	2	100.00	Using where; Using index
6629Warnings:
6630Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`b`,`test`.`t1`.`b` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where (length(`test`.`t1`.`a`) < 500) ), <primary_index_lookup>(`test`.`t1`.`b` in <temporary table> on <auto_key> where ((`test`.`t1`.`b` = `materialized-subquery`.`a`)))))
6631SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
6632a	b
6633DROP TABLE t1,t2;
6634#
6635# BUG#45928 "Differing query results depending on MRR and
6636# engine_condition_pushdown settings"
6637#
6638CREATE TABLE `t1` (
6639`pk` int(11) NOT NULL AUTO_INCREMENT,
6640`time_nokey` time NOT NULL,
6641`varchar_key` varchar(1) NOT NULL,
6642`varchar_nokey` varchar(1) NOT NULL,
6643PRIMARY KEY (`pk`),
6644KEY `varchar_key` (`varchar_key`)
6645) AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;
6646INSERT INTO `t1` VALUES (10,'00:00:00','i','i'),(11,'00:00:00','','');
6647SELECT `time_nokey` G1  FROM t1  WHERE ( `varchar_nokey`  , `varchar_key`  )  IN (
6648SELECT `varchar_nokey`  , `varchar_nokey`  )  AND `varchar_key`  >= 'c' HAVING G1  ORDER
6649BY `pk`   ;
6650G1
6651DROP TABLE t1;
6652#
6653# BUG#45863 "Assertion failed: (fixed == 0), function fix_fields(),
6654#            file item.cc, line 4448"
6655#
6656DROP TABLE IF EXISTS C, BB;
6657CREATE TABLE C (
6658varchar_nokey varchar(1) NOT NULL
6659);
6660INSERT INTO C VALUES
6661('k'),('a'),(''),('u'),('e'),('v'),('i'),
6662('t'),('u'),('f'),('u'),('m'),('j'),('f'),
6663('v'),('j'),('g'),('e'),('h'),('z');
6664CREATE TABLE BB (
6665varchar_nokey varchar(1) NOT NULL
6666);
6667INSERT INTO BB VALUES ('i'),('t');
6668SELECT varchar_nokey FROM C
6669WHERE (varchar_nokey, OUTR) IN (SELECT varchar_nokey
6670FROM BB);
6671ERROR 42S22: Unknown column 'OUTR' in 'IN/ALL/ANY subquery'
6672SELECT varchar_nokey FROM C
6673WHERE (varchar_nokey, OUTR) IN (SELECT varchar_nokey, varchar_nokey
6674FROM BB);
6675ERROR 42S22: Unknown column 'OUTR' in 'IN/ALL/ANY subquery'
6676DROP TABLE C,BB;
6677#
6678# During work with BUG#45863 I had problems with a query that was
6679# optimized differently in regular and prepared mode.
6680# Because there was a bug in one of the selected strategies, I became
6681# aware of the problem. Adding an EXPLAIN query to catch this.
6682DROP TABLE IF EXISTS t1, t2, t3;
6683CREATE TABLE t1
6684(EMPNUM   CHAR(3) NOT NULL,
6685EMPNAME  CHAR(20),
6686GRADE    DECIMAL(4),
6687CITY     CHAR(15));
6688CREATE TABLE t2
6689(PNUM     CHAR(3) NOT NULL,
6690PNAME    CHAR(20),
6691PTYPE    CHAR(6),
6692BUDGET   DECIMAL(9),
6693CITY     CHAR(15));
6694CREATE TABLE t3
6695(EMPNUM   CHAR(3) NOT NULL,
6696PNUM     CHAR(3) NOT NULL,
6697HOURS    DECIMAL(5));
6698INSERT INTO t1 VALUES ('E1','Alice',12,'Deale');
6699INSERT INTO t1 VALUES ('E2','Betty',10,'Vienna');
6700INSERT INTO t1 VALUES ('E3','Carmen',13,'Vienna');
6701INSERT INTO t1 VALUES ('E4','Don',12,'Deale');
6702INSERT INTO t1 VALUES ('E5','Ed',13,'Akron');
6703INSERT INTO t2 VALUES ('P1','MXSS','Design',10000,'Deale');
6704INSERT INTO t2 VALUES ('P2','CALM','Code',30000,'Vienna');
6705INSERT INTO t2 VALUES ('P3','SDP','Test',30000,'Tampa');
6706INSERT INTO t2 VALUES ('P4','SDP','Design',20000,'Deale');
6707INSERT INTO t2 VALUES ('P5','IRM','Test',10000,'Vienna');
6708INSERT INTO t2 VALUES ('P6','PAYR','Design',50000,'Deale');
6709INSERT INTO t3 VALUES  ('E1','P1',40);
6710INSERT INTO t3 VALUES  ('E1','P2',20);
6711INSERT INTO t3 VALUES  ('E1','P3',80);
6712INSERT INTO t3 VALUES  ('E1','P4',20);
6713INSERT INTO t3 VALUES  ('E1','P5',12);
6714INSERT INTO t3 VALUES  ('E1','P6',12);
6715INSERT INTO t3 VALUES  ('E2','P1',40);
6716INSERT INTO t3 VALUES  ('E2','P2',80);
6717INSERT INTO t3 VALUES  ('E3','P2',20);
6718INSERT INTO t3 VALUES  ('E4','P2',20);
6719INSERT INTO t3 VALUES  ('E4','P4',40);
6720INSERT INTO t3 VALUES  ('E4','P5',80);
6721CREATE UNIQUE INDEX t1_IDX ON t1(EMPNUM);
6722EXPLAIN SELECT EMPNAME
6723FROM t1
6724WHERE EMPNUM IN
6725(SELECT EMPNUM
6726FROM t3
6727WHERE PNUM IN
6728(SELECT PNUM
6729FROM t2
6730WHERE PTYPE = 'Design'));
6731id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
67321	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
67332	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
67343	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6735Warnings:
6736Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6737PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
6738FROM t1
6739WHERE EMPNUM IN
6740   (SELECT EMPNUM
6741    FROM t3
6742    WHERE PNUM IN
6743       (SELECT PNUM
6744        FROM t2
6745        WHERE PTYPE = 'Design'))";
6746EXECUTE stmt;
6747id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
67481	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
67492	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
67503	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6751Warnings:
6752Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6753EXECUTE stmt;
6754id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
67551	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
67562	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
67573	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6758Warnings:
6759Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6760DEALLOCATE PREPARE stmt;
6761DROP INDEX t1_IDX ON t1;
6762CREATE INDEX t1_IDX ON t1(EMPNUM);
6763EXPLAIN SELECT EMPNAME
6764FROM t1
6765WHERE EMPNUM IN
6766(SELECT EMPNUM
6767FROM t3
6768WHERE PNUM IN
6769(SELECT PNUM
6770FROM t2
6771WHERE PTYPE = 'Design'));
6772id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
67731	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
67742	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
67753	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6776Warnings:
6777Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6778PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
6779FROM t1
6780WHERE EMPNUM IN
6781   (SELECT EMPNUM
6782    FROM t3
6783    WHERE PNUM IN
6784       (SELECT PNUM
6785        FROM t2
6786        WHERE PTYPE = 'Design'))";
6787EXECUTE stmt;
6788id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
67891	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
67902	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
67913	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6792Warnings:
6793Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6794EXECUTE stmt;
6795id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
67961	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
67972	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
67983	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6799Warnings:
6800Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6801DEALLOCATE PREPARE stmt;
6802DROP INDEX t1_IDX ON t1;
6803EXPLAIN SELECT EMPNAME
6804FROM t1
6805WHERE EMPNUM IN
6806(SELECT EMPNUM
6807FROM t3
6808WHERE PNUM IN
6809(SELECT PNUM
6810FROM t2
6811WHERE PTYPE = 'Design'));
6812id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
68131	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
68142	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
68153	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6816Warnings:
6817Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6818PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
6819FROM t1
6820WHERE EMPNUM IN
6821   (SELECT EMPNUM
6822    FROM t3
6823    WHERE PNUM IN
6824       (SELECT PNUM
6825        FROM t2
6826        WHERE PTYPE = 'Design'))";
6827EXECUTE stmt;
6828id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
68291	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
68302	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
68313	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6832Warnings:
6833Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6834EXECUTE stmt;
6835id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
68361	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
68372	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
68383	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
6839Warnings:
6840Note	1003	/* select#1 */ select `test`.`t1`.`EMPNAME` AS `EMPNAME` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`EMPNUM`,`test`.`t1`.`EMPNUM` in ( <materialize> (/* select#2 */ select `test`.`t3`.`EMPNUM` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`PNUM`,`test`.`t3`.`PNUM` in ( <materialize> (/* select#3 */ select `test`.`t2`.`PNUM` from `test`.`t2` where (`test`.`t2`.`PTYPE` = 'Design') ), <primary_index_lookup>(`test`.`t3`.`PNUM` in <temporary table> on <auto_key> where ((`test`.`t3`.`PNUM` = `materialized-subquery`.`PNUM`))))) ), <primary_index_lookup>(`test`.`t1`.`EMPNUM` in <temporary table> on <auto_key> where ((`test`.`t1`.`EMPNUM` = `materialized-subquery`.`EMPNUM`)))))
6841DEALLOCATE PREPARE stmt;
6842DROP TABLE t1, t2, t3;
6843#
6844# BUG#45221 Query SELECT pk FROM C WHERE pk IN (SELECT int_key) failing
6845#
6846CREATE TABLE t1 (
6847i1_key INT,
6848i2 INT,
6849i3 INT,
6850KEY i1_index (i1_key)
6851);
6852INSERT INTO t1 VALUES (9,1,2), (9,2,1);
6853CREATE TABLE t2 (
6854pk INT NOT NULL,
6855i1 INT,
6856PRIMARY KEY (pk)
6857);
6858INSERT INTO t2 VALUES (9,1);
6859SELECT pk
6860FROM t2
6861WHERE
6862pk IN (
6863SELECT i1_key
6864FROM t1
6865WHERE t1.i2 < t1.i3 XOR t2.i1 > 1
6866ORDER BY t1.i2 desc);
6867pk
68689
6869DROP TABLE t1,t2;
6870# BUG#50361 Doublenested noncorrelated subquery with FirstMatch and join cache wrong result
6871#
6872CREATE TABLE t1(
6873id INTEGER
6874);
6875INSERT INTO t1 VALUES(10),(20);
6876create table t2 select * from t1;
6877create table t3 select * from t1;
6878SELECT *
6879FROM t1
6880WHERE 1 IN(SELECT 1
6881FROM t2
6882WHERE 1 IN(SELECT 1
6883FROM t3));
6884id
688510
688620
6887explain extended SELECT *
6888FROM t1
6889WHERE 1 IN(SELECT 1
6890FROM t2
6891WHERE 1 IN(SELECT 1
6892FROM t3));
6893id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
68941	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
68952	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
68963	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
6897Warnings:
6898Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
6899Note	1003	/* select#1 */ select `test`.`t1`.`id` AS `id` from `test`.`t1` where 1
6900delete from t2;
6901delete from t3;
6902INSERT INTO t1 VALUES(30),(40),(50),(60),(70),(80),(90);
6903insert into t2 select * from t1;
6904insert into t3 select * from t1;
6905create table t4 select * from t1;
6906SELECT *
6907FROM t1
6908WHERE 1 IN(SELECT 1
6909FROM t2
6910WHERE 1 IN(SELECT 1
6911FROM t3
6912WHERE 1 IN(SELECT 1
6913FROM t4)));
6914id
691510
691620
691730
691840
691950
692060
692170
692280
692390
6924explain SELECT *
6925FROM t1
6926WHERE 1 IN(SELECT 1
6927FROM t2
6928WHERE 1 IN(SELECT 1
6929FROM t3
6930WHERE 1 IN(SELECT 1
6931FROM t4)));
6932id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
69331	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
69342	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
69353	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
69364	SUBQUERY	t4	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
6937Warnings:
6938Note	1003	/* select#1 */ select `test`.`t1`.`id` AS `id` from `test`.`t1` where 1
6939SELECT *
6940FROM t1
6941WHERE 1 IN(SELECT 1
6942FROM t1
6943WHERE 1 IN(SELECT 1
6944FROM t1
6945WHERE 1 IN(SELECT 1
6946FROM t1)));
6947id
694810
694920
695030
695140
695250
695360
695470
695580
695690
6957drop table t1,t2,t3,t4;
6958#
6959# Bug#53236 Segfault in DTCollation::set(DTCollation&)
6960#
6961CREATE TABLE t1 (
6962pk INTEGER AUTO_INCREMENT,
6963col_varchar VARCHAR(1),
6964PRIMARY KEY (pk)
6965)
6966;
6967INSERT INTO t1 (col_varchar)
6968VALUES
6969('w'),
6970('m')
6971;
6972SELECT  table1.pk
6973FROM ( t1 AS table1 JOIN t1 AS table2 ON (table1.col_varchar =
6974table2.col_varchar) )
6975WHERE ( 1, 2 ) IN ( SELECT SUBQUERY1_t1.pk AS SUBQUERY1_field1,
6976SUBQUERY1_t1.pk AS SUBQUERY1_field2
6977FROM ( t1 AS SUBQUERY1_t1 JOIN t1 AS SUBQUERY1_t2
6978ON (SUBQUERY1_t2.col_varchar =
6979SUBQUERY1_t1.col_varchar) ) )
6980;
6981pk
6982drop table t1;
6983#
6984# BUG#53298 "wrong result with semijoin (no semijoin strategy chosen)"
6985#
6986create table t1 (uid int, fid int);
6987insert into t1 values (1,1), (3,1);
6988create table t2 (uid int, name varchar(128));
6989insert into t2 values (1, "A"), (2, "B");
6990create table t3 (uid int, fid int, index(uid));
6991insert into t3 values (1,3), (1,3);
6992create table t4 (uid int);
6993insert into t4 values (3);
6994explain select t2.uid from t2, t1
6995where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
6996and t2.uid=t1.fid;
6997id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
69981	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
69991	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
70002	SUBQUERY	t4	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
70012	SUBQUERY	t3	NULL	ref	uid	uid	5	const	1	50.00	Using where
7002Warnings:
7003Note	1003	/* select#1 */ select `test`.`t2`.`uid` AS `uid` from `test`.`t2` join `test`.`t1` where ((`test`.`t1`.`fid` = `test`.`t2`.`uid`) and <in_optimizer>(`test`.`t1`.`uid`,`test`.`t1`.`uid` in ( <materialize> (/* select#2 */ select '3' from `test`.`t3` where ((`test`.`t3`.`fid` = '3') and (`test`.`t3`.`uid` = 1)) ), <primary_index_lookup>(`test`.`t1`.`uid` in <temporary table> on <auto_key> where ((`test`.`t1`.`uid` = `materialized-subquery`.`uid`))))))
7004select t2.uid from t2, t1
7005where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
7006and t2.uid=t1.fid;
7007uid
70081
7009drop table t1,t2,t3,t4;
7010CREATE TABLE t1 (
7011pk int,
7012a varchar(1),
7013b varchar(4),
7014c varchar(4),
7015d varchar(4),
7016PRIMARY KEY (pk)
7017);
7018INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
7019CREATE TABLE t2 LIKE t1;
7020INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
7021EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
7022id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
70231	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
70242	SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	100.00	Using where
7025Warnings:
7026Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`pk` > 0) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
7027SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
7028pk
70292
7030SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0);
7031pk
70322
7033DROP TABLE t1, t2;
7034CREATE TABLE t1 (f1 INT, f2 DECIMAL(5,3)) ENGINE=MyISAM;
7035INSERT INTO t1 (f1, f2) VALUES (1, 1.789);
7036INSERT INTO t1 (f1, f2) VALUES (13, 1.454);
7037INSERT INTO t1 (f1, f2) VALUES (10, 1.668);
7038CREATE TABLE t2 LIKE t1;
7039INSERT INTO t2 VALUES (1, 1.789);
7040INSERT INTO t2 VALUES (13, 1.454);
7041EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
7042id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
70431	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
70442	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
7045Warnings:
7046Note	1003	/* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`f1`,`test`.`t1`.`f2`),(`test`.`t1`.`f1`,`test`.`t1`.`f2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`f1`,`test`.`t2`.`f2` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`f1` in <temporary table> on <auto_key> where ((`test`.`t1`.`f1` = `materialized-subquery`.`f1`) and (`test`.`t1`.`f2` = `materialized-subquery`.`f2`)))))
7047SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
7048COUNT(*)
70492
7050DROP TABLE t1, t2;
7051CREATE TABLE t1 (
7052ID int(11) NOT NULL auto_increment,
7053Name char(35) NOT NULL default '',
7054Country char(3) NOT NULL default '',
7055Population int(11) NOT NULL default '0',
7056PRIMARY KEY  (ID),
7057INDEX (Population),
7058INDEX (Country)
7059);
7060CREATE TABLE t2 (
7061Code char(3) NOT NULL default '',
7062Name char(52) NOT NULL default '',
7063SurfaceArea float(10,2) NOT NULL default '0.00',
7064Population int(11) NOT NULL default '0',
7065Capital int(11) default NULL,
7066PRIMARY KEY  (Code),
7067UNIQUE INDEX (Name),
7068INDEX (Population)
7069);
7070CREATE TABLE t3 (
7071Country char(3) NOT NULL default '',
7072Language char(30) NOT NULL default '',
7073Percentage float(3,1) NOT NULL default '0.0',
7074PRIMARY KEY  (Country, Language),
7075INDEX (Percentage)
7076);
7077EXPLAIN SELECT Name FROM t2
7078WHERE t2.Code IN (SELECT Country FROM t1 WHERE Population > 5000000)
7079AND
7080t2.Code IN (SELECT Country FROM t3
7081WHERE Language='English' AND Percentage > 10 AND
7082t2.Population > 100000);
7083id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
70841	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	16	100.00	Using where
70853	DEPENDENT SUBQUERY	t3	NULL	unique_subquery	PRIMARY,Percentage	PRIMARY	33	func,const	1	95.45	Using where
70862	SUBQUERY	t1	NULL	range	Population,Country	Population	4	NULL	1	100.00	Using where
7087Warnings:
7088Note	1276	Field or reference 'test.t2.Population' of SELECT #3 was resolved in SELECT #1
7089Note	1003	/* select#1 */ select `test`.`t2`.`Name` AS `Name` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`Code`,`test`.`t2`.`Code` in ( <materialize> (/* select#2 */ select `test`.`t1`.`Country` from `test`.`t1` where (`test`.`t1`.`Population` > 5000000) ), <primary_index_lookup>(`test`.`t2`.`Code` in <temporary table> on <auto_key> where ((`test`.`t2`.`Code` = `materialized-subquery`.`Country`))))) and <in_optimizer>(`test`.`t2`.`Code`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`Code`) in t3 on PRIMARY where ((`test`.`t3`.`Language` = 'English') and (`test`.`t3`.`Percentage` > 10) and (`test`.`t2`.`Population` > 100000) and (<cache>(`test`.`t2`.`Code`) = `test`.`t3`.`Country`))))))
7090EXPLAIN FORMAT=JSON SELECT Name FROM t2
7091WHERE t2.Code IN (SELECT Country FROM t1 WHERE Population > 5000000)
7092AND
7093t2.Code IN (SELECT Country FROM t3
7094WHERE Language='English' AND Percentage > 10 AND
7095t2.Population > 100000);
7096EXPLAIN
7097{
7098  "query_block": {
7099    "select_id": 1,
7100    "cost_info": {
7101      "query_cost": "5.46"
7102    },
7103    "table": {
7104      "table_name": "t2",
7105      "access_type": "ALL",
7106      "rows_examined_per_scan": 16,
7107      "rows_produced_per_join": 16,
7108      "filtered": "100.00",
7109      "cost_info": {
7110        "read_cost": "2.27",
7111        "eval_cost": "3.20",
7112        "prefix_cost": "5.47",
7113        "data_read_per_join": "1K"
7114      },
7115      "used_columns": [
7116        "Code",
7117        "Name",
7118        "Population"
7119      ],
7120      "attached_condition": "(<in_optimizer>(`test`.`t2`.`Code`,`test`.`t2`.`Code` in ( <materialize> (/* select#2 */ select `test`.`t1`.`Country` from `test`.`t1` where (`test`.`t1`.`Population` > 5000000) ), <primary_index_lookup>(`test`.`t2`.`Code` in <temporary table> on <auto_key> where ((`test`.`t2`.`Code` = `materialized-subquery`.`Country`))))) and <in_optimizer>(`test`.`t2`.`Code`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`Code`) in t3 on PRIMARY where ((`test`.`t3`.`Language` = 'English') and (`test`.`t3`.`Percentage` > 10) and (`test`.`t2`.`Population` > 100000) and (<cache>(`test`.`t2`.`Code`) = `test`.`t3`.`Country`))))))",
7121      "attached_subqueries": [
7122        {
7123          "dependent": true,
7124          "cacheable": false,
7125          "query_block": {
7126            "select_id": 3,
7127            "cost_info": {
7128              "query_cost": "1.20"
7129            },
7130            "table": {
7131              "table_name": "t3",
7132              "access_type": "unique_subquery",
7133              "possible_keys": [
7134                "PRIMARY",
7135                "Percentage"
7136              ],
7137              "key": "PRIMARY",
7138              "used_key_parts": [
7139                "Country",
7140                "Language"
7141              ],
7142              "key_length": "33",
7143              "ref": [
7144                "func",
7145                "const"
7146              ],
7147              "rows_examined_per_scan": 1,
7148              "rows_produced_per_join": 0,
7149              "filtered": "95.45",
7150              "cost_info": {
7151                "read_cost": "1.00",
7152                "eval_cost": "0.19",
7153                "prefix_cost": "1.20",
7154                "data_read_per_join": "38"
7155              },
7156              "used_columns": [
7157                "Country",
7158                "Language",
7159                "Percentage"
7160              ],
7161              "attached_condition": "((`test`.`t3`.`Language` = 'English') and (`test`.`t3`.`Percentage` > 10) and (`test`.`t2`.`Population` > 100000) and (<cache>(`test`.`t2`.`Code`) = `test`.`t3`.`Country`))"
7162            }
7163          }
7164        },
7165        {
7166          "table": {
7167            "table_name": "<materialized_subquery>",
7168            "access_type": "eq_ref",
7169            "key": "<auto_key>",
7170            "key_length": "3",
7171            "rows_examined_per_scan": 1,
7172            "materialized_from_subquery": {
7173              "using_temporary_table": true,
7174              "dependent": true,
7175              "cacheable": false,
7176              "query_block": {
7177                "select_id": 2,
7178                "cost_info": {
7179                  "query_cost": "2.41"
7180                },
7181                "table": {
7182                  "table_name": "t1",
7183                  "access_type": "range",
7184                  "possible_keys": [
7185                    "Population",
7186                    "Country"
7187                  ],
7188                  "key": "Population",
7189                  "used_key_parts": [
7190                    "Population"
7191                  ],
7192                  "key_length": "4",
7193                  "rows_examined_per_scan": 1,
7194                  "rows_produced_per_join": 1,
7195                  "filtered": "100.00",
7196                  "cost_info": {
7197                    "read_cost": "2.21",
7198                    "eval_cost": "0.20",
7199                    "prefix_cost": "2.41",
7200                    "data_read_per_join": "48"
7201                  },
7202                  "used_columns": [
7203                    "Country",
7204                    "Population"
7205                  ],
7206                  "attached_condition": "(`test`.`t1`.`Population` > 5000000)"
7207                }
7208              }
7209            }
7210          }
7211        }
7212      ]
7213    }
7214  }
7215}
7216Warnings:
7217Note	1276	Field or reference 'test.t2.Population' of SELECT #3 was resolved in SELECT #1
7218Note	1003	/* select#1 */ select `test`.`t2`.`Name` AS `Name` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`Code`,`test`.`t2`.`Code` in ( <materialize> (/* select#2 */ select `test`.`t1`.`Country` from `test`.`t1` where (`test`.`t1`.`Population` > 5000000) ), <primary_index_lookup>(`test`.`t2`.`Code` in <temporary table> on <auto_key> where ((`test`.`t2`.`Code` = `materialized-subquery`.`Country`))))) and <in_optimizer>(`test`.`t2`.`Code`,<exists>(<primary_index_lookup>(<cache>(`test`.`t2`.`Code`) in t3 on PRIMARY where ((`test`.`t3`.`Language` = 'English') and (`test`.`t3`.`Percentage` > 10) and (`test`.`t2`.`Population` > 100000) and (<cache>(`test`.`t2`.`Code`) = `test`.`t3`.`Country`))))))
7219DROP TABLE t1,t2,t3;
7220CREATE TABLE t1 (
7221Code char(3) NOT NULL DEFAULT '',
7222Name char(52) NOT NULL DEFAULT '',
7223Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL DEFAULT 'Asia',
7224Region char(26) NOT NULL DEFAULT '',
7225SurfaceArea float(10,2) NOT NULL DEFAULT '0.00',
7226IndepYear smallint(6) DEFAULT NULL,
7227Population int(11) NOT NULL DEFAULT '0',
7228LifeExpectancy float(3,1) DEFAULT NULL,
7229GNP float(10,2) DEFAULT NULL,
7230GNPOld float(10,2) DEFAULT NULL,
7231LocalName char(45) NOT NULL DEFAULT '',
7232GovernmentForm char(45) NOT NULL DEFAULT '',
7233HeadOfState char(60) DEFAULT NULL,
7234Capital int(11) DEFAULT NULL,
7235Code2 char(2) NOT NULL DEFAULT '',
7236PRIMARY KEY (Code)
7237);
7238CREATE TABLE t2 (
7239ID int(11) NOT NULL AUTO_INCREMENT,
7240Name char(35) NOT NULL DEFAULT '',
7241CountryCode char(3) NOT NULL DEFAULT '',
7242District char(20) NOT NULL DEFAULT '',
7243Population int(11) NOT NULL DEFAULT '0',
7244PRIMARY KEY (ID),
7245KEY CountryCode (CountryCode)
7246);
7247Fill the table with test data
7248This must not use LooseScan:
7249EXPLAIN SELECT Name FROM t1
7250WHERE t1.Code IN (
7251SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
7252id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
72531	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	31	100.00	Using where
72542	SUBQUERY	t2	NULL	ALL	CountryCode	NULL	NULL	NULL	545	33.33	Using where
7255Warnings:
7256Note	1003	/* select#1 */ select `test`.`t1`.`Name` AS `Name` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`Code`,`test`.`t1`.`Code` in ( <materialize> (/* select#2 */ select `test`.`t2`.`CountryCode` from `test`.`t2` where (`test`.`t2`.`Population` > 5000000) ), <primary_index_lookup>(`test`.`t1`.`Code` in <temporary table> on <auto_key> where ((`test`.`t1`.`Code` = `materialized-subquery`.`CountryCode`)))))
7257SELECT Name FROM t1
7258WHERE t1.Code IN (
7259SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
7260Name
7261Austria
7262Canada
7263China
7264Czech Republic
7265drop table t1, t2;
7266create table t0 (a int);
7267insert into t0 values (0),(1),(2),(3),(4);
7268create table t1 (a int, b int, key(a));
7269insert into t1 select a,a from t0;
7270create table t2 (a int, b int, primary key(a));
7271insert into t2 select * from t1;
7272Table t2, unlike table t1, should be displayed as pulled out
7273explain extended select * from t0
7274where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and
7275t1.b=t2.b);
7276id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
72771	PRIMARY	t0	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
72782	DEPENDENT SUBQUERY	t1	NULL	ref	a	a	5	func	1	100.00	NULL
72792	DEPENDENT SUBQUERY	t2	NULL	eq_ref	PRIMARY	PRIMARY	4	test.t0.a	1	20.00	Using where
7280Warnings:
7281Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7282Note	1276	Field or reference 'test.t0.a' of SELECT #2 was resolved in SELECT #1
7283Note	1003	/* select#1 */ select `test`.`t0`.`a` AS `a` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`a`,<exists>(/* select#2 */ select 1 from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`a` = `test`.`t0`.`a`) and (<cache>(`test`.`t0`.`a`) = `test`.`t1`.`a`))))
7284update t1 set a=3, b=11 where a=4;
7285update t2 set b=11 where a=3;
7286create temporary table tmp select * from t0 where t0.a in
7287(select t1.a from t1, t2 where t2.a=t0.a and t1.b=t2.b);
7288create temporary table tmp_as_ref (a int);
7289insert into tmp_as_ref values(0),(1),(2),(3);
7290select * from tmp;
7291a
72920
72931
72942
72953
7296drop table t0, t1, t2, tmp, tmp_as_ref;
7297CREATE TABLE t1 (
7298id int(11) NOT NULL,
7299PRIMARY KEY (id));
7300CREATE TABLE t2 (
7301id int(11) NOT NULL,
7302fid int(11) NOT NULL,
7303PRIMARY KEY (id));
7304insert into t1 values(1);
7305insert into t2 values(1,7503),(2,1);
7306explain select count(*)
7307from t1
7308where fid IN (select fid from t2 where (id between 7502 and 8420) order by fid );
7309ERROR 42S22: Unknown column 'fid' in 'IN/ALL/ANY subquery'
7310drop table t1, t2;
7311create table t1 (a int, b int, key (a), key (b));
7312insert into t1 values (2,4),(2,4),(2,4);
7313select t1.a from t1
7314where
7315t1.a in (select 1 from t1 where t1.a in (select 1 from t1) group by  t1.a);
7316a
7317drop table t1;
7318create table t1(a int,b int,key(a),key(b));
7319insert into t1 values (1,1),(2,2),(3,3);
7320select 1 from t1
7321where t1.a not in (select 1 from t1
7322where t1.a in (select 1 from t1)
7323group by  t1.b);
73241
73251
73261
7327drop table t1;
7328CREATE TABLE t1
7329(EMPNUM   CHAR(3) NOT NULL,
7330EMPNAME  CHAR(20),
7331GRADE    DECIMAL(4),
7332CITY     CHAR(15));
7333CREATE TABLE t2
7334(PNUM     CHAR(3) NOT NULL,
7335PNAME    CHAR(20),
7336PTYPE    CHAR(6),
7337BUDGET   DECIMAL(9),
7338CITY     CHAR(15));
7339CREATE TABLE t3
7340(EMPNUM   CHAR(3) NOT NULL,
7341PNUM     CHAR(3) NOT NULL,
7342HOURS    DECIMAL(5));
7343INSERT INTO t1 VALUES ('E1','Alice',12,'Deale');
7344INSERT INTO t1 VALUES ('E2','Betty',10,'Vienna');
7345INSERT INTO t1 VALUES ('E3','Carmen',13,'Vienna');
7346INSERT INTO t1 VALUES ('E4','Don',12,'Deale');
7347INSERT INTO t1 VALUES ('E5','Ed',13,'Akron');
7348INSERT INTO t2 VALUES ('P1','MXSS','Design',10000,'Deale');
7349INSERT INTO t2 VALUES ('P2','CALM','Code',30000,'Vienna');
7350INSERT INTO t2 VALUES ('P3','SDP','Test',30000,'Tampa');
7351INSERT INTO t2 VALUES ('P4','SDP','Design',20000,'Deale');
7352INSERT INTO t2 VALUES ('P5','IRM','Test',10000,'Vienna');
7353INSERT INTO t2 VALUES ('P6','PAYR','Design',50000,'Deale');
7354INSERT INTO t3 VALUES  ('E1','P1',40);
7355INSERT INTO t3 VALUES  ('E1','P2',20);
7356INSERT INTO t3 VALUES  ('E1','P3',80);
7357INSERT INTO t3 VALUES  ('E1','P4',20);
7358INSERT INTO t3 VALUES  ('E1','P5',12);
7359INSERT INTO t3 VALUES  ('E1','P6',12);
7360INSERT INTO t3 VALUES  ('E2','P1',40);
7361INSERT INTO t3 VALUES  ('E2','P2',80);
7362INSERT INTO t3 VALUES  ('E3','P2',20);
7363INSERT INTO t3 VALUES  ('E4','P2',20);
7364INSERT INTO t3 VALUES  ('E4','P4',40);
7365INSERT INTO t3 VALUES  ('E4','P5',80);
7366SELECT * FROM t1;
7367EMPNUM	EMPNAME	GRADE	CITY
7368E1	Alice	12	Deale
7369E2	Betty	10	Vienna
7370E3	Carmen	13	Vienna
7371E4	Don	12	Deale
7372E5	Ed	13	Akron
7373CREATE UNIQUE INDEX t1_IDX ON t1(EMPNUM);
7374SELECT EMPNAME
7375FROM t1
7376WHERE EMPNUM IN
7377(SELECT EMPNUM
7378FROM t3
7379WHERE PNUM IN
7380(SELECT PNUM
7381FROM t2
7382WHERE PTYPE = 'Design'));
7383EMPNAME
7384Alice
7385Betty
7386Don
7387DROP INDEX t1_IDX ON t1;
7388CREATE INDEX t1_IDX ON t1(EMPNUM);
7389SELECT EMPNAME
7390FROM t1
7391WHERE EMPNUM IN
7392(SELECT EMPNUM
7393FROM t3
7394WHERE PNUM IN
7395(SELECT PNUM
7396FROM t2
7397WHERE PTYPE = 'Design'));
7398EMPNAME
7399Alice
7400Betty
7401Don
7402DROP INDEX t1_IDX ON t1;
7403SELECT EMPNAME
7404FROM t1
7405WHERE EMPNUM IN
7406(SELECT EMPNUM
7407FROM t3
7408WHERE PNUM IN
7409(SELECT PNUM
7410FROM t2
7411WHERE PTYPE = 'Design'));
7412EMPNAME
7413Alice
7414Betty
7415Don
7416DROP TABLE t1, t2, t3;
7417CREATE TABLE t1 (f1 INT NOT NULL);
7418CREATE VIEW v1 (a) AS SELECT f1 IN (SELECT f1 FROM t1) FROM t1;
7419SELECT * FROM v1;
7420a
7421drop view v1;
7422drop table t1;
7423create table t0 (a int);
7424insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
7425create table t1(a int, b int);
7426insert into t1 values (0,0),(1,1),(2,2);
7427create table t2 as select * from t1;
7428create table t3 (pk int, a int, primary key(pk));
7429insert into t3 select a,a from t0;
7430explain
7431select * from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t3));
7432id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
74331	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
74341	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (Block Nested Loop)
74352	SUBQUERY	t3	NULL	index	PRIMARY	PRIMARY	4	NULL	10	100.00	Using index
7436Warnings:
7437Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` left join `test`.`t2` on(((`test`.`t2`.`a` = `test`.`t1`.`a`) and <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t3`.`pk` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`pk`))))))) where 1
7438drop table t0, t1, t2, t3;
7439create table t0 (a int);
7440insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
7441create table t1 (a int) as select A.a + 10 *(B.a + 10*C.a) as a  from t0 A, t0 B, t0 C;
7442create table t2 (id int, a int, primary key(id), key(a)) as select a as id, a as a  from t1;
7443show create table t2;
7444Table	Create Table
7445t2	CREATE TABLE `t2` (
7446  `id` int(11) NOT NULL,
7447  `a` int(11) DEFAULT NULL,
7448  PRIMARY KEY (`id`),
7449  KEY `a` (`a`)
7450) ENGINE=MyISAM DEFAULT CHARSET=latin1
7451set @a=0;
7452create table t3 as select * from t2 limit 0;
7453insert into t3 select @a:=@a+1, t2.a from t2, t0;
7454insert into t3 select @a:=@a+1, t2.a from t2, t0;
7455insert into t3 select @a:=@a+1, t2.a from t2, t0;
7456alter table t3 add primary key(id), add key(a);
7457The following must use loose index scan over t3, key a:
7458explain select count(a) from t2 where a in ( SELECT  a FROM t3);
7459id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
74601	PRIMARY	t2	NULL	index	NULL	a	5	NULL	1000	100.00	Using where; Using index
74612	SUBQUERY	t3	NULL	index	a	a	5	NULL	30000	100.00	Using index
7462Warnings:
7463Note	1003	/* select#1 */ select count(`test`.`t2`.`a`) AS `count(a)` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t3`.`a` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on <auto_key> where ((`test`.`t2`.`a` = `materialized-subquery`.`a`)))))
7464select count(a) from t2 where a in ( SELECT  a FROM t3);
7465count(a)
74661000
7467drop table t0,t1,t2,t3;
7468#
7469# Bug#33062: subquery in stored routine cause crash
7470#
7471CREATE TABLE t1(a INT);
7472CREATE TABLE t2(c INT);
7473CREATE PROCEDURE p1(v1 int)
7474BEGIN
7475SELECT 1 FROM t1 WHERE a = v1 AND a IN (SELECT c FROM t2);
7476END
7477//
7478CREATE PROCEDURE p2(v1 int)
7479BEGIN
7480SELECT 1 FROM t1 WHERE a IN (SELECT c FROM t2);
7481END
7482//
7483CREATE PROCEDURE p3(v1 int)
7484BEGIN
7485SELECT 1
7486FROM
7487t1 t01,t1 t02,t1 t03,t1 t04,t1 t05,t1 t06,t1 t07,t1 t08,
7488t1 t09,t1 t10,t1 t11,t1 t12,t1 t13,t1 t14,t1 t15,t1 t16,
7489t1 t17,t1 t18,t1 t19,t1 t20,t1 t21,t1 t22,t1 t23,t1 t24,
7490t1 t25,t1 t26,t1 t27,t1 t28,t1 t29,t1 t30,t1 t31,t1 t32,
7491t1 t33,t1 t34,t1 t35,t1 t36,t1 t37,t1 t38,t1 t39,t1 t40,
7492t1 t41,t1 t42,t1 t43,t1 t44,t1 t45,t1 t46,t1 t47,t1 t48,
7493t1 t49,t1 t50,t1 t51,t1 t52,t1 t53,t1 t54,t1 t55,t1 t56,
7494t1 t57,t1 t58,t1 t59,t1 t60
7495WHERE t01.a IN (SELECT c FROM t2);
7496END
7497//
7498CREATE PROCEDURE p4(v1 int)
7499BEGIN
7500SELECT 1
7501FROM
7502t1 t01,t1 t02,t1 t03,t1 t04,t1 t05,t1 t06,t1 t07,t1 t08,
7503t1 t09,t1 t10,t1 t11,t1 t12,t1 t13,t1 t14,t1 t15,t1 t16,
7504t1 t17,t1 t18,t1 t19,t1 t20,t1 t21,t1 t22,t1 t23,t1 t24,
7505t1 t25,t1 t26,t1 t27,t1 t28,t1 t29,t1 t30,t1 t31,t1 t32,
7506t1 t33,t1 t34,t1 t35,t1 t36,t1 t37,t1 t38,t1 t39,t1 t40,
7507t1 t41,t1 t42,t1 t43,t1 t44,t1 t45,t1 t46,t1 t47,t1 t48,
7508t1 t49,t1 t50,t1 t51,t1 t52,t1 t53,t1 t54,t1 t55,t1 t56,
7509t1 t57,t1 t58,t1 t59,t1 t60
7510WHERE t01.a = v1 AND t01.a IN (SELECT c FROM t2);
7511END
7512//
7513CALL p1(1);
75141
7515CALL p2(1);
75161
7517CALL p3(1);
75181
7519CALL p4(1);
75201
7521DROP TABLE t1, t2;
7522DROP PROCEDURE p1;
7523DROP PROCEDURE p2;
7524DROP PROCEDURE p3;
7525DROP PROCEDURE p4;
7526#
7527# Bug#48213 Materialized subselect crashes if using GEOMETRY type
7528#
7529CREATE TABLE t1 (
7530pk int,
7531a varchar(1),
7532b varchar(4),
7533c tinyblob,
7534d blob,
7535e mediumblob,
7536f longblob,
7537g tinytext,
7538h text,
7539i mediumtext,
7540j longtext,
7541k geometry,
7542PRIMARY KEY (pk)
7543);
7544INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo','ffff','ffff','ffff','ffff','ffff','ffff',ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff', 'ffff','ffff','ffff','ffff','ffff','ffff',ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
7545CREATE TABLE t2 LIKE t1;
7546INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii','iiii','ffff','ffff','ffff','ffff','ffff',ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff',ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
7547EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
7548id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
75491	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
75502	SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	100.00	Using where
7551Warnings:
7552Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7553Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),(`test`.`t1`.`a`,`test`.`t1`.`b`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`a`,`test`.`t2`.`b` from `test`.`t2` where (`test`.`t2`.`pk` > 0) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`) and (`test`.`t1`.`b` = `materialized-subquery`.`b`)))))
7554SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
7555pk
75562
7557EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, c) IN (SELECT b, c FROM t2 WHERE pk > 0);
7558id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
75591	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
75602	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7561Warnings:
7562Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7563Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`c`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`c`) = `test`.`t2`.`c`))))
7564SELECT pk FROM t1 WHERE (b, c) IN (SELECT b, c FROM t2 WHERE pk > 0);
7565pk
75661
75672
7568EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, d) IN (SELECT b, d FROM t2 WHERE pk > 0);
7569id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
75701	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
75712	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7572Warnings:
7573Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7574Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`d`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`d`) = `test`.`t2`.`d`))))
7575SELECT pk FROM t1 WHERE (b, d) IN (SELECT b, d FROM t2 WHERE pk > 0);
7576pk
75772
7578EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, e) IN (SELECT b, e FROM t2 WHERE pk > 0);
7579id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
75801	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
75812	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7582Warnings:
7583Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7584Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`e`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`e`) = `test`.`t2`.`e`))))
7585SELECT pk FROM t1 WHERE (b, e) IN (SELECT b, e FROM t2 WHERE pk > 0);
7586pk
75871
75882
7589EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, f) IN (SELECT b, f FROM t2 WHERE pk > 0);
7590id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
75911	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
75922	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7593Warnings:
7594Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7595Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`f`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`f`) = `test`.`t2`.`f`))))
7596SELECT pk FROM t1 WHERE (b, f) IN (SELECT b, f FROM t2 WHERE pk > 0);
7597pk
75981
75992
7600EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, g) IN (SELECT b, g FROM t2 WHERE pk > 0);
7601id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
76021	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
76032	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7604Warnings:
7605Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7606Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`g`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`g`) = `test`.`t2`.`g`))))
7607SELECT pk FROM t1 WHERE (b, g) IN (SELECT b, g FROM t2 WHERE pk > 0);
7608pk
76091
76102
7611EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, h) IN (SELECT b, h FROM t2 WHERE pk > 0);
7612id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
76131	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
76142	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7615Warnings:
7616Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7617Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`h`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`h`) = `test`.`t2`.`h`))))
7618SELECT pk FROM t1 WHERE (b, h) IN (SELECT b, h FROM t2 WHERE pk > 0);
7619pk
76201
76212
7622EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, i) IN (SELECT b, i FROM t2 WHERE pk > 0);
7623id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
76241	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
76252	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7626Warnings:
7627Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7628Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`i`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`i`) = `test`.`t2`.`i`))))
7629SELECT pk FROM t1 WHERE (b, i) IN (SELECT b, i FROM t2 WHERE pk > 0);
7630pk
76311
76322
7633EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, j) IN (SELECT b, j FROM t2 WHERE pk > 0);
7634id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
76351	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
76362	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7637Warnings:
7638Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7639Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`j`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`j`) = `test`.`t2`.`j`))))
7640SELECT pk FROM t1 WHERE (b, j) IN (SELECT b, j FROM t2 WHERE pk > 0);
7641pk
76421
76432
7644EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, k) IN (SELECT b, k FROM t2 WHERE pk > 0);
7645id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
76461	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
76472	DEPENDENT SUBQUERY	t2	NULL	range	PRIMARY	PRIMARY	4	NULL	2	50.00	Using where
7648Warnings:
7649Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7650Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`b`,`test`.`t1`.`k`),<exists>(/* select#2 */ select 1,1 from `test`.`t2` where ((`test`.`t2`.`pk` > 0) and (<cache>(`test`.`t1`.`b`) = `test`.`t2`.`b`) and (<cache>(`test`.`t1`.`k`) = `test`.`t2`.`k`))))
7651SELECT pk FROM t1 WHERE (b, k) IN (SELECT b, k FROM t2 WHERE pk > 0);
7652pk
76531
76542
7655DROP TABLE t1, t2;
7656# End of Bug#48213
7657#
7658# BUG#53060: LooseScan semijoin strategy does not return all rows
7659#
7660CREATE TABLE t1 (i INTEGER);
7661INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
7662CREATE TABLE t2 (i INTEGER, j INTEGER, KEY k(i, j));
7663INSERT INTO t2 VALUES (1, 0), (1, 1), (2, 0), (2, 1);
7664EXPLAIN
7665SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
7666id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
76671	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
76682	SUBQUERY	t2	NULL	index	k	k	10	NULL	4	33.33	Using where; Using index
7669Warnings:
7670Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t2`.`i` from `test`.`t2` where (`test`.`t2`.`j` > 0) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
7671SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
7672i
76731
76742
7675DROP TABLE t1, t2;
7676# End of BUG#53060
7677#
7678# Bug#53305 "Duplicate weedout + join buffer (join cache --level=7,8) loses rows"
7679#
7680create table t1 (uid int, fid int, index(uid));
7681insert into t1 values
7682(1,1), (1,2), (1,3), (1,4),
7683(2,5), (2,6), (2,7), (2,8),
7684(3,1), (3,2), (3,9);
7685create table t2 (uid int primary key, name varchar(128), index(name));
7686insert into t2 values
7687(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
7688(6, "F"), (7, "G"), (8, "H"), (9, "I");
7689create table t3 (uid int, fid int, index(uid));
7690insert into t3 values
7691(1,1), (1,2), (1,3),(1,4),
7692(2,5), (2,6), (2,7), (2,8),
7693(3,1), (3,2), (3,9);
7694create table t4 (uid int primary key, name varchar(128), index(name));
7695insert into t4 values
7696(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
7697(6, "F"), (7, "G"), (8, "H"), (9, "I");
7698explain select name from t2, t1
7699where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
7700and t2.uid=t1.fid;
7701id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
77021	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	11	100.00	Using where
77031	PRIMARY	t2	NULL	eq_ref	PRIMARY	PRIMARY	4	test.t1.fid	1	100.00	NULL
77042	SUBQUERY	t3	NULL	ref	uid	uid	5	const	4	100.00	Using where
77052	SUBQUERY	t4	NULL	eq_ref	PRIMARY	PRIMARY	4	test.t3.fid	1	100.00	Using index
7706Warnings:
7707Note	1003	/* select#1 */ select `test`.`t2`.`name` AS `name` from `test`.`t2` join `test`.`t1` where ((`test`.`t2`.`uid` = `test`.`t1`.`fid`) and <in_optimizer>(`test`.`t1`.`uid`,`test`.`t1`.`uid` in ( <materialize> (/* select#2 */ select `test`.`t4`.`uid` from `test`.`t4` join `test`.`t3` where ((`test`.`t4`.`uid` = `test`.`t3`.`fid`) and (`test`.`t3`.`uid` = 1)) ), <primary_index_lookup>(`test`.`t1`.`uid` in <temporary table> on <auto_key> where ((`test`.`t1`.`uid` = `materialized-subquery`.`uid`))))))
7708select name from t2, t1
7709where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
7710and t2.uid=t1.fid;
7711name
7712A
7713A
7714B
7715B
7716C
7717D
7718E
7719F
7720G
7721H
7722I
7723drop table t1,t2,t3,t4;
7724#
7725# Bug#43768 Prepared query with nested subqueries core dump on second execution
7726#
7727CREATE TABLE t1 (
7728id INT PRIMARY KEY,
7729partner_id VARCHAR(35)
7730);
7731INSERT INTO t1 VALUES
7732(1, 'partner1'), (2, 'partner2'),
7733(3, 'partner3'), (4, 'partner4');
7734CREATE TABLE t2 (
7735id INT NOT NULL,
7736t1_line_id INT,
7737article_id VARCHAR(20),
7738PRIMARY KEY(id, t1_line_id)
7739);
7740INSERT INTO t2 VALUES
7741(1, 1, 'sup'), (2, 1, 'sup'),
7742(2, 2, 'sup'), (2, 3, 'sup'),
7743(2, 4, 'imp'), (3, 1, 'sup'),
7744(4, 1, 'sup');
7745CREATE TABLE t3 (
7746user_id VARCHAR(50),
7747article_id VARCHAR(20) NOT NULL,
7748PRIMARY KEY(user_id)
7749);
7750INSERT INTO t3 VALUES('nicke', 'imp');
7751EXPLAIN
7752SELECT t1.partner_id
7753FROM t1
7754WHERE t1.id IN (
7755SELECT t2.id
7756FROM t2
7757WHERE article_id IN (
7758SELECT article_id FROM t3
7759WHERE user_id = 'nicke'
7760    )
7761);
7762id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
77631	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
77642	SUBQUERY	t2	NULL	ALL	PRIMARY	NULL	NULL	NULL	7	100.00	Using where
77653	SUBQUERY	t3	NULL	system	PRIMARY	NULL	NULL	NULL	1	100.00	NULL
7766Warnings:
7767Note	1003	/* select#1 */ select `test`.`t1`.`partner_id` AS `partner_id` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`id`,`test`.`t1`.`id` in ( <materialize> (/* select#2 */ select `test`.`t2`.`id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`article_id`,`test`.`t2`.`article_id` in ( <materialize> (/* select#3 */ select 'imp' from dual where 1 ), <primary_index_lookup>(`test`.`t2`.`article_id` in <temporary table> on <auto_key> where ((`test`.`t2`.`article_id` = `materialized-subquery`.`article_id`))))) ), <primary_index_lookup>(`test`.`t1`.`id` in <temporary table> on <auto_key> where ((`test`.`t1`.`id` = `materialized-subquery`.`id`)))))
7768SELECT t1.partner_id
7769FROM t1
7770WHERE t1.id IN (
7771SELECT t2.id
7772FROM t2
7773WHERE article_id IN (
7774SELECT article_id FROM t3
7775WHERE user_id = 'nicke'
7776    )
7777);
7778partner_id
7779partner2
7780PREPARE stmt FROM
7781'EXPLAIN SELECT t1.partner_id
7782FROM t1
7783WHERE t1.id IN (
7784    SELECT t2.id
7785    FROM t2
7786    WHERE article_id IN (
7787      SELECT article_id FROM t3
7788      WHERE user_id = \'nicke\'
7789    )
7790  )';
7791EXECUTE stmt;
7792id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
77931	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
77942	SUBQUERY	t2	NULL	ALL	PRIMARY	NULL	NULL	NULL	7	100.00	Using where
77953	SUBQUERY	t3	NULL	system	PRIMARY	NULL	NULL	NULL	1	100.00	NULL
7796Warnings:
7797Note	1003	/* select#1 */ select `test`.`t1`.`partner_id` AS `partner_id` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`id`,`test`.`t1`.`id` in ( <materialize> (/* select#2 */ select `test`.`t2`.`id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`article_id`,`test`.`t2`.`article_id` in ( <materialize> (/* select#3 */ select 'imp' from dual where 1 ), <primary_index_lookup>(`test`.`t2`.`article_id` in <temporary table> on <auto_key> where ((`test`.`t2`.`article_id` = `materialized-subquery`.`article_id`))))) ), <primary_index_lookup>(`test`.`t1`.`id` in <temporary table> on <auto_key> where ((`test`.`t1`.`id` = `materialized-subquery`.`id`)))))
7798EXECUTE stmt;
7799id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
78001	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
78012	SUBQUERY	t2	NULL	ALL	PRIMARY	NULL	NULL	NULL	7	100.00	Using where
78023	SUBQUERY	t3	NULL	system	PRIMARY	NULL	NULL	NULL	1	100.00	NULL
7803Warnings:
7804Note	1003	/* select#1 */ select `test`.`t1`.`partner_id` AS `partner_id` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`id`,`test`.`t1`.`id` in ( <materialize> (/* select#2 */ select `test`.`t2`.`id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`article_id`,`test`.`t2`.`article_id` in ( <materialize> (/* select#3 */ select 'imp' from dual where 1 ), <primary_index_lookup>(`test`.`t2`.`article_id` in <temporary table> on <auto_key> where ((`test`.`t2`.`article_id` = `materialized-subquery`.`article_id`))))) ), <primary_index_lookup>(`test`.`t1`.`id` in <temporary table> on <auto_key> where ((`test`.`t1`.`id` = `materialized-subquery`.`id`)))))
7805PREPARE stmt FROM
7806'SELECT t1.partner_id
7807FROM t1
7808WHERE t1.id IN (
7809    SELECT t2.id
7810    FROM t2
7811    WHERE article_id IN (
7812      SELECT article_id FROM t3
7813      WHERE user_id = \'nicke\'
7814    )
7815  )';
7816EXECUTE stmt;
7817partner_id
7818partner2
7819EXECUTE stmt;
7820partner_id
7821partner2
7822DROP TABLE t1,t2,t3;
7823# End of Bug#43768
7824#
7825# Bug#53058 - semijoin execution of subquery with outerjoin yields wrong result
7826#
7827CREATE TABLE t1 (i INTEGER);
7828CREATE TABLE t2 (i INTEGER);
7829CREATE TABLE t3 (i INTEGER);
7830INSERT INTO t1 VALUES (1), (2);
7831INSERT INTO t2 VALUES (6);
7832INSERT INTO t3 VALUES (1), (2);
7833explain extended SELECT * FROM t1 WHERE (t1.i) IN
7834(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
7835id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
78361	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
78372	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
78382	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
7839Warnings:
7840Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
7841Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t3`.`i` from `test`.`t3` left join `test`.`t2` on((`test`.`t2`.`i` = `test`.`t3`.`i`)) where 1 ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
7842SELECT * FROM t1 WHERE (t1.i) IN
7843(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
7844i
78451
78462
7847drop table t1,t2,t3;
7848#
7849# BUG#49453: re-execution of prepared statement with view
7850#            and semijoin crashes
7851#
7852CREATE TABLE t1 (city VARCHAR(50), country_id INT);
7853CREATE TABLE t2 (country_id INT, country VARCHAR(50));
7854INSERT INTO t1 VALUES
7855('Batna',2),('Bchar',2),('Skikda',2),('Tafuna',3),('Algeria',2) ;
7856INSERT INTO t2 VALUES (2,'Algeria'),(2,'AlgeriaDup'),(3,'XAmerican Samoa');
7857CREATE VIEW v1 AS
7858SELECT country_id as vf_country_id
7859FROM t2
7860WHERE LEFT(country,1) = "A";
7861PREPARE stmt FROM "
7862SELECT city, country_id
7863FROM t1
7864WHERE country_id IN (SELECT vf_country_id FROM v1);
7865";
7866
7867EXECUTE stmt;
7868city	country_id
7869Batna	2
7870Bchar	2
7871Skikda	2
7872Algeria	2
7873EXECUTE stmt;
7874city	country_id
7875Batna	2
7876Bchar	2
7877Skikda	2
7878Algeria	2
7879DROP TABLE t1,t2;
7880DROP VIEW v1;
7881#
7882# Bug#54437 Extra rows with LEFT JOIN + semijoin (firstmatch
7883# and duplicates weedout)
7884#
7885create table t1 (a int);
7886create table t2 (a int);
7887create table t3 (a int);
7888insert into t1 values(1),(1);
7889insert into t2 values(1),(1),(1),(1);
7890insert into t3 values(2),(2);
7891explain select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
7892id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
78931	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
78942	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
78952	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
7896Warnings:
7897Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` left join `test`.`t3` on((`test`.`t3`.`a` = `test`.`t2`.`a`)) where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
7898select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
7899a
79001
79011
7902drop table t1,t2,t3;
7903#
7904# Bug#55955: crash in MEMORY engine with IN(LEFT JOIN (JOIN))
7905#
7906CREATE TABLE t1 (a INT);
7907CREATE TABLE t2 (a INT);
7908CREATE TABLE t3 (a INT);
7909INSERT INTO t1 VALUES(1),(1);
7910INSERT INTO t2 VALUES(1),(1);
7911INSERT INTO t3 VALUES(2),(2);
7912explain SELECT * FROM t1
7913WHERE t1.a IN (SELECT t2.a
7914FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
7915id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
79161	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
79172	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
79182	SUBQUERY	t2inner	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (Block Nested Loop)
79192	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
7920Warnings:
7921Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` left join (`test`.`t2` `t2inner` join `test`.`t3`) on((`test`.`t3`.`a` = `test`.`t2`.`a`)) where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
7922SELECT * FROM t1
7923WHERE t1.a IN (SELECT t2.a
7924FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
7925a
79261
79271
7928DROP TABLE t1,t2,t3;
7929#
7930# BUG#52329 - Wrong result: subquery materialization, IN,
7931#             non-null field followed by nullable
7932#
7933CREATE TABLE t1 (a1 CHAR(8) NOT NULL, a2 char(8) NOT NULL);
7934CREATE TABLE t2a (b1 char(8), b2 char(8));
7935CREATE TABLE t2b (b1 CHAR(8), b2 char(8) NOT NULL);
7936CREATE TABLE t2c (b1 CHAR(8) NOT NULL, b2 char(8));
7937INSERT INTO t1 VALUES ('1 - 12', '2 - 22');
7938INSERT INTO t2a VALUES ('1 - 11', '2 - 21'),
7939('1 - 11', '2 - 21'),
7940('1 - 12', '2 - 22'),
7941('1 - 12', '2 - 22'),
7942('1 - 13', '2 - 23');
7943INSERT INTO t2b SELECT * FROM t2a;
7944INSERT INTO t2c SELECT * FROM t2a;
7945SELECT * FROM t1
7946WHERE (a1, a2) IN (
7947SELECT b1, b2 FROM t2c WHERE b1 > '0' GROUP BY b1, b2);
7948a1	a2
79491 - 12	2 - 22
7950SELECT * FROM t1
7951WHERE (a1, a2) IN (
7952SELECT b1, b2 FROM t2a WHERE b1 > '0');
7953a1	a2
79541 - 12	2 - 22
7955SELECT * FROM t1
7956WHERE (a1, a2) IN (
7957SELECT b1, b2 FROM t2b WHERE b1 > '0');
7958a1	a2
79591 - 12	2 - 22
7960SELECT * FROM t1
7961WHERE (a1, a2) IN (
7962SELECT b1, b2 FROM t2c WHERE b1 > '0');
7963a1	a2
79641 - 12	2 - 22
7965DROP TABLE t1,t2a,t2b,t2c;
7966# End BUG#52329
7967#
7968# Bug#45174: Incorrectly applied equality propagation caused wrong
7969# result on a query with a materialized semi-join.
7970#
7971CREATE TABLE t1 (
7972varchar_nokey varchar(1) NOT NULL
7973);
7974INSERT INTO t1 VALUES
7975('v'), ('u'), ('n'), ('l'), ('h'), ('u'), ('n'), ('j'), ('k'),
7976('e'), ('i'), ('u'), ('n'), ('b'), ('x'), (''), ('q'), ('u');
7977CREATE TABLE t2 (
7978pk int NOT NULL,
7979varchar_key varchar(1) NOT NULL,
7980varchar_nokey varchar(1) NOT NULL,
7981PRIMARY KEY(pk),
7982KEY varchar_key(varchar_key)
7983);
7984INSERT INTO t2 VALUES
7985(11,'m','m'), (12,'j','j'), (13,'z','z'), (14,'a','a'), (15,'',''),
7986(16,'e','e'), (17,'t','t'), (19,'b','b'), (20,'w','w'), (21,'m','m'),
7987(23,'',''), (24,'w','w'), (26,'e','e'), (27,'e','e'), (28,'p','p');
7988SELECT varchar_nokey
7989FROM t1
7990WHERE (varchar_nokey, varchar_nokey) IN (SELECT varchar_key, varchar_nokey
7991FROM t2
7992WHERE varchar_nokey < 'n' XOR pk);
7993varchar_nokey
7994explain SELECT varchar_nokey
7995FROM t1
7996WHERE (varchar_nokey, varchar_nokey) IN (SELECT varchar_key, varchar_nokey
7997FROM t2
7998WHERE varchar_nokey < 'n' XOR pk);
7999id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
80001	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	18	100.00	Using where
80012	SUBQUERY	t2	NULL	ALL	varchar_key	NULL	NULL	NULL	15	63.34	Using where
8002Warnings:
8003Note	1003	/* select#1 */ select `test`.`t1`.`varchar_nokey` AS `varchar_nokey` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`varchar_nokey`,`test`.`t1`.`varchar_nokey`),(`test`.`t1`.`varchar_nokey`,`test`.`t1`.`varchar_nokey`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`varchar_key`,`test`.`t2`.`varchar_nokey` from `test`.`t2` where ((`test`.`t2`.`varchar_nokey` < 'n') xor `test`.`t2`.`pk`) ), <primary_index_lookup>(`test`.`t1`.`varchar_nokey` in <temporary table> on <auto_key> where ((`test`.`t1`.`varchar_nokey` = `materialized-subquery`.`varchar_key`) and (`test`.`t1`.`varchar_nokey` = `materialized-subquery`.`varchar_nokey`)))))
8004DROP TABLE t1, t2;
8005# End of the test for bug#45174.
8006#
8007# Bug#50019: Wrong result for IN-query with materialization
8008#
8009CREATE TABLE t1(i INT);
8010INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
8011CREATE TABLE t2(i INT);
8012INSERT INTO t2 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
8013CREATE TABLE t3(i INT);
8014INSERT INTO t3 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
8015SELECT * FROM t1 WHERE t1.i IN (SELECT t2.i
8016FROM t2 JOIN t3
8017WHERE t2.i + t3.i = 5);
8018i
80191
80202
80213
80224
8023explain SELECT * FROM t1 WHERE t1.i IN (SELECT t2.i
8024FROM t2 JOIN t3
8025WHERE t2.i + t3.i = 5);
8026id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
80271	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
80282	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	NULL
80292	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where; Using join buffer (Block Nested Loop)
8030Warnings:
8031Note	1003	/* select#1 */ select `test`.`t1`.`i` AS `i` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`i`,`test`.`t1`.`i` in ( <materialize> (/* select#2 */ select `test`.`t2`.`i` from `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`i` + `test`.`t3`.`i`) = 5) ), <primary_index_lookup>(`test`.`t1`.`i` in <temporary table> on <auto_key> where ((`test`.`t1`.`i` = `materialized-subquery`.`i`)))))
8032DROP TABLE t1,t2,t3;
8033# End of the test for bug#50019.
8034#
8035# Bug#52068: Optimizer generates invalid semijoin materialization plan
8036#
8037CREATE TABLE ot1(a INTEGER);
8038INSERT INTO ot1 VALUES(5), (8);
8039CREATE TABLE it2(a INTEGER);
8040INSERT INTO it2 VALUES(9), (5), (1), (8);
8041CREATE TABLE it3(a INTEGER);
8042INSERT INTO it3 VALUES(7), (1), (0), (5), (1), (4);
8043CREATE TABLE ot4(a INTEGER);
8044INSERT INTO ot4 VALUES(1), (3), (5), (7), (9), (7), (3), (1);
8045SELECT * FROM ot1,ot4
8046WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
8047FROM it2,it3);
8048a	a
80495	1
80508	1
80515	5
80528	5
80535	7
80548	7
80555	7
80568	7
80575	1
80588	1
8059explain SELECT * FROM ot1,ot4
8060WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
8061FROM it2,it3);
8062id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
80631	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
80641	PRIMARY	ot4	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	Using where; Using join buffer (Block Nested Loop)
80652	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
80662	SUBQUERY	it3	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using join buffer (Block Nested Loop)
8067Warnings:
8068Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot4`.`a` AS `a` from `test`.`ot1` join `test`.`ot4` where <in_optimizer>((`test`.`ot1`.`a`,`test`.`ot4`.`a`),(`test`.`ot1`.`a`,`test`.`ot4`.`a`) in ( <materialize> (/* select#2 */ select `test`.`it2`.`a`,`test`.`it3`.`a` from `test`.`it2` join `test`.`it3` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`) and (`test`.`ot4`.`a` = `materialized-subquery`.`a`)))))
8069DROP TABLE IF EXISTS ot1, ot4, it2, it3;
8070# End of the test for bug#52068.
8071#
8072# Bug#57623: subquery within before insert trigger causes crash (sj=on)
8073#
8074CREATE TABLE ot1(a INT);
8075CREATE TABLE ot2(a INT);
8076CREATE TABLE ot3(a INT);
8077CREATE TABLE it1(a INT);
8078INSERT INTO ot1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
8079INSERT INTO ot2 VALUES(0),(2),(4),(6);
8080INSERT INTO ot3 VALUES(0),(3),(6);
8081INSERT INTO it1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
8082explain SELECT *
8083FROM   ot1
8084LEFT JOIN
8085(ot2 JOIN ot3 on ot2.a=ot3.a)
8086ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
8087id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
80881	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
80891	PRIMARY	ot3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (Block Nested Loop)
80901	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
80912	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
8092Warnings:
8093Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a`,`test`.`ot3`.`a` AS `a` from `test`.`ot1` left join (`test`.`ot2` join `test`.`ot3`) on(((`test`.`ot3`.`a` = `test`.`ot1`.`a`) and (`test`.`ot2`.`a` = `test`.`ot1`.`a`) and <in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#2 */ select `test`.`it1`.`a` from `test`.`it1` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`))))))) where 1
8094SELECT *
8095FROM   ot1
8096LEFT JOIN
8097(ot2 JOIN ot3 on ot2.a=ot3.a)
8098ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
8099a	a	a
81000	0	0
81011	NULL	NULL
81022	NULL	NULL
81033	NULL	NULL
81044	NULL	NULL
81055	NULL	NULL
81066	6	6
81077	NULL	NULL
8108prepare s from 'SELECT *
8109FROM   ot1
8110LEFT JOIN
8111(ot2 JOIN ot3 on ot2.a=ot3.a)
8112ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1)';
8113execute s;
8114a	a	a
81150	0	0
81161	NULL	NULL
81172	NULL	NULL
81183	NULL	NULL
81194	NULL	NULL
81205	NULL	NULL
81216	6	6
81227	NULL	NULL
8123execute s;
8124a	a	a
81250	0	0
81261	NULL	NULL
81272	NULL	NULL
81283	NULL	NULL
81294	NULL	NULL
81305	NULL	NULL
81316	6	6
81327	NULL	NULL
8133deallocate prepare s;
8134DROP TABLE ot1, ot2, ot3, it1;
8135# End of the test for bug#57623.
8136#
8137# Bug#11766739: Crash in tmp_table_param::init() with semijoin=on
8138#
8139CREATE TABLE t1 (f1 INTEGER) ENGINE=MyISAM;
8140CREATE TABLE t2 (f1 INTEGER, f2 INTEGER) ENGINE=MyISAM;
8141INSERT INTO t1 VALUES (1);
8142INSERT INTO t2 VALUES (1,1), (2,1);
8143EXPLAIN SELECT * FROM t2
8144WHERE f2 IN (SELECT t1.f1
8145FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
8146id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
81471	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
81482	SUBQUERY	t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
81492	SUBQUERY	b1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
81502	SUBQUERY	b2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
8151Warnings:
8152Note	1003	/* select#1 */ select `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`f2`,`test`.`t2`.`f2` in ( <materialize> (/* select#2 */ select '1' from (`test`.`t2` `b1` join `test`.`t2` `b2`) where 1 ), <primary_index_lookup>(`test`.`t2`.`f2` in <temporary table> on <auto_key> where ((`test`.`t2`.`f2` = `materialized-subquery`.`f1`)))))
8153SELECT * FROM t2
8154WHERE f2 IN (SELECT t1.f1
8155FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
8156f1	f2
81571	1
81582	1
8159DROP TABLE t1, t2;
8160# End of the test for bug#11766739.
8161#
8162# Bug#11766642: crash in Item_field::register_field_in_read_map with view
8163#
8164CREATE TABLE t1(a INT);
8165CREATE VIEW v1 AS SELECT a FROM t1;
8166INSERT INTO t1 VALUES (0),(1),(2);
8167SELECT a FROM t1 WHERE a IN
8168(SELECT a XOR a FROM v1)
8169ORDER BY a;
8170a
81710
8172DROP TABLE t1;
8173DROP VIEW v1;
8174#
8175# Bug#12546542 MISSING ROW WHEN USING OPTIMIZER_JOIN_CACHE_LEVEL>=3
8176#
8177CREATE TABLE t1 (
8178f2 varchar(1024)
8179);
8180INSERT INTO t1 VALUES ('v'),('we');
8181CREATE TABLE t2 (
8182col_varchar_1024_utf8 varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
8183col_int_key int,
8184col_int int
8185);
8186INSERT INTO t2 VALUES ('we',4,NULL),('v',1305673728,6);
8187CREATE TABLE t3 (
8188col_int_key int,
8189col_int int
8190);
8191INSERT INTO t3 VALUES (4,4);
8192SELECT *
8193FROM t1
8194WHERE f2 IN (SELECT a1.col_varchar_1024_utf8 AS f2
8195FROM t2 AS a1 LEFT JOIN t3 AS a2
8196ON a1.col_int_key = a2.col_int_key
8197WHERE a1.col_int BETWEEN 1 AND 10 OR a2.col_int IS NOT NULL);
8198f2
8199v
8200we
8201DROP TABLE t1,t2,t3;
8202#
8203# BUG#12616344 - JCL: DIFFERENT RESULT SET AND DIFFERENT AMOUNT
8204# OF ROWS WHEN JCL>=3
8205#
8206CREATE TABLE t1 (col_int_nokey int, col_int_key int, col_varchar_key varchar(1));
8207INSERT INTO t1 VALUES (0,4,'c'),(1,6,'u');
8208CREATE TABLE t2 (pk int, col_int_nokey int, col_varchar_nokey varchar(1));
8209INSERT INTO t2 VALUES (1,4,'b'),(94,6,'u');
8210CREATE TABLE t3 (pk int, col_int_nokey int, col_varchar_key varchar(1));
8211INSERT INTO t3 VALUES (1,4,'j'),(2,6,'v');
8212SELECT table2.col_int_key
8213from t3 as table1 join t1 as table2 on table2.col_int_nokey
8214where table1.col_int_nokey in
8215(
8216select subquery2_t2.col_int_nokey
8217from t3 as subquery2_t1
8218right join
8219t2 as subquery2_t2
8220join t1 as subquery2_t3
8221on subquery2_t3.col_int_key = subquery2_t2.col_int_nokey
8222on subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_nokey
8223where subquery2_t1.col_varchar_key != table1.col_varchar_key
8224or subquery2_t2.pk <= table1.pk
8225);
8226col_int_key
82276
82286
8229DROP TABLE t1,t2,t3;
8230#
8231# Bug#12608157: ASSERT IN FIELD_LONG::VAL_INT WHEN USING MEMORY ENGINE
8232#
8233CREATE TABLE t1 (i1 int);
8234INSERT INTO t1 VALUES (1);
8235CREATE TABLE t2 (i1 int, i2 int) ENGINE=memory;
8236INSERT INTO t2 VALUES (1, 2),(7, 3);
8237SELECT GRANDPARENT1.i1
8238FROM t2 AS GRANDPARENT1
8239WHERE GRANDPARENT1.i2
8240IN ( SELECT PARENT1.i2
8241FROM t2 AS PARENT1 JOIN t1 AS PARENT2 ON (PARENT1.i1 = PARENT2.i1)
8242WHERE
8243GRANDPARENT1.i1 IN ( SELECT CHILD1.i1 FROM t2 AS CHILD1 )
8244ORDER BY PARENT1.i1)
8245ORDER BY GRANDPARENT1.i2 ;
8246i1
82471
8248DROP TABLE t1,t2;
8249#
8250# Bug#12640083: Same query executed as WHERE subquery gives different
8251#              results on IN() compare
8252#
8253CREATE TABLE t1 (
8254pk int NOT NULL,
8255col_varchar_1024_utf8_key varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
8256col_varchar_10_latin1_key varchar(10) DEFAULT NULL,
8257PRIMARY KEY (pk),
8258KEY col_varchar_1024_utf8_key(col_varchar_1024_utf8_key(333)),
8259KEY col_varchar_10_latin1_key(col_varchar_10_latin1_key)
8260);
8261INSERT INTO t1 VALUES
8262(1, 'a', 'a'),
8263(2, 'ab', 'ab'),
8264(3, 'abc', 'abc'),
8265(4, 'abcd', 'abcd');
8266CREATE TABLE t2 (
8267pk int NOT NULL AUTO_INCREMENT,
8268PRIMARY KEY (pk)
8269) ENGINE=Innodb;
8270CREATE TABLE t3
8271SELECT alias1.col_varchar_10_latin1_key
8272FROM t1 AS alias1
8273LEFT JOIN t1 AS alias2
8274JOIN t2 AS alias3
8275ON alias2.col_varchar_10_latin1_key
8276ON alias1.col_varchar_1024_utf8_key
8277WHERE alias1.pk AND alias1.pk < 3 OR alias1.pk AND alias3.pk;
8278EXPLAIN SELECT *
8279FROM t3
8280WHERE col_varchar_10_latin1_key IN (
8281SELECT alias1.col_varchar_10_latin1_key
8282FROM t1 AS alias1
8283LEFT JOIN t1 AS alias2
8284JOIN t2 AS alias3
8285ON alias2.col_varchar_10_latin1_key
8286ON alias1.col_varchar_1024_utf8_key
8287WHERE alias1.pk AND alias1.pk < 3 OR alias1.pk AND alias3.pk);
8288id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
82891	PRIMARY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
82902	SUBQUERY	alias1	NULL	ALL	PRIMARY,col_varchar_10_latin1_key	NULL	NULL	NULL	4	81.25	Using where
82912	SUBQUERY	alias3	NULL	index	NULL	PRIMARY	4	NULL	1	100.00	Using where; Using index; Using join buffer (Block Nested Loop)
82922	SUBQUERY	alias2	NULL	index	NULL	col_varchar_10_latin1_key	13	NULL	4	100.00	Using where; Using index; Using join buffer (Block Nested Loop)
8293Warnings:
8294Note	1003	/* select#1 */ select `test`.`t3`.`col_varchar_10_latin1_key` AS `col_varchar_10_latin1_key` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`col_varchar_10_latin1_key`,`test`.`t3`.`col_varchar_10_latin1_key` in ( <materialize> (/* select#2 */ select `test`.`alias1`.`col_varchar_10_latin1_key` from `test`.`t1` `alias1` left join (`test`.`t1` `alias2` join `test`.`t2` `alias3`) on((`test`.`alias1`.`col_varchar_1024_utf8_key` and `test`.`alias2`.`col_varchar_10_latin1_key`)) where ((`test`.`alias1`.`pk` and (`test`.`alias1`.`pk` < 3)) or (`test`.`alias1`.`pk` and `test`.`alias3`.`pk`)) ), <primary_index_lookup>(`test`.`t3`.`col_varchar_10_latin1_key` in <temporary table> on <auto_key> where ((`test`.`t3`.`col_varchar_10_latin1_key` = `materialized-subquery`.`col_varchar_10_latin1_key`)))))
8295SELECT *
8296FROM t3
8297WHERE col_varchar_10_latin1_key IN (
8298SELECT alias1.col_varchar_10_latin1_key
8299FROM t1 AS alias1
8300LEFT JOIN t1 AS alias2
8301JOIN t2 AS alias3
8302ON alias2.col_varchar_10_latin1_key
8303ON alias1.col_varchar_1024_utf8_key
8304WHERE alias1.pk AND alias1.pk < 3 OR alias1.pk AND alias3.pk);
8305col_varchar_10_latin1_key
8306a
8307ab
8308DROP TABLE t1, t2, t3;
8309# End of the test for bug#12640083.
8310#
8311# Bug#12603200 - Assert in QUICK_INDEX_MERGE_SELECT::need_sorted_output
8312#
8313CREATE TABLE t1 (
8314pk int NOT NULL,
8315col_int_key int NOT NULL,
8316col_varchar_nokey varchar(1) NOT NULL,
8317col_varchar_key varchar(1) NOT NULL,
8318PRIMARY KEY(pk),
8319KEY col_int_key(col_int_key),
8320KEY col_varchar_key(col_varchar_key, col_int_key)
8321) engine=innodb;
8322INSERT INTO t1 VALUES
8323(1,7,'a','a'),
8324(2,0,'v','v'),
8325(3,9,'c','c'),
8326(4,3,'m','m'),
8327(5,2,'a','a'),
8328(6,1,'d','d'),
8329(7,8,'y','y'),
8330(8,6,'t','t'),
8331(11,7,'a','x'),
8332(12,0,'v','v'),
8333(13,9,'c','c'),
8334(14,3,'m','m'),
8335(15,2,'a','x'),
8336(16,1,'d','d'),
8337(17,8,'y','y'),
8338(18,6,'t','u'),
8339(19,6,'t','u');
8340CREATE TABLE t2 (
8341pk int NOT NULL,
8342col_int_key int NOT NULL,
8343col_varchar_key varchar(1) NOT NULL,
8344PRIMARY KEY(pk),
8345KEY col_varchar_key(col_varchar_key, col_int_key)
8346) engine=innodb;
8347INSERT INTO t2(pk,col_int_key,col_varchar_key) VALUES
8348(8,7,'c'),
8349(11,4,'l'),
8350(12,7,'b'),
8351(13,0,'c'),
8352(14,2,'i'),
8353(15,9,'h'),
8354(16,4,'q'),
8355(17,1,'m'),
8356(18,9,'b'),
8357(19,2,'e'),
8358(20,1,'c'),
8359(21,7,'z'),
8360(22,4,'l'),
8361(23,7,'z'),
8362(24,0,'c'),
8363(25,2,'i'),
8364(26,9,'h'),
8365(27,4,'q'),
8366(28,0,'a'),
8367(29,1,'d');
8368EXPLAIN SELECT outr.col_varchar_key AS x, outr.pk AS y
8369FROM t1 AS outr
8370WHERE outr.col_varchar_key IN (SELECT innr.col_varchar_key
8371FROM t2 AS innr
8372WHERE innr.col_varchar_key = 'a' OR innr.pk = 8)
8373AND outr.col_varchar_nokey < 't'
8374ORDER BY outr.col_varchar_key, outr.pk;
8375id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
83761	PRIMARY	outr	NULL	ALL	NULL	NULL	NULL	NULL	17	33.33	Using where; Using filesort
83772	SUBQUERY	innr	NULL	index_merge	PRIMARY,col_varchar_key	col_varchar_key,PRIMARY	3,4	NULL	2	100.00	Using sort_union(col_varchar_key,PRIMARY); Using where
8378Warnings:
8379Note	1003	/* select#1 */ select `test`.`outr`.`col_varchar_key` AS `x`,`test`.`outr`.`pk` AS `y` from `test`.`t1` `outr` where (<in_optimizer>(`test`.`outr`.`col_varchar_key`,`test`.`outr`.`col_varchar_key` in ( <materialize> (/* select#2 */ select `test`.`innr`.`col_varchar_key` from `test`.`t2` `innr` where ((`test`.`innr`.`col_varchar_key` = 'a') or (`test`.`innr`.`pk` = 8)) ), <primary_index_lookup>(`test`.`outr`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`outr`.`col_varchar_key` = `materialized-subquery`.`col_varchar_key`))))) and (`test`.`outr`.`col_varchar_nokey` < 't')) order by `test`.`outr`.`col_varchar_key`,`test`.`outr`.`pk`
8380SELECT outr.col_varchar_key AS x, outr.pk AS y
8381FROM t1 AS outr
8382WHERE outr.col_varchar_key IN (SELECT innr.col_varchar_key
8383FROM t2 AS innr
8384WHERE innr.col_varchar_key = 'a' OR innr.pk = 8)
8385AND outr.col_varchar_nokey < 't'
8386ORDER BY outr.col_varchar_key, outr.pk;
8387x	y
8388a	1
8389a	5
8390c	3
8391c	13
8392DROP TABLE t1, t2;
8393# End of bug#12603200
8394#
8395# Bug#12603183: Segfault in hp_movelink
8396#
8397CREATE TABLE t1 (
8398col_varchar_key varchar(1) ,
8399col_varchar_nokey varchar(1) ,
8400KEY col_varchar_key(col_varchar_key)
8401);
8402INSERT INTO t1 VALUES
8403('i','i'),
8404('h','h'),
8405('q','q'),
8406('a','a'),
8407('v','v'),
8408('u','u'),
8409('s','s'),
8410('y','y'),
8411('z','z'),
8412('h','h'),
8413('p','p'),
8414('e','e'),
8415('i','i'),
8416('y','y'),
8417('w','w');
8418CREATE TABLE t2 (
8419col_varchar_nokey varchar(1)
8420);
8421INSERT INTO t2 VALUES
8422('b');
8423EXPLAIN SELECT grandparent1.col_varchar_nokey
8424FROM t1 AS grandparent1 LEFT JOIN t2 AS grandparent2 USING (col_varchar_nokey)
8425WHERE (grandparent1.col_varchar_key) IN
8426(SELECT parent1.col_varchar_nokey
8427FROM t1 AS parent1
8428WHERE parent1.col_varchar_key IN
8429(SELECT child1.col_varchar_nokey AS c1
8430FROM t1 AS child1 LEFT JOIN t2 AS child2
8431ON (child1.col_varchar_key > child2.col_varchar_nokey)));
8432id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
84331	PRIMARY	grandparent1	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	Using where
84341	PRIMARY	grandparent2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
84352	SUBQUERY	parent1	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	Using where
84363	SUBQUERY	child1	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	NULL
84373	SUBQUERY	child2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
8438Warnings:
8439Note	1003	/* select#1 */ select `test`.`grandparent1`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`t1` `grandparent1` left join `test`.`t2` `grandparent2` on((`test`.`grandparent2`.`col_varchar_nokey` = `test`.`grandparent1`.`col_varchar_nokey`)) where <in_optimizer>(`test`.`grandparent1`.`col_varchar_key`,`test`.`grandparent1`.`col_varchar_key` in ( <materialize> (/* select#2 */ select `test`.`parent1`.`col_varchar_nokey` from `test`.`t1` `parent1` where <in_optimizer>(`test`.`parent1`.`col_varchar_key`,`test`.`parent1`.`col_varchar_key` in ( <materialize> (/* select#3 */ select `test`.`child1`.`col_varchar_nokey` AS `c1` from `test`.`t1` `child1` left join `test`.`t2` `child2` on((`test`.`child1`.`col_varchar_key` > `test`.`child2`.`col_varchar_nokey`)) where 1 ), <primary_index_lookup>(`test`.`parent1`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`parent1`.`col_varchar_key` = `materialized-subquery`.`c1`))))) ), <primary_index_lookup>(`test`.`grandparent1`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`grandparent1`.`col_varchar_key` = `materialized-subquery`.`col_varchar_nokey`)))))
8440SELECT grandparent1.col_varchar_nokey
8441FROM t1 AS grandparent1 LEFT JOIN t2 AS grandparent2 USING (col_varchar_nokey)
8442WHERE (grandparent1.col_varchar_key) IN
8443(SELECT parent1.col_varchar_nokey
8444FROM t1 AS parent1
8445WHERE parent1.col_varchar_key IN
8446(SELECT child1.col_varchar_nokey AS c1
8447FROM t1 AS child1 LEFT JOIN t2 AS child2
8448ON (child1.col_varchar_key > child2.col_varchar_nokey)));
8449col_varchar_nokey
8450a
8451e
8452h
8453h
8454i
8455i
8456p
8457q
8458s
8459u
8460v
8461w
8462y
8463y
8464z
8465DROP TABLE t1, t2;
8466# End of test for bug#12603183.
8467#
8468# Bug#12818569: Diff nr of rows returned when using IN/ALL+subquery
8469#
8470CREATE TABLE t1 (
8471col_int_key INT NOT NULL,
8472col_datetime_key DATETIME NOT NULL,
8473col_varchar_key VARCHAR(1) NOT NULL,
8474KEY col_int_key (col_int_key),
8475KEY col_datetime_key(col_datetime_key),
8476KEY col_varchar_key (col_varchar_key,col_int_key)
8477) ENGINE=InnoDB;
8478INSERT INTO t1 VALUES
8479(7,'2004-06-06 04:22:12','v'), (0,'2005-11-13 01:12:31','s'),
8480(9,'2002-05-04 01:50:00','l'), (3,'2004-10-27 10:28:45','y'),
8481(4,'2006-07-22 05:24:23','c'), (2,'2002-05-16 21:34:03','i'),
8482(5,'2008-04-17 10:45:30','h'), (3,'2009-04-21 02:58:02','q'),
8483(1,'2008-01-11 11:01:51','a'), (3,'1900-01-01 00:00:00','v'),
8484(6,'2007-05-17 18:24:57','u'), (7,'2007-08-07 00:00:00','s'),
8485(5,'2001-08-28 00:00:00','y'), (1,'2004-04-16 00:27:28','z'),
8486(204,'2005-05-03 07:06:22','h'), (224,'2009-03-11 17:09:50','p'),
8487(9,'2007-12-08 01:54:28','e'), (5,'2009-07-28 18:19:54','i'),
8488(0,'2008-06-08 00:00:00','y'), (3,'2005-02-09 09:20:26','w');
8489CREATE TABLE t2 (
8490col_varchar_nokey VARCHAR(1) NOT NULL
8491) ENGINE=InnoDB;
8492INSERT INTO t2 VALUES ('v'), ('y'), ('j'), ('c'), ('d'), ('r');
8493explain SELECT col_varchar_key
8494FROM t1
8495WHERE col_varchar_key IN (SELECT col_varchar_nokey
8496FROM t2)
8497ORDER BY col_datetime_key LIMIT 4;
8498id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
84991	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where; Using filesort
85002	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
8501Warnings:
8502Note	1003	/* select#1 */ select `test`.`t1`.`col_varchar_key` AS `col_varchar_key` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`col_varchar_key`,`test`.`t1`.`col_varchar_key` in ( <materialize> (/* select#2 */ select `test`.`t2`.`col_varchar_nokey` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`t1`.`col_varchar_key` = `materialized-subquery`.`col_varchar_nokey`))))) order by `test`.`t1`.`col_datetime_key` limit 4
8503SELECT col_varchar_key
8504FROM t1
8505WHERE col_varchar_key IN (SELECT col_varchar_nokey
8506FROM t2)
8507ORDER BY col_datetime_key LIMIT 4;
8508col_varchar_key
8509v
8510y
8511v
8512y
8513DROP TABLE t1, t2;
8514# End of test for bug#12818569.
8515#
8516# Bug#12803439: Assert in replace_subcondition() on update query
8517#
8518CREATE TABLE t1(a INTEGER);
8519INSERT INTO t1 values(1), (2);
8520CREATE TABLE t2(a INTEGER);
8521INSERT INTO t2 VALUES(1), (3);
8522SELECT *
8523FROM t1
8524WHERE a IN (SELECT a
8525FROM t2
8526HAVING a IN (SELECT a
8527FROM t2)
8528)
8529HAVING a IN (SELECT a
8530FROM t2);
8531a
85321
8533DROP TABLE t1, t2;
8534# End of test for bug#12803439.
8535#
8536# Bug#12797534: Segfault in hp_movelink still exists
8537#
8538CREATE TABLE t1 (
8539g1 VARCHAR(1) NOT NULL
8540) ENGINE=InnoDB;
8541INSERT INTO t1 VALUES ('d'), ('s');
8542CREATE TABLE t2 (
8543pk INT NOT NULL,
8544col_int_key INT NOT NULL,
8545col_varchar_key VARCHAR(1) NOT NULL,
8546col_varchar_nokey VARCHAR(1) NOT NULL,
8547PRIMARY KEY (pk),
8548KEY col_varchar_key(col_varchar_key, col_int_key)
8549) ENGINE=InnoDB;
8550INSERT INTO t2 VALUES
8551(1,4,'j','j'), (2,6,'v','v'), (3,3,'c','c'), (4,5,'m','m'),
8552(5,3,'d','d'), (6,246,'d','d'), (7,2,'y','y'), (8,9,'t','t'),
8553(9,3,'d','d'), (10,8,'s','s'), (11,1,'r','r'), (12,8,'m','m'),
8554(13,8,'b','b'), (14,5,'x','x'), (15,7,'g','g'), (16,5,'p','p'),
8555(17,1,'q','q'), (18,6,'w','w'), (19,2,'d','d'), (20,9,'e','e');
8556CREATE TABLE t3 (
8557pk INTEGER NOT NULL,
8558PRIMARY KEY (pk)
8559) ENGINE=InnoDB;
8560INSERT INTO t3 VALUES (10);
8561EXPLAIN SELECT *
8562FROM t1
8563WHERE g1 NOT IN
8564(SELECT  grandparent1.col_varchar_nokey AS g1
8565FROM t2 AS grandparent1
8566WHERE grandparent1.col_varchar_key IN
8567(SELECT parent1.col_varchar_nokey AS p1
8568FROM t2 AS parent1 LEFT JOIN t3 AS parent2 USING (pk)
8569)
8570AND grandparent1.col_varchar_key IS NOT NULL
8571);
8572id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
85731	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	ROWS	100.00	Using where
85742	SUBQUERY	grandparent1	NULL	ALL	col_varchar_key	NULL	NULL	NULL	ROWS	90.00	Using where
85753	SUBQUERY	parent1	NULL	ALL	NULL	NULL	NULL	NULL	ROWS	100.00	NULL
85763	SUBQUERY	parent2	NULL	eq_ref	PRIMARY	PRIMARY	4	test.parent1.pk	ROWS	100.00	Using index
8577Warnings:
8578Note	1003	/* select#1 */ select `test`.`t1`.`g1` AS `g1` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`g1`,`test`.`t1`.`g1` in ( <materialize> (/* select#2 */ select `test`.`grandparent1`.`col_varchar_nokey` AS `g1` from `test`.`t2` `grandparent1` where (<in_optimizer>(`test`.`grandparent1`.`col_varchar_key`,`test`.`grandparent1`.`col_varchar_key` in ( <materialize> (/* select#3 */ select `test`.`parent1`.`col_varchar_nokey` AS `p1` from `test`.`t2` `parent1` left join `test`.`t3` `parent2` on((`test`.`parent2`.`pk` = `test`.`parent1`.`pk`)) where 1 ), <primary_index_lookup>(`test`.`grandparent1`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`grandparent1`.`col_varchar_key` = `materialized-subquery`.`p1`))))) and (`test`.`grandparent1`.`col_varchar_key` is not null)) ), <primary_index_lookup>(`test`.`t1`.`g1` in <temporary table> on <auto_key> where ((`test`.`t1`.`g1` = `materialized-subquery`.`g1`)))))))
8579SELECT *
8580FROM t1
8581WHERE g1 NOT IN
8582(SELECT  grandparent1.col_varchar_nokey AS g1
8583FROM t2 AS grandparent1
8584WHERE grandparent1.col_varchar_key IN
8585(SELECT parent1.col_varchar_nokey AS p1
8586FROM t2 AS parent1 LEFT JOIN t3 AS parent2 USING (pk)
8587)
8588AND grandparent1.col_varchar_key IS NOT NULL
8589);
8590g1
8591DROP TABLE t1, t2, t3;
8592CREATE TABLE t1 (
8593pk INTEGER AUTO_INCREMENT,
8594col_int_key INTEGER ,
8595col_varchar_key VARCHAR(1) ,
8596col_varchar_nokey VARCHAR(1) ,
8597PRIMARY KEY (pk),
8598KEY (col_varchar_key,col_int_key)
8599) ENGINE=INNODB;
8600INSERT INTO t1 (col_int_key,col_varchar_key,col_varchar_nokey) VALUES
8601(0,'x','x'), (1,'j','j'), (1,'r','r'), (9,'v','v'), (5,'r','r');
8602CREATE TABLE t2 (
8603pk INTEGER AUTO_INCREMENT,
8604col_int_key INTEGER ,
8605col_varchar_key VARCHAR(1) ,
8606col_varchar_nokey VARCHAR(1) ,
8607PRIMARY KEY (pk),
8608KEY (col_int_key),
8609KEY (col_varchar_key,col_int_key)
8610) AUTO_INCREMENT=10 ENGINE=INNODB;
8611INSERT INTO t2 (col_int_key, col_varchar_key, col_varchar_nokey) VALUES
8612(NULL,'x','x'), (NULL,'j','j'), (8,'c','c');
8613CREATE TABLE t3
8614SELECT outr.col_varchar_nokey AS x
8615FROM t1 AS outr
8616WHERE outr.col_varchar_nokey IN
8617(SELECT innr.col_varchar_nokey AS y
8618FROM t2 AS innr
8619WHERE innr.col_int_key IS NULL)
8620AND outr.col_varchar_nokey IS NOT NULL
8621AND NOT col_varchar_key IS NULL;
8622SELECT *
8623FROM t3
8624WHERE x NOT IN
8625(SELECT outr.col_varchar_nokey AS x
8626FROM t1 AS outr
8627WHERE outr.col_varchar_nokey IN
8628(SELECT innr.col_varchar_nokey AS y
8629FROM t2 AS innr
8630WHERE innr.col_int_key IS NULL)
8631AND outr.col_varchar_nokey IS NOT NULL
8632AND NOT col_varchar_key IS NULL);
8633x
8634DROP TABLE t1, t2, t3;
8635# End of test for bug#12797534.
8636#
8637# Bug#12714094: Assert in optimize_semijoin_nests()
8638#
8639CREATE TABLE it (
8640pk int NOT NULL,
8641col_varchar VARCHAR(10) DEFAULT NULL,
8642PRIMARY KEY (pk)
8643) ENGINE=MyISAM;
8644INSERT INTO it VALUES (1, 'g');
8645CREATE TABLE ot
8646SELECT alias1.pk AS field1
8647FROM it AS alias1
8648LEFT JOIN it AS alias2
8649ON alias1.col_varchar = alias2.col_varchar
8650;
8651SELECT *
8652FROM ot
8653WHERE field1 IN (
8654SELECT alias1.pk
8655FROM it AS alias1
8656LEFT JOIN it AS alias2
8657ON alias1.col_varchar = alias2.col_varchar
8658);
8659field1
86601
8661DROP TABLE it, ot;
8662# End of test for bug#12714094
8663#
8664# Bug#12867557: Valgrind: conditional jump/move at key_cmp
8665#
8666CREATE TABLE t1 (
8667pk INTEGER AUTO_INCREMENT,
8668col_int_key INTEGER,
8669PRIMARY KEY (pk),
8670KEY (col_int_key)
8671) AUTO_INCREMENT=10;
8672INSERT INTO t1 (col_int_key) VALUES (8);
8673CREATE TABLE t2 (
8674pk INTEGER AUTO_INCREMENT,
8675col_int_key INTEGER,
8676col_time_key TIME,
8677PRIMARY KEY (pk),
8678KEY (col_int_key),
8679KEY (col_time_key)
8680)  AUTO_INCREMENT=10;
8681INSERT INTO t2 (col_int_key, col_time_key)
8682VALUES
8683(8, '22:55:23.019225'), (7, '10:19:31.050677'), (1, '14:40:36.038608'),
8684(7, '04:37:47.062416'), (9, '19:34:06.054514'), (NULL,'20:35:33.022996'),
8685(1, NULL), (9, '14:43:37.057393'), (2, '02:23:09.043438'),
8686(9, '01:22:45.041064'), (2, '00:00:00'), (4, '00:13:25.038482'),
8687(0, '03:47:16.042671'), (4, '01:41:48.007423'), (8, '00:00:00'),
8688(NULL, '22:32:04.047407'), (NULL, '16:44:14.028443'), (0, '17:38:37.059754'),
8689(NULL, '08:46:48.042388'), (8, '14:11:27.044095');
8690CREATE TABLE t0
8691SELECT DISTINCT grandparent1.col_time_key AS g1
8692FROM t2 AS grandparent1
8693WHERE grandparent1.col_int_key IN
8694(SELECT parent1.col_int_key AS p1
8695FROM t1 AS parent1)
8696AND grandparent1.pk > 9;
8697UPDATE t0
8698SET g1 = g1
8699WHERE g1 IN
8700(SELECT grandparent1.col_time_key AS g1
8701FROM t2 AS grandparent1
8702WHERE grandparent1.col_int_key IN
8703(SELECT parent1.col_int_key AS p1
8704FROM t1 AS parent1)
8705AND grandparent1.pk > 9);
8706DROP TABLE t0, t1, t2;
8707# End of test for bug#12867557
8708#
8709# Bug#12711441: crash in fix_after_pullout
8710#
8711CREATE TABLE t1 (
8712pk int NOT NULL,
8713col_int_nokey int DEFAULT NULL,
8714col_int_key int DEFAULT NULL,
8715col_time_key time DEFAULT NULL,
8716col_varchar_key varchar(1) DEFAULT NULL,
8717PRIMARY KEY (pk)
8718);
8719CREATE VIEW v1 AS SELECT * FROM t1;
8720CREATE TABLE t2 (
8721col_int_key int DEFAULT NULL,
8722col_varchar_key varchar(1) DEFAULT NULL,
8723col_varchar_nokey varchar(1) DEFAULT NULL,
8724KEY col_varchar_key(col_varchar_key, col_int_key)
8725);
8726CREATE TABLE t3 (
8727pk int NOT NULL,
8728col_int_key INT DEFAULT NULL,
8729PRIMARY KEY (pk)
8730);
8731CREATE TABLE t4 (
8732col_int_nokey INT DEFAULT NULL,
8733col_varchar_key varchar(1) DEFAULT NULL,
8734col_varchar_nokey varchar(1) DEFAULT NULL,
8735KEY col_varchar_key(col_varchar_key)
8736);
8737CREATE TABLE ts
8738SELECT alias1.col_time_key AS field1
8739FROM v1 AS alias1
8740RIGHT JOIN t3 AS alias2
8741ON alias2.col_int_key = alias1.col_int_nokey
8742WHERE alias1.pk >= SOME(
8743SELECT SQ1_alias1.pk AS SQ1_field1
8744FROM t3 AS SQ1_alias1
8745INNER JOIN (t2 AS SQ1_alias2
8746INNER JOIN t4 AS SQ1_alias3
8747ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
8748ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
8749WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
8750AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
8751;
8752SELECT * FROM ts WHERE field1 IN (
8753SELECT alias1.col_time_key AS field1
8754FROM v1 AS alias1
8755RIGHT JOIN t3 AS alias2
8756ON alias2.col_int_key = alias1.col_int_nokey
8757WHERE alias1.pk >= SOME(
8758SELECT SQ1_alias1.pk AS SQ1_field1
8759FROM t3 AS SQ1_alias1
8760INNER JOIN (t2 AS SQ1_alias2
8761INNER JOIN t4 AS SQ1_alias3
8762ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
8763ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
8764WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
8765AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
8766);
8767field1
8768DROP TABLE t1, t2, t3, t4, ts;
8769DROP VIEW v1;
8770# End of test for bug#12711441.
8771#
8772# Bug#12664936: Same query executed as where subquery ...
8773#
8774CREATE TABLE t1 (
8775col_varchar_key VARCHAR(1),
8776KEY col_varchar_key (col_varchar_key)
8777);
8778INSERT INTO t1 VALUES
8779('o'), ('w'), ('m'), ('q'),
8780('f'), ('p'), ('j'), ('c');
8781CREATE TABLE t2 (
8782col_int_nokey INTEGER,
8783col_int_key INTEGER,
8784col_varchar_key varchar(1),
8785KEY col_int_key (col_int_key)
8786);
8787INSERT INTO t2 VALUES
8788(8,5,'u'),(4,5,'p'),(8,1,'o'),(NULL,7,'v'),
8789(1,2,'g'),(2,1,'q'),(NULL,7,'l'),(3,1,'n');
8790CREATE TABLE t4
8791SELECT t2.col_int_nokey, t2.col_varchar_key
8792FROM t1 JOIN t2 ON t2.col_varchar_key = t1.col_varchar_key
8793WHERE t2.col_int_key = 1;
8794EXPLAIN SELECT *
8795FROM t4
8796WHERE (col_int_nokey, col_varchar_key) IN
8797(SELECT t2.col_int_nokey, t2.col_varchar_key
8798FROM t1 JOIN t2 ON t2.col_varchar_key = t1.col_varchar_key
8799WHERE t2.col_int_key = 1
8800);
8801id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
88021	PRIMARY	t4	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
88032	SUBQUERY	t2	NULL	ref	col_int_key	col_int_key	5	const	3	100.00	Using where
88042	SUBQUERY	t1	NULL	ref	col_varchar_key	col_varchar_key	4	test.t2.col_varchar_key	2	100.00	Using index
8805Warnings:
8806Note	1003	/* select#1 */ select `test`.`t4`.`col_int_nokey` AS `col_int_nokey`,`test`.`t4`.`col_varchar_key` AS `col_varchar_key` from `test`.`t4` where <in_optimizer>((`test`.`t4`.`col_int_nokey`,`test`.`t4`.`col_varchar_key`),(`test`.`t4`.`col_int_nokey`,`test`.`t4`.`col_varchar_key`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`col_int_nokey`,`test`.`t2`.`col_varchar_key` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`col_varchar_key` = `test`.`t2`.`col_varchar_key`) and (`test`.`t2`.`col_int_key` = 1)) ), <primary_index_lookup>(`test`.`t4`.`col_int_nokey` in <temporary table> on <auto_key> where ((`test`.`t4`.`col_int_nokey` = `materialized-subquery`.`col_int_nokey`) and (`test`.`t4`.`col_varchar_key` = `materialized-subquery`.`col_varchar_key`)))))
8807SELECT *
8808FROM t4
8809WHERE (col_int_nokey, col_varchar_key) IN
8810(SELECT t2.col_int_nokey, t2.col_varchar_key
8811FROM t1 JOIN t2 ON t2.col_varchar_key = t1.col_varchar_key
8812WHERE t2.col_int_key = 1
8813);
8814col_int_nokey	col_varchar_key
88158	o
88162	q
8817DROP TABLE t1, t2, t4;
8818# End of test for bug#12664936.
8819#
8820# Bug#13340270: assertion table->sort.record_pointers == __null
8821#
8822CREATE TABLE t1 (
8823pk int NOT NULL,
8824col_int_key int DEFAULT NULL,
8825col_varchar_key varchar(1) DEFAULT NULL,
8826col_varchar_nokey varchar(1) DEFAULT NULL,
8827PRIMARY KEY (pk),
8828KEY col_int_key (col_int_key),
8829KEY col_varchar_key (col_varchar_key, col_int_key)
8830) ENGINE=InnoDB;
8831INSERT INTO t1 VALUES
8832(10,8,'x','x'),
8833(11,7,'d','d'),
8834(12,1,'r','r'),
8835(13,7,'f','f'),
8836(14,9,'y','y'),
8837(15,NULL,'u','u'),
8838(16,1,'m','m'),
8839(17,9,NULL,NULL),
8840(18,2,'o','o'),
8841(19,9,'w','w'),
8842(20,2,'m','m'),
8843(21,4,'q','q');
8844CREATE TABLE t2
8845SELECT alias1.col_varchar_nokey AS field1
8846FROM t1 AS alias1 JOIN t1 AS alias2
8847ON alias2.col_int_key = alias1.pk OR
8848alias2.col_int_key = alias1.col_int_key
8849WHERE alias1.pk = 58 OR alias1.col_varchar_key = 'o'
8850
8851;
8852EXPLAIN SELECT *
8853FROM t2
8854WHERE (field1) IN (SELECT alias1.col_varchar_nokey AS field1
8855FROM t1 AS alias1 JOIN t1 AS alias2
8856ON alias2.col_int_key = alias1.pk OR
8857alias2.col_int_key = alias1.col_int_key
8858WHERE alias1.pk = 58 OR alias1.col_varchar_key = 'o'
8859);
8860id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
88611	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
88622	SUBQUERY	alias1	NULL	index_merge	PRIMARY,col_int_key,col_varchar_key	col_varchar_key,PRIMARY	4,4	NULL	2	100.00	Using sort_union(col_varchar_key,PRIMARY); Using where
88632	SUBQUERY	alias2	NULL	ALL	col_int_key	NULL	NULL	NULL	12	19.00	Range checked for each record (index map: 0x2)
8864Warnings:
8865Note	1003	/* select#1 */ select `test`.`t2`.`field1` AS `field1` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`field1`,`test`.`t2`.`field1` in ( <materialize> (/* select#2 */ select `test`.`alias1`.`col_varchar_nokey` AS `field1` from `test`.`t1` `alias1` join `test`.`t1` `alias2` where (((`test`.`alias1`.`pk` = 58) or (`test`.`alias1`.`col_varchar_key` = 'o')) and ((`test`.`alias2`.`col_int_key` = `test`.`alias1`.`pk`) or (`test`.`alias2`.`col_int_key` = `test`.`alias1`.`col_int_key`))) ), <primary_index_lookup>(`test`.`t2`.`field1` in <temporary table> on <auto_key> where ((`test`.`t2`.`field1` = `materialized-subquery`.`field1`)))))
8866SELECT *
8867FROM t2
8868WHERE (field1) IN (SELECT alias1.col_varchar_nokey AS field1
8869FROM t1 AS alias1 JOIN t1 AS alias2
8870ON alias2.col_int_key = alias1.pk OR
8871alias2.col_int_key = alias1.col_int_key
8872WHERE alias1.pk = 58 OR alias1.col_varchar_key = 'o'
8873);
8874field1
8875o
8876o
8877DROP TABLE t1, t2;
8878# End of test for bug#13340270.
8879#
8880# Bug#13335319: Seg fault when analyzing FirstMatch semi-join strategy
8881#
8882CREATE TABLE ot1(a INTEGER);
8883INSERT INTO ot1 VALUES(1), (2), (3);
8884CREATE TABLE ot2(a INTEGER);
8885INSERT INTO ot2 VALUES(1), (2), (4), (6), (8), (10);
8886CREATE TABLE it1(a INTEGER);
8887INSERT INTO it1 VALUES(1), (3), (5), (7);
8888CREATE TABLE it2(a INTEGER);
8889INSERT INTO it2 VALUES(1), (3), (5), (7), (9);
8890explain SELECT ot1.a, ot2.a
8891FROM ot1, ot2
8892WHERE ot1.a IN (SELECT a FROM it1) AND
8893ot2.a IN (SELECT a FROM it2);
8894id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
88951	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
88961	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using where; Using join buffer (Block Nested Loop)
88973	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
88982	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
8899Warnings:
8900Note	1003	/* select#1 */ select `test`.`ot1`.`a` AS `a`,`test`.`ot2`.`a` AS `a` from `test`.`ot1` join `test`.`ot2` where (<in_optimizer>(`test`.`ot1`.`a`,`test`.`ot1`.`a` in ( <materialize> (/* select#2 */ select `test`.`it1`.`a` from `test`.`it1` where 1 ), <primary_index_lookup>(`test`.`ot1`.`a` in <temporary table> on <auto_key> where ((`test`.`ot1`.`a` = `materialized-subquery`.`a`))))) and <in_optimizer>(`test`.`ot2`.`a`,`test`.`ot2`.`a` in ( <materialize> (/* select#3 */ select `test`.`it2`.`a` from `test`.`it2` where 1 ), <primary_index_lookup>(`test`.`ot2`.`a` in <temporary table> on <auto_key> where ((`test`.`ot2`.`a` = `materialized-subquery`.`a`))))))
8901SELECT ot1.a, ot2.a
8902FROM ot1, ot2
8903WHERE ot1.a IN (SELECT a FROM it1) AND
8904ot2.a IN (SELECT a FROM it2);
8905a	a
89061	1
89073	1
8908DROP TABLE ot1, ot2, it1, it2;
8909# End of test for bug#13335319.
8910#
8911# Bug#13334882: Assertion keypart_map failed in MyIsam function
8912#
8913CREATE TABLE t1 (
8914pk int NOT NULL,
8915col_int_nokey INT NOT NULL,
8916col_int_key INT NOT NULL,
8917PRIMARY KEY (pk),
8918KEY col_int_key (col_int_key)
8919) ENGINE=MyISAM;
8920INSERT INTO t1 VALUES
8921(1,4,0),
8922(2,6,8),
8923(3,3,1),
8924(7,2,6),
8925(8,9,1),
8926(9,3,6),
8927(10,8,2),
8928(11,1,4),
8929(12,8,8),
8930(13,8,4),
8931(14,5,4);
8932CREATE TABLE t2 (
8933pk int NOT NULL,
8934col_int_nokey int NOT NULL,
8935col_int_key int NOT NULL,
8936PRIMARY KEY (pk),
8937KEY col_int_key (col_int_key)
8938) ENGINE=MyISAM;
8939INSERT INTO t2 VALUES
8940(10,8,7);
8941CREATE TABLE t3
8942SELECT grandparent1.col_int_nokey AS g1
8943FROM t1 AS grandparent1
8944WHERE (grandparent1.col_int_nokey, grandparent1.col_int_key) IN
8945(SELECT parent1.col_int_key AS p1,
8946parent1.col_int_key AS p2
8947FROM t1 AS parent1
8948LEFT JOIN t2 AS parent2
8949ON parent1.col_int_nokey = parent2.col_int_key
8950)
8951AND grandparent1.col_int_key <> 3
8952;
8953explain SELECT * FROM t3
8954WHERE g1 NOT IN
8955(SELECT grandparent1.col_int_nokey AS g1
8956FROM t1 AS grandparent1
8957WHERE (grandparent1.col_int_nokey, grandparent1.col_int_key) IN
8958(SELECT parent1.col_int_key AS p1,
8959parent1.col_int_key AS p2
8960FROM t1 AS parent1
8961LEFT JOIN t2 AS parent2
8962ON parent1.col_int_nokey = parent2.col_int_key
8963)
8964AND grandparent1.col_int_key <> 3
8965);
8966id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
89671	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
89682	DEPENDENT SUBQUERY	grandparent1	NULL	ALL	col_int_key	NULL	NULL	NULL	11	10.00	Using where
89693	SUBQUERY	parent1	NULL	ALL	col_int_key	NULL	NULL	NULL	11	100.00	NULL
89703	SUBQUERY	parent2	NULL	index	col_int_key	col_int_key	4	NULL	1	100.00	Using where; Using index; Using join buffer (Block Nested Loop)
8971Warnings:
8972Note	1003	/* select#1 */ select '8' AS `g1` from dual where (not(<in_optimizer>('8',<exists>(/* select#2 */ select 1 from `test`.`t1` `grandparent1` where (<in_optimizer>((`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_key`),(`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_key`) in ( <materialize> (/* select#3 */ select `test`.`parent1`.`col_int_key` AS `p1`,`test`.`parent1`.`col_int_key` AS `p2` from `test`.`t1` `parent1` left join `test`.`t2` `parent2` on((`test`.`parent2`.`col_int_key` = `test`.`parent1`.`col_int_nokey`)) where 1 ), <primary_index_lookup>(`test`.`grandparent1`.`col_int_nokey` in <temporary table> on <auto_key> where ((`test`.`grandparent1`.`col_int_nokey` = `materialized-subquery`.`p1`) and (`test`.`grandparent1`.`col_int_key` = `materialized-subquery`.`p2`))))) and (`test`.`grandparent1`.`col_int_key` <> 3) and (<cache>('8') = `test`.`grandparent1`.`col_int_nokey`))))))
8973explain format=json SELECT * FROM t3
8974WHERE g1 NOT IN
8975(SELECT grandparent1.col_int_nokey AS g1
8976FROM t1 AS grandparent1
8977WHERE (grandparent1.col_int_nokey, grandparent1.col_int_key) IN
8978(SELECT parent1.col_int_key AS p1,
8979parent1.col_int_key AS p2
8980FROM t1 AS parent1
8981LEFT JOIN t2 AS parent2
8982ON parent1.col_int_nokey = parent2.col_int_key
8983)
8984AND grandparent1.col_int_key <> 3
8985);
8986EXPLAIN
8987{
8988  "query_block": {
8989    "select_id": 1,
8990    "message": "Impossible WHERE noticed after reading const tables",
8991    "optimized_away_subqueries": [
8992      {
8993        "dependent": true,
8994        "cacheable": false,
8995        "query_block": {
8996          "select_id": 2,
8997          "cost_info": {
8998            "query_cost": "4.23"
8999          },
9000          "table": {
9001            "table_name": "grandparent1",
9002            "access_type": "ALL",
9003            "possible_keys": [
9004              "col_int_key"
9005            ],
9006            "rows_examined_per_scan": 11,
9007            "rows_produced_per_join": 1,
9008            "filtered": "10.00",
9009            "cost_info": {
9010              "read_cost": "2.03",
9011              "eval_cost": "0.22",
9012              "prefix_cost": "4.23",
9013              "data_read_per_join": "17"
9014            },
9015            "used_columns": [
9016              "col_int_nokey",
9017              "col_int_key"
9018            ],
9019            "attached_condition": "(<in_optimizer>((`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_key`),(`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_key`) in ( <materialize> (/* select#3 */ select `test`.`parent1`.`col_int_key` AS `p1`,`test`.`parent1`.`col_int_key` AS `p2` from `test`.`t1` `parent1` left join `test`.`t2` `parent2` on((`test`.`parent2`.`col_int_key` = `test`.`parent1`.`col_int_nokey`)) where 1 ), <primary_index_lookup>(`test`.`grandparent1`.`col_int_nokey` in <temporary table> on <auto_key> where ((`test`.`grandparent1`.`col_int_nokey` = `materialized-subquery`.`p1`) and (`test`.`grandparent1`.`col_int_key` = `materialized-subquery`.`p2`))))) and (`test`.`grandparent1`.`col_int_key` <> 3) and (<cache>('8') = `test`.`grandparent1`.`col_int_nokey`))",
9020            "attached_subqueries": [
9021              {
9022                "table": {
9023                  "table_name": "<materialized_subquery>",
9024                  "access_type": "eq_ref",
9025                  "key": "<auto_key>",
9026                  "key_length": "8",
9027                  "rows_examined_per_scan": 1,
9028                  "materialized_from_subquery": {
9029                    "using_temporary_table": true,
9030                    "dependent": true,
9031                    "cacheable": false,
9032                    "query_block": {
9033                      "select_id": 3,
9034                      "cost_info": {
9035                        "query_cost": "8.44"
9036                      },
9037                      "nested_loop": [
9038                        {
9039                          "table": {
9040                            "table_name": "parent1",
9041                            "access_type": "ALL",
9042                            "possible_keys": [
9043                              "col_int_key"
9044                            ],
9045                            "rows_examined_per_scan": 11,
9046                            "rows_produced_per_join": 11,
9047                            "filtered": "100.00",
9048                            "cost_info": {
9049                              "read_cost": "2.03",
9050                              "eval_cost": "2.20",
9051                              "prefix_cost": "4.23",
9052                              "data_read_per_join": "176"
9053                            },
9054                            "used_columns": [
9055                              "col_int_nokey",
9056                              "col_int_key"
9057                            ]
9058                          }
9059                        },
9060                        {
9061                          "table": {
9062                            "table_name": "parent2",
9063                            "access_type": "index",
9064                            "possible_keys": [
9065                              "col_int_key"
9066                            ],
9067                            "key": "col_int_key",
9068                            "used_key_parts": [
9069                              "col_int_key"
9070                            ],
9071                            "key_length": "4",
9072                            "rows_examined_per_scan": 1,
9073                            "rows_produced_per_join": 11,
9074                            "filtered": "100.00",
9075                            "using_index": true,
9076                            "using_join_buffer": "Block Nested Loop",
9077                            "cost_info": {
9078                              "read_cost": "2.00",
9079                              "eval_cost": "2.20",
9080                              "prefix_cost": "8.44",
9081                              "data_read_per_join": "176"
9082                            },
9083                            "used_columns": [
9084                              "col_int_key"
9085                            ],
9086                            "attached_condition": "<if>(is_not_null_compl(parent2), (`test`.`parent2`.`col_int_key` = `test`.`parent1`.`col_int_nokey`), true)"
9087                          }
9088                        }
9089                      ]
9090                    }
9091                  }
9092                }
9093              }
9094            ]
9095          }
9096        }
9097      }
9098    ]
9099  }
9100}
9101Warnings:
9102Note	1003	/* select#1 */ select '8' AS `g1` from dual where (not(<in_optimizer>('8',<exists>(/* select#2 */ select 1 from `test`.`t1` `grandparent1` where (<in_optimizer>((`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_key`),(`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_key`) in ( <materialize> (/* select#3 */ select `test`.`parent1`.`col_int_key` AS `p1`,`test`.`parent1`.`col_int_key` AS `p2` from `test`.`t1` `parent1` left join `test`.`t2` `parent2` on((`test`.`parent2`.`col_int_key` = `test`.`parent1`.`col_int_nokey`)) where 1 ), <primary_index_lookup>(`test`.`grandparent1`.`col_int_nokey` in <temporary table> on <auto_key> where ((`test`.`grandparent1`.`col_int_nokey` = `materialized-subquery`.`p1`) and (`test`.`grandparent1`.`col_int_key` = `materialized-subquery`.`p2`))))) and (`test`.`grandparent1`.`col_int_key` <> 3) and (<cache>('8') = `test`.`grandparent1`.`col_int_nokey`))))))
9103SELECT * FROM t3
9104WHERE g1 NOT IN
9105(SELECT grandparent1.col_int_nokey AS g1
9106FROM t1 AS grandparent1
9107WHERE (grandparent1.col_int_nokey, grandparent1.col_int_key) IN
9108(SELECT parent1.col_int_key AS p1,
9109parent1.col_int_key AS p2
9110FROM t1 AS parent1
9111LEFT JOIN t2 AS parent2
9112ON parent1.col_int_nokey = parent2.col_int_key
9113)
9114AND grandparent1.col_int_key <> 3
9115);
9116g1
9117DROP TABLE t1, t2, t3;
9118# End of test for bug#13334882.
9119#
9120# Bug#13339643: Assertion on JOIN::flatten_subqueries on second execution
9121#
9122CREATE TABLE t1 (
9123col_int_nokey INT,
9124col_varchar_nokey VARCHAR(1)
9125);
9126INSERT INTO t1 VALUES
9127(1,'o'),
9128(2,'t');
9129CREATE TABLE t2 LIKE t1;
9130INSERT INTO t2 VALUES
9131(1,'o'),
9132(4,'f');
9133CREATE VIEW v_t2 AS SELECT * FROM t2;
9134CREATE TABLE t3 LIKE t1;
9135INSERT INTO t3 VALUES
9136(1,'o'),
9137(4,'f');
9138explain SELECT alias1.col_varchar_nokey
9139FROM t1 AS alias1
9140INNER JOIN v_t2 AS alias2
9141ON alias2.col_int_nokey = alias1.col_int_nokey AND
9142'o' IN (SELECT col_varchar_nokey
9143FROM t3);
9144id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
91451	PRIMARY	alias1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
91461	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
91472	SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
9148Warnings:
9149Note	1003	/* select#1 */ select `test`.`alias1`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`t1` `alias1` join `test`.`t2` where (`test`.`t2`.`col_int_nokey` = `test`.`alias1`.`col_int_nokey`)
9150SELECT alias1.col_varchar_nokey
9151FROM t1 AS alias1
9152INNER JOIN v_t2 AS alias2
9153ON alias2.col_int_nokey = alias1.col_int_nokey AND
9154'o' IN (SELECT col_varchar_nokey
9155FROM t3);
9156col_varchar_nokey
9157o
9158PREPARE stmt FROM "SELECT alias1.col_varchar_nokey
9159FROM t1 AS alias1
9160INNER JOIN v_t2 AS alias2
9161ON alias2.col_int_nokey = alias1.col_int_nokey AND
9162'o' IN (SELECT col_varchar_nokey
9163FROM t3)";
9164EXECUTE stmt;
9165col_varchar_nokey
9166o
9167DROP VIEW v_t2;
9168DROP TABLE t1, t2, t3;
9169# End of test for bug#13339643.
9170#
9171# Bug#13424134: Wrong result on JOIN + nested WHERE ... IN clauses
9172#
9173CREATE TABLE t1 (
9174pk int NOT NULL,
9175col_int_nokey int NOT NULL,
9176col_int_key int NOT NULL,
9177PRIMARY KEY (pk),
9178KEY col_int_key (col_int_key)
9179) ENGINE=MyIsam;
9180INSERT INTO t1 VALUES
9181(10,1,7), (13,7,3), (18,0,1), (23,8,1);
9182CREATE TABLE t2 (
9183pk int NOT NULL,
9184col_int_key int NOT NULL,
9185PRIMARY KEY (pk),
9186KEY col_int_key (col_int_key)
9187) ENGINE=MyIsam;
9188INSERT INTO t2 VALUES (1,7);
9189EXPLAIN SELECT t1a.*
9190FROM t1 AS t1a
9191JOIN t1 AS t1b USING ( col_int_nokey )
9192WHERE t1a.col_int_key IN (
9193SELECT pk
9194FROM t2
9195WHERE col_int_key IN (
9196SELECT col_int_nokey
9197FROM t1
9198)
9199);
9200id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
92011	PRIMARY	t1a	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
92021	PRIMARY	t1b	NULL	ALL	NULL	NULL	NULL	NULL	4	25.00	Using where; Using join buffer (Block Nested Loop)
92032	SUBQUERY	t2	NULL	system	PRIMARY	NULL	NULL	NULL	1	100.00	NULL
92043	DEPENDENT SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	25.00	Using where
9205Warnings:
9206Note	1003	/* select#1 */ select `test`.`t1a`.`pk` AS `pk`,`test`.`t1a`.`col_int_nokey` AS `col_int_nokey`,`test`.`t1a`.`col_int_key` AS `col_int_key` from `test`.`t1` `t1a` join `test`.`t1` `t1b` where ((`test`.`t1b`.`col_int_nokey` = `test`.`t1a`.`col_int_nokey`) and <in_optimizer>(`test`.`t1a`.`col_int_key`,`test`.`t1a`.`col_int_key` in ( <materialize> (/* select#2 */ select '1' from dual where <in_optimizer>('7',<exists>(/* select#3 */ select 1 from `test`.`t1` where (<cache>('7') = `test`.`t1`.`col_int_nokey`))) ), <primary_index_lookup>(`test`.`t1a`.`col_int_key` in <temporary table> on <auto_key> where ((`test`.`t1a`.`col_int_key` = `materialized-subquery`.`pk`))))))
9207SELECT t1a.*
9208FROM t1 AS t1a
9209JOIN t1 AS t1b USING ( col_int_nokey )
9210WHERE t1a.col_int_key IN (
9211SELECT pk
9212FROM t2
9213WHERE col_int_key IN (
9214SELECT col_int_nokey
9215FROM t1
9216)
9217);
9218pk	col_int_nokey	col_int_key
921918	0	1
922023	8	1
9221ALTER TABLE t1 ENGINE=Innodb;
9222ALTER TABLE t2 ENGINE=Innodb;
9223SELECT t1a.*
9224FROM t1 AS t1a
9225JOIN t1 AS t1b USING ( col_int_nokey )
9226WHERE t1a.col_int_key IN (
9227SELECT pk
9228FROM t2
9229WHERE col_int_key IN (
9230SELECT col_int_nokey
9231FROM t1
9232)
9233);
9234pk	col_int_nokey	col_int_key
923518	0	1
923623	8	1
9237DROP TABLE t1, t2;
9238# End of test for bug#13424134.
9239#
9240# Bug#13414014: Extra rows in result on semijoin query with where ...
9241#
9242CREATE TABLE t1 (
9243c INT,
9244d INT,
9245a VARCHAR(1),
9246b VARCHAR(1),
9247KEY a (a)
9248);
9249INSERT INTO t1 VALUES
9250(NULL,8,'x','x'), (7,4,'q','q'), (6,8,'c','c');
9251CREATE TABLE t2 (
9252a VARCHAR(1),
9253KEY a (a)
9254);
9255INSERT INTO t2 VALUES
9256('c'), (NULL), ('x'), ('q');
9257explain SELECT *
9258FROM t2 AS ot
9259WHERE (a, a) IN
9260(SELECT a, b
9261FROM t1 AS it
9262WHERE it.a = 'x' OR it.c > it.d
9263)
9264;
9265id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
92661	PRIMARY	ot	NULL	index	NULL	a	4	NULL	4	100.00	Using where; Using index
92672	SUBQUERY	it	NULL	ALL	a	NULL	NULL	NULL	3	55.56	Using where
9268Warnings:
9269Note	1003	/* select#1 */ select `test`.`ot`.`a` AS `a` from `test`.`t2` `ot` where <in_optimizer>((`test`.`ot`.`a`,`test`.`ot`.`a`),(`test`.`ot`.`a`,`test`.`ot`.`a`) in ( <materialize> (/* select#2 */ select `test`.`it`.`a`,`test`.`it`.`b` from `test`.`t1` `it` where ((`test`.`it`.`a` = 'x') or (`test`.`it`.`c` > `test`.`it`.`d`)) ), <primary_index_lookup>(`test`.`ot`.`a` in <temporary table> on <auto_key> where ((`test`.`ot`.`a` = `materialized-subquery`.`a`) and (`test`.`ot`.`a` = `materialized-subquery`.`b`)))))
9270SELECT *
9271FROM t2 AS ot
9272WHERE (a, a) IN
9273(SELECT a, b
9274FROM t1 AS it
9275WHERE it.a = 'x' OR it.c > it.d
9276)
9277;
9278a
9279q
9280x
9281DROP TABLE t1, t2;
9282# End of test for bug#13414014.
9283#
9284# Bug#13545215: Missing rows on nested in-subquery with materialization
9285#
9286CREATE TABLE t1 (
9287col_int_key int,
9288col_varchar_key varchar(1),
9289col_varchar_nokey varchar(1),
9290KEY col_int_key (col_int_key),
9291KEY col_varchar_key (col_varchar_key,col_int_key)
9292) ;
9293INSERT INTO t1 VALUES
9294(8,'x','x'), (0,'p','p'), (8,'c','c');
9295CREATE TABLE t2 (
9296pk int NOT NULL,
9297col_varchar_key varchar(1),
9298col_varchar_nokey varchar(1),
9299PRIMARY KEY (pk),
9300KEY col_varchar_key (col_varchar_key)
9301);
9302INSERT INTO t2 VALUES
9303(1,'v','v'), (2,'v','v'), (3,'c','c'), (4,NULL,NULL),
9304(5,'x','x'), (6,'i','i'), (7,'e','e'), (8,'p','p');
9305CREATE TABLE t3 (
9306col_int_nokey int
9307);
9308INSERT INTO t3 VALUES (7);
9309explain SELECT grandparent1.col_varchar_nokey
9310FROM t1 AS grandparent1 JOIN t1 AS grandparent2 USING (col_int_key)
9311WHERE grandparent1.col_varchar_key IN (
9312SELECT col_varchar_nokey
9313FROM t2 AS parent1
9314WHERE col_varchar_key IN (
9315SELECT child1.col_varchar_nokey
9316FROM t2 AS child1 LEFT JOIN t3 AS child2
9317ON child1.pk < child2.col_int_nokey
9318)
9319);
9320id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
93211	PRIMARY	grandparent1	NULL	ALL	col_int_key	NULL	NULL	NULL	3	100.00	Using where
93221	PRIMARY	grandparent2	NULL	index	col_int_key	col_int_key	5	NULL	3	33.33	Using where; Using index; Using join buffer (Block Nested Loop)
93232	SUBQUERY	parent1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	Using where
93243	SUBQUERY	child1	NULL	ALL	NULL	NULL	NULL	NULL	8	100.00	NULL
93253	SUBQUERY	child2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (Block Nested Loop)
9326Warnings:
9327Note	1003	/* select#1 */ select `test`.`grandparent1`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`t1` `grandparent1` join `test`.`t1` `grandparent2` where ((`test`.`grandparent2`.`col_int_key` = `test`.`grandparent1`.`col_int_key`) and <in_optimizer>(`test`.`grandparent1`.`col_varchar_key`,`test`.`grandparent1`.`col_varchar_key` in ( <materialize> (/* select#2 */ select `test`.`parent1`.`col_varchar_nokey` from `test`.`t2` `parent1` where <in_optimizer>(`test`.`parent1`.`col_varchar_key`,`test`.`parent1`.`col_varchar_key` in ( <materialize> (/* select#3 */ select `test`.`child1`.`col_varchar_nokey` from `test`.`t2` `child1` left join `test`.`t3` `child2` on((`test`.`child1`.`pk` < `test`.`child2`.`col_int_nokey`)) where 1 ), <primary_index_lookup>(`test`.`parent1`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`parent1`.`col_varchar_key` = `materialized-subquery`.`col_varchar_nokey`))))) ), <primary_index_lookup>(`test`.`grandparent1`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`grandparent1`.`col_varchar_key` = `materialized-subquery`.`col_varchar_nokey`))))))
9328SELECT grandparent1.col_varchar_nokey
9329FROM t1 AS grandparent1 JOIN t1 AS grandparent2 USING (col_int_key)
9330WHERE grandparent1.col_varchar_key IN (
9331SELECT col_varchar_nokey
9332FROM t2 AS parent1
9333WHERE col_varchar_key IN (
9334SELECT child1.col_varchar_nokey
9335FROM t2 AS child1 LEFT JOIN t3 AS child2
9336ON child1.pk < child2.col_int_nokey
9337)
9338);
9339col_varchar_nokey
9340c
9341c
9342p
9343x
9344x
9345DROP TABLE t1, t2, t3;
9346# End of test for bug#13545215.
9347#
9348# BUG#13553211 - MISSING ROWS ON SELECT WITH IN-SUBQUERY AND
9349# MATERIALIZATION + SEMIJOIN ON
9350#
9351CREATE TABLE t1 (
9352col_int_key int(11) DEFAULT NULL,
9353col_varchar_key varchar(1) DEFAULT NULL,
9354col_varchar_nokey varchar(1) DEFAULT NULL,
9355KEY col_int_key (col_int_key),
9356KEY col_varchar_key (col_varchar_key,col_int_key)
9357);
9358INSERT INTO t1 VALUES (4,'v','v');
9359INSERT INTO t1 VALUES (62,'v','v');
9360INSERT INTO t1 VALUES (7,'c','c');
9361INSERT INTO t1 VALUES (1,NULL,NULL);
9362EXPLAIN SELECT
9363alias1.col_varchar_nokey AS a1_nokey,
9364alias1.col_varchar_key AS a1_key,
9365alias2.col_varchar_nokey AS a2_nokey
9366FROM
9367t1 AS alias1, t1 AS alias2
9368WHERE
9369(alias1.col_varchar_nokey,alias2.col_varchar_nokey)
9370IN
9371(
9372SELECT
9373sq2_alias2.col_varchar_nokey, sq2_alias1.col_varchar_key
9374FROM
9375t1 AS sq2_alias1, t1 AS sq2_alias2
9376)
9377;
9378id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
93791	PRIMARY	alias1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	NULL
93801	PRIMARY	alias2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
93812	SUBQUERY	sq2_alias1	NULL	index	col_varchar_key	col_varchar_key	9	NULL	4	100.00	Using index
93822	SUBQUERY	sq2_alias2	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using join buffer (Block Nested Loop)
9383Warnings:
9384Note	1003	/* select#1 */ select `test`.`alias1`.`col_varchar_nokey` AS `a1_nokey`,`test`.`alias1`.`col_varchar_key` AS `a1_key`,`test`.`alias2`.`col_varchar_nokey` AS `a2_nokey` from `test`.`t1` `alias1` join `test`.`t1` `alias2` where <in_optimizer>((`test`.`alias1`.`col_varchar_nokey`,`test`.`alias2`.`col_varchar_nokey`),(`test`.`alias1`.`col_varchar_nokey`,`test`.`alias2`.`col_varchar_nokey`) in ( <materialize> (/* select#2 */ select `test`.`sq2_alias2`.`col_varchar_nokey`,`test`.`sq2_alias1`.`col_varchar_key` from `test`.`t1` `sq2_alias1` join `test`.`t1` `sq2_alias2` where 1 ), <primary_index_lookup>(`test`.`alias1`.`col_varchar_nokey` in <temporary table> on <auto_key> where ((`test`.`alias1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_nokey`) and (`test`.`alias2`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_key`)))))
9385SELECT
9386alias1.col_varchar_nokey AS a1_nokey,
9387alias1.col_varchar_key AS a1_key,
9388alias2.col_varchar_nokey AS a2_nokey
9389FROM
9390t1 AS alias1, t1 AS alias2
9391WHERE
9392(alias1.col_varchar_nokey,alias2.col_varchar_nokey)
9393IN
9394(
9395SELECT
9396sq2_alias2.col_varchar_nokey, sq2_alias1.col_varchar_key
9397FROM
9398t1 AS sq2_alias1, t1 AS sq2_alias2
9399)
9400;
9401a1_nokey	a1_key	a2_nokey
9402c	c	c
9403c	c	v
9404c	c	v
9405v	v	c
9406v	v	c
9407v	v	v
9408v	v	v
9409v	v	v
9410v	v	v
9411DROP TABLE t1;
9412#
9413# Bug#13541406: Wrong result with loosescan on select .. where .. in
9414#
9415CREATE TABLE t1 (
9416col_int_key INT NOT NULL,
9417col_varchar_nokey VARCHAR(1) NOT NULL,
9418KEY col_int_key (col_int_key)
9419) ENGINE=InnoDB;
9420INSERT INTO t1 VALUES
9421(7,'v'), (0,'s'), (9,'l'), (3,'y'), (4,'c'), (2,'i'), (5,'h'), (3,'q'),
9422(1,'a'), (3,'v'), (6,'u'), (7,'s'), (5,'y'), (1,'z'), (204,'h'), (224,'p'),
9423(9,'e'), (5,'i'), (0,'y'), (3,'w');
9424CREATE TABLE t2 (
9425pk INT NOT NULL,
9426col_int_key INT NOT NULL,
9427col_varchar_key VARCHAR(1) NOT NULL,
9428col_varchar_nokey VARCHAR(1) NOT NULL,
9429PRIMARY KEY (pk),
9430KEY col_int_key (col_int_key),
9431KEY col_varchar_key (col_varchar_key,col_int_key)
9432) ENGINE=InnoDB;
9433INSERT INTO t2 VALUES
9434(1,0,'j','j'), (2,8,'v','v'), (3,1,'c','c'), (4,8,'m','m'),
9435(5,9,'d','d'), (6,24,'d','d'), (7,6,'y','y'), (8,1,'t','t'),
9436(9,6,'d','d'), (10,2,'s','s'), (11,4,'r','r'), (12,8,'m','m'),
9437(13,4,'b','b'), (14,4,'x','x'), (15,7,'g','g'), (16,4,'p','p'),
9438(17,1,'q','q'), (18,9,'w','w'), (19,4,'d','d'), (20,8,'e','e');
9439# This query should never use a LooseScan strategy
9440explain SELECT ot1.col_int_key AS field1
9441FROM t2 AS ot1, t2 AS ot2
9442WHERE (ot1.col_varchar_key, ot2.col_varchar_nokey) IN (
9443SELECT it2.col_varchar_nokey, it1.col_varchar_key
9444FROM t2 AS it1 JOIN t1 AS it2 ON it2.col_int_key = it1.pk);
9445id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
94461	PRIMARY	ot1	NULL	index	NULL	col_varchar_key	7	NULL	20	100.00	Using index
94471	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where; Using join buffer (Block Nested Loop)
94482	SUBQUERY	it2	NULL	ALL	col_int_key	NULL	NULL	NULL	20	100.00	NULL
94492	SUBQUERY	it1	NULL	eq_ref	PRIMARY,col_varchar_key	PRIMARY	4	test.it2.col_int_key	1	100.00	NULL
9450Warnings:
9451Note	1003	/* select#1 */ select `test`.`ot1`.`col_int_key` AS `field1` from `test`.`t2` `ot1` join `test`.`t2` `ot2` where <in_optimizer>((`test`.`ot1`.`col_varchar_key`,`test`.`ot2`.`col_varchar_nokey`),(`test`.`ot1`.`col_varchar_key`,`test`.`ot2`.`col_varchar_nokey`) in ( <materialize> (/* select#2 */ select `test`.`it2`.`col_varchar_nokey`,`test`.`it1`.`col_varchar_key` from `test`.`t2` `it1` join `test`.`t1` `it2` where (`test`.`it1`.`pk` = `test`.`it2`.`col_int_key`) ), <primary_index_lookup>(`test`.`ot1`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`ot1`.`col_varchar_key` = `materialized-subquery`.`col_varchar_nokey`) and (`test`.`ot2`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_key`)))))
9452SELECT ot1.col_int_key AS field1
9453FROM t2 AS ot1, t2 AS ot2
9454WHERE (ot1.col_varchar_key, ot2.col_varchar_nokey) IN (
9455SELECT it2.col_varchar_nokey, it1.col_varchar_key
9456FROM t2 AS it1 JOIN t1 AS it2 ON it2.col_int_key = it1.pk);
9457field1
94581
94591
94601
94612
94626
94636
94646
94656
94666
94678
94688
94698
94708
94718
94728
94739
9474DROP TABLE t1, t2;
9475# End of test for bug#13541406.
9476#
9477# Bug#13576391: Missing rows on select with in-subquery and
9478# batched-key-access=on and semijoin
9479#
9480CREATE TABLE t1 (
9481col_int_nokey int NOT NULL,
9482col_varchar_key varchar(1) NOT NULL,
9483KEY col_varchar_key (col_varchar_key)
9484) engine=InnoDB;
9485INSERT INTO t1 VALUES
9486(1,'v'), (7,'s'), (4,'l'), (7,'y'), (0,'c'), (2,'i'), (9,'h'), (4,'q'),
9487(0,'a'), (9,'v'), (1,'u'), (3,'s'), (8,'y'), (8,'z'), (18,'h'), (84,'p'),
9488(6,'e'), (3,'i'), (6,'y'), (6,'w');
9489CREATE TABLE t2 (
9490col_int_nokey int NOT NULL,
9491col_varchar_nokey varchar(1) NOT NULL
9492) engine=InnoDB;
9493INSERT INTO t2 VALUES
9494(4,'j'), (6,'v'), (3,'c'), (5,'m'), (3,'d'), (246,'d'), (2,'y'), (9,'t'),
9495(3,'d'), (8,'s'), (1,'r'), (8,'m'), (8,'b'), (5,'x'), (7,'g'), (5,'p'),
9496(1,'q'), (6,'w'), (2,'d'), (9,'e');
9497explain SELECT col_varchar_nokey
9498FROM t2 AS ot
9499WHERE col_varchar_nokey IN (
9500SELECT col_varchar_key
9501FROM t1 AS it
9502WHERE it.col_int_nokey <= it.col_int_nokey
9503AND NOT ot.col_int_nokey < 2
9504)
9505ORDER BY col_varchar_nokey;
9506id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
95071	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where; Using filesort
95082	DEPENDENT SUBQUERY	it	NULL	index_subquery	col_varchar_key	col_varchar_key	3	func	1	100.00	Using where
9509Warnings:
9510Note	1276	Field or reference 'test.ot.col_int_nokey' of SELECT #2 was resolved in SELECT #1
9511Note	1003	/* select#1 */ select `test`.`ot`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`t2` `ot` where <in_optimizer>(`test`.`ot`.`col_varchar_nokey`,<exists>(<index_lookup>(<cache>(`test`.`ot`.`col_varchar_nokey`) in t1 on col_varchar_key where ((`test`.`ot`.`col_int_nokey` >= 2) and (<cache>(`test`.`ot`.`col_varchar_nokey`) = `test`.`it`.`col_varchar_key`))))) order by `test`.`ot`.`col_varchar_nokey`
9512SELECT col_varchar_nokey
9513FROM t2 AS ot
9514WHERE col_varchar_nokey IN (
9515SELECT col_varchar_key
9516FROM t1 AS it
9517WHERE it.col_int_nokey <= it.col_int_nokey
9518AND NOT ot.col_int_nokey < 2
9519)
9520ORDER BY col_varchar_nokey;
9521col_varchar_nokey
9522c
9523e
9524p
9525s
9526v
9527w
9528y
9529ALTER TABLE t1 ENGINE=MyISAM;
9530ALTER TABLE t2 ENGINE=MyISAM;
9531explain SELECT col_varchar_nokey
9532FROM t2 AS ot
9533WHERE col_varchar_nokey IN (
9534SELECT col_varchar_key
9535FROM t1 AS it
9536WHERE it.col_int_nokey <= it.col_int_nokey
9537AND NOT ot.col_int_nokey < 2
9538)
9539ORDER BY col_varchar_nokey;
9540id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
95411	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where; Using filesort
95422	DEPENDENT SUBQUERY	it	NULL	index_subquery	col_varchar_key	col_varchar_key	3	func	2	100.00	Using where
9543Warnings:
9544Note	1276	Field or reference 'test.ot.col_int_nokey' of SELECT #2 was resolved in SELECT #1
9545Note	1003	/* select#1 */ select `test`.`ot`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`t2` `ot` where <in_optimizer>(`test`.`ot`.`col_varchar_nokey`,<exists>(<index_lookup>(<cache>(`test`.`ot`.`col_varchar_nokey`) in t1 on col_varchar_key where ((`test`.`ot`.`col_int_nokey` >= 2) and (<cache>(`test`.`ot`.`col_varchar_nokey`) = `test`.`it`.`col_varchar_key`))))) order by `test`.`ot`.`col_varchar_nokey`
9546SELECT col_varchar_nokey
9547FROM t2 AS ot
9548WHERE col_varchar_nokey IN (
9549SELECT col_varchar_key
9550FROM t1 AS it
9551WHERE it.col_int_nokey <= it.col_int_nokey
9552AND NOT ot.col_int_nokey < 2
9553)
9554ORDER BY col_varchar_nokey;
9555col_varchar_nokey
9556c
9557e
9558p
9559s
9560v
9561w
9562y
9563ALTER TABLE t1 ENGINE=Memory;
9564ALTER TABLE t2 ENGINE=Memory;
9565explain SELECT col_varchar_nokey
9566FROM t2 AS ot
9567WHERE col_varchar_nokey IN (
9568SELECT col_varchar_key
9569FROM t1 AS it
9570WHERE it.col_int_nokey <= it.col_int_nokey
9571AND NOT ot.col_int_nokey < 2
9572)
9573ORDER BY col_varchar_nokey;
9574id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
95751	PRIMARY	ot	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where; Using filesort
95762	DEPENDENT SUBQUERY	it	NULL	index_subquery	col_varchar_key	col_varchar_key	3	func	2	100.00	Using where
9577Warnings:
9578Note	1276	Field or reference 'test.ot.col_int_nokey' of SELECT #2 was resolved in SELECT #1
9579Note	1003	/* select#1 */ select `test`.`ot`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`t2` `ot` where <in_optimizer>(`test`.`ot`.`col_varchar_nokey`,<exists>(<index_lookup>(<cache>(`test`.`ot`.`col_varchar_nokey`) in t1 on col_varchar_key where ((`test`.`ot`.`col_int_nokey` >= 2) and (<cache>(`test`.`ot`.`col_varchar_nokey`) = `test`.`it`.`col_varchar_key`))))) order by `test`.`ot`.`col_varchar_nokey`
9580SELECT col_varchar_nokey
9581FROM t2 AS ot
9582WHERE col_varchar_nokey IN (
9583SELECT col_varchar_key
9584FROM t1 AS it
9585WHERE it.col_int_nokey <= it.col_int_nokey
9586AND NOT ot.col_int_nokey < 2
9587)
9588ORDER BY col_varchar_nokey;
9589col_varchar_nokey
9590c
9591e
9592p
9593s
9594v
9595w
9596y
9597DROP TABLE t1, t2;
9598# End of test for bug#13576391.
9599#
9600# Bug #13589848 "MISSING ROW ON SELECT WITH NESTED IN CLAUSES WHEN LOOSESCAN=ON"
9601#
9602CREATE TABLE t1 (
9603id INT,
9604col_varchar_key VARCHAR(1),
9605col_varchar_nokey VARCHAR(1),
9606KEY (col_varchar_key)
9607);
9608INSERT INTO t1 VALUES (100,'m','m'),
9609(200,'b','b'), (300,'x','x');
9610CREATE TABLE t2 (
9611col_varchar_key VARCHAR(1),
9612col_varchar_nokey VARCHAR(1),
9613KEY (col_varchar_key)
9614);
9615INSERT INTO t2 VALUES ('b','b');
9616CREATE TABLE t3 (
9617col_varchar_key VARCHAR(1),
9618col_varchar_nokey VARCHAR(1),
9619KEY (col_varchar_key)
9620);
9621INSERT INTO t3 VALUES ('k','k');
9622EXPLAIN SELECT gp1.id
9623FROM t1 AS gp1 JOIN t3 AS gp2
9624ON gp2.col_varchar_key <> gp1.col_varchar_nokey
9625WHERE (gp1.col_varchar_nokey, gp1.col_varchar_nokey)
9626IN (
9627SELECT col_varchar_nokey, col_varchar_nokey
9628FROM t1
9629WHERE col_varchar_nokey
9630IN ( SELECT col_varchar_key
9631FROM t2 LEFT JOIN t3 USING (col_varchar_key) )
9632)
9633;
9634id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
96351	PRIMARY	gp2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
96361	PRIMARY	gp1	NULL	ALL	NULL	NULL	NULL	NULL	3	66.67	Using where
96372	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
96383	SUBQUERY	t2	NULL	system	col_varchar_key	NULL	NULL	NULL	1	100.00	NULL
96393	SUBQUERY	t3	NULL	system	col_varchar_key	NULL	NULL	NULL	1	100.00	NULL
9640Warnings:
9641Note	1003	/* select#1 */ select `test`.`gp1`.`id` AS `id` from `test`.`t1` `gp1` where (<in_optimizer>((`test`.`gp1`.`col_varchar_nokey`,`test`.`gp1`.`col_varchar_nokey`),(`test`.`gp1`.`col_varchar_nokey`,`test`.`gp1`.`col_varchar_nokey`) in ( <materialize> (/* select#2 */ select `test`.`t1`.`col_varchar_nokey`,`test`.`t1`.`col_varchar_nokey` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`col_varchar_nokey`,`test`.`t1`.`col_varchar_nokey` in ( <materialize> (/* select#3 */ select 'b' from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`col_varchar_nokey` in <temporary table> on <auto_key> where ((`test`.`t1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_key`))))) ), <primary_index_lookup>(`test`.`gp1`.`col_varchar_nokey` in <temporary table> on <auto_key> where ((`test`.`gp1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_nokey`) and (`test`.`gp1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_nokey`))))) and ('k' <> `test`.`gp1`.`col_varchar_nokey`))
9642SELECT gp1.id
9643FROM t1 AS gp1 JOIN t3 AS gp2
9644ON gp2.col_varchar_key <> gp1.col_varchar_nokey
9645WHERE (gp1.col_varchar_nokey, gp1.col_varchar_nokey)
9646IN (
9647SELECT col_varchar_nokey, col_varchar_nokey
9648FROM t1
9649WHERE col_varchar_nokey
9650IN ( SELECT col_varchar_key
9651FROM t2 LEFT JOIN t3 USING (col_varchar_key) )
9652)
9653;
9654id
9655200
9656DROP TABLE t1,t2,t3;
9657#
9658# Bug #13596176: Missing row on select with nested in clause when
9659#                matr=on and bnl=off + MyISAM
9660#
9661CREATE TABLE t1 (
9662int_key int DEFAULT NULL,
9663vc_key varchar(1) DEFAULT NULL,
9664vc_nokey varchar(1) DEFAULT NULL,
9665KEY int_key (int_key),
9666KEY vc_key (vc_key, int_key)
9667) ENGINE=MyISAM;
9668INSERT INTO t1 VALUES
9669(8,'x','x'), (7,'d','d'), (1,'r','r'), (7,'f','f'),
9670(9,'y','y'), (NULL,'u','u'), (1,'m','m'), (9,NULL,NULL),
9671(2,'o','o'), (9,'w','w'), (2,'m','m'), (4,'q','q'),
9672(0,NULL,NULL), (4,'d','d'), (8,'g','g'), (NULL,'x','x'),
9673(NULL,'f','f'), (0,'p','p'), (NULL,'j','j'), (8,'c','c');
9674CREATE TABLE t2 (
9675int_key int DEFAULT NULL,
9676vc_key varchar(1) DEFAULT NULL,
9677KEY int_key (int_key),
9678KEY vc_key (vc_key, int_key)
9679) ENGINE=MyISAM;
9680INSERT INTO t2 VALUES (8,'g');
9681explain SELECT vc_key
9682FROM t1 as outr
9683WHERE (vc_nokey, vc_key ) IN
9684(SELECT vc_nokey, vc_nokey
9685FROM t1 middle
9686WHERE vc_nokey IN
9687(SELECT child1.vc_key
9688FROM t2 AS child1 JOIN t1 AS child2 USING (int_key)
9689)
9690);
9691id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
96921	PRIMARY	outr	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where
96932	SUBQUERY	middle	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where
96943	SUBQUERY	child1	NULL	system	int_key,vc_key	NULL	NULL	NULL	1	100.00	NULL
96953	SUBQUERY	child2	NULL	ref	int_key	int_key	5	const	3	100.00	Using index
9696Warnings:
9697Note	1003	/* select#1 */ select `test`.`outr`.`vc_key` AS `vc_key` from `test`.`t1` `outr` where <in_optimizer>((`test`.`outr`.`vc_nokey`,`test`.`outr`.`vc_key`),(`test`.`outr`.`vc_nokey`,`test`.`outr`.`vc_key`) in ( <materialize> (/* select#2 */ select `test`.`middle`.`vc_nokey`,`test`.`middle`.`vc_nokey` from `test`.`t1` `middle` where <in_optimizer>(`test`.`middle`.`vc_nokey`,`test`.`middle`.`vc_nokey` in ( <materialize> (/* select#3 */ select 'g' from `test`.`t1` `child2` where (`test`.`child2`.`int_key` = '8') ), <primary_index_lookup>(`test`.`middle`.`vc_nokey` in <temporary table> on <auto_key> where ((`test`.`middle`.`vc_nokey` = `materialized-subquery`.`vc_key`))))) ), <primary_index_lookup>(`test`.`outr`.`vc_nokey` in <temporary table> on <auto_key> where ((`test`.`outr`.`vc_nokey` = `materialized-subquery`.`vc_nokey`) and (`test`.`outr`.`vc_key` = `materialized-subquery`.`vc_nokey`)))))
9698SELECT vc_key
9699FROM t1 as outr
9700WHERE (vc_nokey, vc_key ) IN
9701(SELECT vc_nokey, vc_nokey
9702FROM t1 middle
9703WHERE vc_nokey IN
9704(SELECT child1.vc_key
9705FROM t2 AS child1 JOIN t1 AS child2 USING (int_key)
9706)
9707);
9708vc_key
9709g
9710DROP TABLE t1, t2;
9711# End of test for bug#13596176.
9712#
9713# BUG#11754478: MAX/MIN + SUBQUERY + AND FAILS TO RETURN ANY ROWS
9714# BUG#13599013: MAX/MIN + SUBQUERY IN WHERE CLAUSE MATCHING NO
9715#               ROWS + INDEX DOES NOT RETURN NULL
9716#
9717CREATE TABLE t1 (
9718pk int(11) PRIMARY KEY,
9719int_key int(11),
9720KEY int_key (int_key)
9721);
9722INSERT INTO t1 VALUES (1,0),(2,0),(3,2),(4,0),(5,3),(6,0);
9723SELECT MIN(int_key) FROM t1 WHERE (4, 4) IN (SELECT 1, 2);
9724MIN(int_key)
9725NULL
9726SELECT MIN(int_key) FROM t1 WHERE (4, 4) IN (SELECT 4, 4);
9727MIN(int_key)
97280
9729SELECT MIN(pk) FROM t1 WHERE pk IN (SELECT int_key FROM t1) AND pk = 6;
9730MIN(pk)
9731NULL
9732DROP TABLE t1;
9733# BUG#13726217: Crash in Item_ident::fix_after_pullout()
9734CREATE TABLE t1(a INTEGER) engine=innodb;
9735INSERT INTO t1 VALUES (0);
9736SELECT 0
9737FROM t1
9738WHERE 0 IN
9739(SELECT 0
9740FROM t1
9741WHERE 0 LIKE
9742(SELECT elt(a, 0) AS b
9743FROM t1
9744GROUP BY a
9745HAVING b
9746)
9747);
97480
9749DROP TABLE t1;
9750# End of test for bug#13726217.
9751# BUG#13773979: Missing rows on second execution of prepared statement
9752CREATE TABLE t1 (
9753col_int_nokey INT,
9754col_int_key INT,
9755col_varchar_key VARCHAR(1)
9756);
9757INSERT INTO t1 VALUES
9758(1,7,'v'), (7,0,'s'), (4,9,'l'), (7,3,'y'),
9759(2,2,'i'), (9,5,'h'), (0,1,'a'), (9,3,'v');
9760CREATE VIEW v1 AS SELECT * FROM t1;
9761SELECT *
9762FROM t1
9763WHERE col_int_key IN (
9764SELECT alias1.col_int_nokey AS field1
9765FROM v1 AS alias1
9766WHERE alias1.col_varchar_key < 'v'
9767);
9768col_int_nokey	col_int_key	col_varchar_key
97691	7	v
97707	0	s
97714	9	l
97722	2	i
9773prepare stmt FROM "SELECT *
9774FROM t1
9775WHERE col_int_key IN (
9776SELECT alias1.col_int_nokey AS field1
9777FROM v1 AS alias1
9778WHERE alias1.col_varchar_key < 'v'
9779)";
9780execute stmt;
9781col_int_nokey	col_int_key	col_varchar_key
97821	7	v
97837	0	s
97844	9	l
97852	2	i
9786execute stmt;
9787col_int_nokey	col_int_key	col_varchar_key
97881	7	v
97897	0	s
97904	9	l
97912	2	i
9792DEALLOCATE PREPARE stmt;
9793DROP VIEW v1;
9794DROP TABLE t1;
9795# End of test for bug#13773979.
9796#
9797# BUG#13685026 ASSERTION CUR_SJ_INNER_TABLES == 0 IN
9798# --OPTIMIZE_TABLE_ORDER::CHOOSE_TABLE_ORDER
9799#
9800CREATE TABLE t1 (
9801col_int_key INT(11) NOT NULL,
9802col_datetime_key DATETIME NOT NULL,
9803col_varchar_key VARCHAR(1) NOT NULL,
9804col_varchar_nokey VARCHAR(1) NOT NULL,
9805KEY col_int_key (col_int_key),
9806KEY col_datetime_key (col_datetime_key),
9807KEY col_varchar_key (col_varchar_key,col_int_key)
9808);
9809INSERT INTO t1 VALUES (0,'2002-02-13 17:30:06','j','j');
9810INSERT INTO t1 VALUES (8,'2008-09-27 00:34:58','v','v');
9811CREATE TABLE t2 (
9812col_int_key INT(11) NOT NULL,
9813col_datetime_key DATETIME NOT NULL,
9814col_varchar_key VARCHAR(1) NOT NULL,
9815col_varchar_nokey VARCHAR(1) NOT NULL,
9816KEY col_int_key (col_int_key),
9817KEY col_datetime_key (col_datetime_key),
9818KEY col_varchar_key (col_varchar_key,col_int_key)
9819);
9820INSERT INTO t2 VALUES (7,'2003-08-21 00:00:00','b','b');
9821ANALYZE TABLE t1, t2;
9822Table	Op	Msg_type	Msg_text
9823test.t1	analyze	status	OK
9824test.t2	analyze	status	OK
9825SET @old_depth=@@optimizer_search_depth;
9826SET optimizer_search_depth=4;
9827EXPLAIN SELECT col_datetime_key
9828FROM t1 as outr
9829WHERE col_datetime_key IN (
9830SELECT alias1.col_datetime_key
9831FROM t1 AS alias1
9832LEFT JOIN t1 as alias3
9833STRAIGHT_JOIN ( t2 AS alias4
9834JOIN t1 AS alias5
9835ON alias5.col_varchar_key <= alias4.col_varchar_nokey )
9836ON alias5.col_int_key < alias4.col_int_key
9837ON alias5.col_varchar_key = alias4.col_varchar_key
9838);
9839id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
98401	PRIMARY	outr	NULL	index	NULL	col_datetime_key	5	NULL	2	100.00	Using where; Using index
98412	SUBQUERY	alias1	NULL	index	col_datetime_key	col_datetime_key	5	NULL	2	100.00	Using index
98422	SUBQUERY	alias4	NULL	ALL	col_int_key,col_varchar_key	NULL	NULL	NULL	1	100.00	Using where
98432	SUBQUERY	alias5	NULL	ref	col_int_key,col_varchar_key	col_varchar_key	3	test.alias4.col_varchar_key	1	100.00	Using where; Using index
98442	SUBQUERY	alias3	NULL	index	NULL	col_int_key	4	NULL	2	100.00	Using index
9845Warnings:
9846Note	1003	/* select#1 */ select `test`.`outr`.`col_datetime_key` AS `col_datetime_key` from `test`.`t1` `outr` where <in_optimizer>(`test`.`outr`.`col_datetime_key`,`test`.`outr`.`col_datetime_key` in ( <materialize> (/* select#2 */ select `test`.`alias1`.`col_datetime_key` from `test`.`t1` `alias1` left join (`test`.`t1` `alias3` join `test`.`t2` `alias4` join `test`.`t1` `alias5`) on(((`test`.`alias5`.`col_varchar_key` = `test`.`alias4`.`col_varchar_key`) and (`test`.`alias5`.`col_int_key` < `test`.`alias4`.`col_int_key`) and (`test`.`alias4`.`col_varchar_key` <= `test`.`alias4`.`col_varchar_nokey`))) where 1 ), <primary_index_lookup>(`test`.`outr`.`col_datetime_key` in <temporary table> on <auto_key> where ((`test`.`outr`.`col_datetime_key` = `materialized-subquery`.`col_datetime_key`)))))
9847SELECT col_datetime_key
9848FROM t1 as outr
9849WHERE col_datetime_key IN (
9850SELECT alias1.col_datetime_key
9851FROM t1 AS alias1
9852LEFT JOIN t1 as alias3
9853STRAIGHT_JOIN ( t2 AS alias4
9854JOIN t1 AS alias5
9855ON alias5.col_varchar_key <= alias4.col_varchar_nokey )
9856ON alias5.col_int_key < alias4.col_int_key
9857ON alias5.col_varchar_key = alias4.col_varchar_key
9858);
9859col_datetime_key
98602002-02-13 17:30:06
98612008-09-27 00:34:58
9862DROP TABLE t1,t2;
9863SET @@optimizer_search_depth=@old_depth;
9864#
9865# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT
9866#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
9867#
9868CREATE TABLE t1 (
9869col_int_key INT,
9870col_varchar_key VARCHAR(1),
9871KEY col_int_key (col_int_key),
9872KEY col_varchar_key (col_varchar_key)
9873);
9874INSERT INTO t1 VALUES (8,'x');
9875CREATE TABLE t2 (
9876col_varchar_key VARCHAR(1),
9877KEY col_varchar_key (col_varchar_key)
9878);
9879INSERT INTO t2 VALUES ('x'), ('y');
9880explain SELECT MIN(col_int_key)
9881FROM t1 as t1_outer
9882HAVING (1, 2) IN (
9883SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
9884FROM t1 as t1_inner JOIN t2
9885ON t2.col_varchar_key = t1_inner.col_varchar_key
9886);
9887id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
98881	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
98892	SUBQUERY	t1_inner	NULL	system	col_varchar_key	NULL	NULL	NULL	1	100.00	NULL
98902	SUBQUERY	t2	NULL	ref	col_varchar_key	col_varchar_key	4	const	1	100.00	Using index
9891Warnings:
9892Note	1003	/* select#1 */ select min(`test`.`t1_outer`.`col_int_key`) AS `MIN(col_int_key)` from `test`.`t1` `t1_outer` having <in_optimizer>((1,2),(1,2) in ( <materialize> (/* select#2 */ select '8',max('8') from `test`.`t2` where (`test`.`t2`.`col_varchar_key` = 'x') having 1 ), <primary_index_lookup>(1 in <temporary table> on <auto_key> where ((1 = `materialized-subquery`.`col_int_key`) and (2 = `materialized-subquery`.`MAX(t1_inner.col_int_key)`)))))
9893SELECT MIN(col_int_key)
9894FROM t1 as t1_outer
9895HAVING (1, 2) IN (
9896SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
9897FROM t1 as t1_inner JOIN t2
9898ON t2.col_varchar_key = t1_inner.col_varchar_key
9899);
9900MIN(col_int_key)
9901DROP TABLE t1,t2;
9902# Bug#13838810: Segfault in evaluate_null_complemented_join_record
9903CREATE TABLE t1 (
9904pk int NOT NULL,
9905col_int_nokey int DEFAULT NULL,
9906col_int_key int DEFAULT NULL,
9907col_varchar_key varchar(1) DEFAULT NULL,
9908PRIMARY KEY (pk),
9909KEY col_int_key (col_int_key),
9910KEY col_varchar_key (col_varchar_key,col_int_key)
9911) ENGINE=InnoDB;
9912INSERT INTO t1 VALUES (10,NULL,8,'x');
9913CREATE TABLE t2 (
9914pk int NOT NULL,
9915col_varchar_nokey varchar(1) DEFAULT NULL,
9916PRIMARY KEY (pk)
9917) ENGINE=InnoDB;
9918INSERT INTO t2 VALUES (1,'x');
9919CREATE TABLE t3 (
9920pk int NOT NULL,
9921col_varchar_key varchar(1) DEFAULT NULL,
9922col_varchar_nokey varchar(1) DEFAULT NULL,
9923PRIMARY KEY (pk),
9924KEY col_varchar_key (col_varchar_key)
9925) ENGINE=InnoDB;
9926INSERT INTO t3 VALUES
9927(1,'v','v'), (2,'v','v'), (3,'c','c'), (4,NULL,NULL);
9928EXPLAIN SELECT table1.pk,table2.pk, table3.pk
9929FROM t2 AS table1
9930LEFT JOIN t1 AS table2
9931LEFT JOIN t1 AS table3
9932ON table3.col_int_key = table2.col_int_key
9933ON table3.pk = table2.col_int_nokey AND
9934table1.col_varchar_nokey IN (
9935SELECT subquery3_t1.col_varchar_nokey
9936FROM t3 AS subquery3_t1
9937LEFT JOIN t1 AS subquery3_t2
9938ON subquery3_t2.col_varchar_key = subquery3_t1.col_varchar_key
9939WHERE subquery3_t2.col_int_nokey <> 9
9940)
9941;
9942id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
99431	PRIMARY	table1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
99441	PRIMARY	table2	NULL	ALL	col_int_key	NULL	NULL	NULL	1	100.00	Using where
99451	PRIMARY	table3	NULL	eq_ref	PRIMARY,col_int_key	PRIMARY	4	test.table2.col_int_nokey	1	100.00	Using where
99462	SUBQUERY	subquery3_t2	NULL	ALL	col_varchar_key	NULL	NULL	NULL	1	100.00	Using where
99472	SUBQUERY	subquery3_t1	NULL	ref	col_varchar_key	col_varchar_key	4	test.subquery3_t2.col_varchar_key	1	100.00	NULL
9948Warnings:
9949Note	1003	/* select#1 */ select `test`.`table1`.`pk` AS `pk`,`test`.`table2`.`pk` AS `pk`,`test`.`table3`.`pk` AS `pk` from `test`.`t2` `table1` left join (`test`.`t1` `table2` join `test`.`t1` `table3`) on(((`test`.`table3`.`col_int_key` = `test`.`table2`.`col_int_key`) and (`test`.`table3`.`pk` = `test`.`table2`.`col_int_nokey`) and <in_optimizer>(`test`.`table1`.`col_varchar_nokey`,`test`.`table1`.`col_varchar_nokey` in ( <materialize> (/* select#2 */ select `test`.`subquery3_t1`.`col_varchar_nokey` from `test`.`t3` `subquery3_t1` join `test`.`t1` `subquery3_t2` where ((`test`.`subquery3_t1`.`col_varchar_key` = `test`.`subquery3_t2`.`col_varchar_key`) and (`test`.`subquery3_t2`.`col_int_nokey` <> 9)) ), <primary_index_lookup>(`test`.`table1`.`col_varchar_nokey` in <temporary table> on <auto_key> where ((`test`.`table1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_nokey`))))))) where 1
9950SELECT table1.pk,table2.pk, table3.pk
9951FROM t2 AS table1
9952LEFT JOIN t1 AS table2
9953LEFT JOIN t1 AS table3
9954ON table3.col_int_key = table2.col_int_key
9955ON table3.pk = table2.col_int_nokey AND
9956table1.col_varchar_nokey IN (
9957SELECT subquery3_t1.col_varchar_nokey
9958FROM t3 AS subquery3_t1
9959LEFT JOIN t1 AS subquery3_t2
9960ON subquery3_t2.col_varchar_key = subquery3_t1.col_varchar_key
9961WHERE subquery3_t2.col_int_nokey <> 9
9962)
9963;
9964pk	pk	pk
99651	NULL	NULL
9966DROP TABLE t1, t2, t3;
9967Extra test case for specific code coverage
9968CREATE TABLE t1(pk INTEGER);
9969INSERT INTO t1 VALUES(1), (2);
9970explain SELECT *
9971FROM t1 AS ot1 LEFT JOIN t1 AS ot2
9972ON ot1.pk=ot2.pk AND
9973ot2.pk IN
9974(SELECT it1.pk
9975FROM t1 AS it1 LEFT JOIN t1 AS it2 ON it1.pk=it2.pk);
9976id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
99771	PRIMARY	ot1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
99781	PRIMARY	ot2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
99792	SUBQUERY	it1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
99802	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
9981Warnings:
9982Note	1003	/* select#1 */ select `test`.`ot1`.`pk` AS `pk`,`test`.`ot2`.`pk` AS `pk` from `test`.`t1` `ot1` left join `test`.`t1` `ot2` on(((`test`.`ot2`.`pk` = `test`.`ot1`.`pk`) and <in_optimizer>(`test`.`ot1`.`pk`,`test`.`ot1`.`pk` in ( <materialize> (/* select#2 */ select `test`.`it1`.`pk` from `test`.`t1` `it1` left join `test`.`t1` `it2` on((`test`.`it2`.`pk` = `test`.`it1`.`pk`)) where 1 ), <primary_index_lookup>(`test`.`ot1`.`pk` in <temporary table> on <auto_key> where ((`test`.`ot1`.`pk` = `materialized-subquery`.`pk`))))))) where 1
9983SELECT *
9984FROM t1 AS ot1 LEFT JOIN t1 AS ot2
9985ON ot1.pk=ot2.pk AND
9986ot2.pk IN
9987(SELECT it1.pk
9988FROM t1 AS it1 LEFT JOIN t1 AS it2 ON it1.pk=it2.pk);
9989pk	pk
99901	1
99912	2
9992DROP TABLE t1;
9993# End of test for bug#13838810.
9994#
9995# Bug#13845930: Segfault in st_join_table::and_with_condition
9996#
9997CREATE TABLE t1 (
9998col_int INTEGER
9999);
10000CREATE TABLE t2 (
10001col_varchar_1 VARCHAR(1),
10002col_varchar_2 VARCHAR(1)
10003);
10004INSERT INTO t2 VALUES ('x','x'), ('c','c');
10005PREPARE stmt FROM '
10006SELECT alias2.col_varchar_2 AS field1
10007FROM t2 AS alias1
10008     JOIN
10009      (t2 AS alias2
10010       LEFT JOIN t2 AS alias3
10011       ON (8, 92) IN
10012          (SELECT sq1_alias1.col_int,
10013                  sq1_alias2.col_int
10014           FROM t1 AS sq1_alias1 JOIN t1 AS sq1_alias2
10015          )
10016      )
10017     ON alias3.col_varchar_1 = alias2.col_varchar_2
10018';
10019EXECUTE stmt;
10020field1
10021EXECUTE stmt;
10022field1
10023DEALLOCATE prepare stmt;
10024DROP TABLE t1, t2;
10025# End of test for bug#13845930.
10026#
10027# Bug#13855925: Assert 'prebuilt->search_tuple->n_fields > 0'
10028#               in ha_innobase::index_read
10029#
10030CREATE TABLE t1 (
10031pk INTEGER AUTO_INCREMENT,
10032col_int_nokey INT,
10033col_int_key INT,
10034col_varchar_key VARCHAR(1),
10035col_varchar_nokey VARCHAR(1),
10036PRIMARY KEY (pk),
10037KEY (col_varchar_key)
10038) ENGINE=INNODB;
10039INSERT INTO t1 (
10040col_int_key, col_int_nokey,
10041col_varchar_key, col_varchar_nokey
10042) VALUES
10043(4, 2, 'v','v'), (62, 150, 'v','v'), (7, NULL, 'c','c'), (1, 2, NULL, NULL),
10044(0, 5, 'x','x'), (7, 3, 'i','i'), (7, 1, 'e','e'), (1, 4, 'p','p'),
10045(7, NULL, 's','s'), (1, 2, 'j','j'), (5, 6, 'z','z'), (2, 6, 'c','c'),
10046(0, 8, 'a','a'), (1, 2, 'q','q'), (8, 6, 'y','y'), (1, 8, NULL, NULL),
10047(1, 3, 'r','r'), (9, 3, 'v','v'), (1, 9, NULL, NULL), (5, 6, 'r','r');
10048CREATE TABLE t2 (
10049pk INT AUTO_INCREMENT,
10050col_int_nokey INT,
10051col_int_key INT,
10052PRIMARY KEY (pk),
10053KEY (col_int_key)
10054) AUTO_INCREMENT=10 ENGINE=INNODB;
10055INSERT INTO t2 (col_int_key, col_int_nokey) VALUES
10056(8, NULL), (7, 8), (1, 1), (7, 9), (9, 4), (NULL, 3), (1, 2), (9, NULL),
10057(2, 2), (9, NULL), (2, 6), (4, 7), (0, 2), (4, 5), (8, 7), (NULL, 6),
10058(NULL, 6), (0, 2), (NULL, 9), (8, 6);
10059CREATE TABLE t3 (
10060pk INT AUTO_INCREMENT,
10061col_varchar_key VARCHAR(1),
10062PRIMARY KEY (pk),
10063KEY (col_varchar_key)
10064) ENGINE=INNODB;
10065INSERT INTO t3 (col_varchar_key) VALUES
10066('c'), ('c'), ('q'), ('g'), ('e'), ('l'), (NULL), ('c'), ('h'), ('d'),
10067('c'), ('i'), ('t'), ('g'), ('q'), ('l'), ('n'), ('z'), ('n'), ('r'), ('p');
10068CREATE VIEW v1 AS
10069SELECT table2.col_varchar_nokey AS field1
10070FROM t2 AS table1
10071INNER JOIN (t1 AS table2
10072STRAIGHT_JOIN t2 AS table3
10073ON table3.col_int_key = table2.pk AND
10074table3.col_int_nokey = ANY
10075(SELECT subquery1_t2.col_int_nokey AS subquery1_field1
10076FROM t2 AS subquery1_t1
10077RIGHT OUTER JOIN t1 AS subquery1_t2
10078INNER JOIN t1 AS subquery1_t3
10079ON subquery1_t3.col_int_key = subquery1_t2.pk
10080ON subquery1_t3.col_varchar_key=subquery1_t2.col_varchar_nokey
10081WHERE subquery1_t1.pk > 1
10082)
10083)
10084ON table3.col_int_key IN
10085(SELECT subquery2_t1.col_int_key AS subquery2_field1
10086FROM t2 AS subquery2_t1
10087RIGHT OUTER JOIN t3 AS subquery2_t2
10088LEFT OUTER JOIN t1 AS subquery2_t3
10089ON subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key
10090ON subquery2_t3.pk = subquery2_t2.pk
10091)
10092;
10093explain SELECT * FROM v1;
10094id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
100951	PRIMARY	table1	NULL	index	NULL	col_int_key	5	NULL	20	100.00	Using index
100961	PRIMARY	table2	NULL	ALL	PRIMARY	NULL	NULL	NULL	20	100.00	Using join buffer (Block Nested Loop)
100971	PRIMARY	table3	NULL	ref	col_int_key	col_int_key	5	test.table2.pk	2	100.00	Using where
100983	SUBQUERY	subquery2_t3	NULL	index	PRIMARY,col_varchar_key	col_varchar_key	4	NULL	20	100.00	Using where; Using index
100993	SUBQUERY	subquery2_t2	NULL	eq_ref	PRIMARY,col_varchar_key	PRIMARY	4	test.subquery2_t3.pk	1	7.14	Using where
101003	SUBQUERY	subquery2_t1	NULL	index	col_int_key	col_int_key	5	NULL	20	100.00	Using index; Using join buffer (Block Nested Loop)
101014	SUBQUERY	subquery1_t3	NULL	ALL	col_varchar_key	NULL	NULL	NULL	20	100.00	Using where
101024	SUBQUERY	subquery1_t2	NULL	eq_ref	PRIMARY	PRIMARY	4	test.subquery1_t3.col_int_key	1	10.00	Using where
101034	SUBQUERY	subquery1_t1	NULL	index	PRIMARY	col_int_key	5	NULL	20	100.00	Using where; Using index; Using join buffer (Block Nested Loop)
10104Warnings:
10105Note	1003	/* select#1 */ select `table2`.`col_varchar_nokey` AS `field1` from `test`.`t2` `table1` join `test`.`t1` `table2` straight_join `test`.`t2` `table3` where ((`table3`.`col_int_key` = `table2`.`pk`) and <in_optimizer>(`table2`.`pk`,`table2`.`pk` in ( <materialize> (/* select#3 */ select `subquery2_t1`.`col_int_key` AS `subquery2_field1` from `test`.`t3` `subquery2_t2` join `test`.`t1` `subquery2_t3` join `test`.`t2` `subquery2_t1` where ((`subquery2_t2`.`col_varchar_key` = `subquery2_t3`.`col_varchar_key`) and (`subquery2_t2`.`pk` = `subquery2_t3`.`pk`)) ), <primary_index_lookup>(`table2`.`pk` in <temporary table> on <auto_key> where ((`table2`.`pk` = `materialized-subquery`.`subquery2_field1`))))) and <in_optimizer>(`table3`.`col_int_nokey`,`table3`.`col_int_nokey` in ( <materialize> (/* select#4 */ select `subquery1_t2`.`col_int_nokey` AS `subquery1_field1` from `test`.`t1` `subquery1_t2` join `test`.`t1` `subquery1_t3` join `test`.`t2` `subquery1_t1` where ((`subquery1_t2`.`pk` = `subquery1_t3`.`col_int_key`) and (`subquery1_t2`.`col_varchar_nokey` = `subquery1_t3`.`col_varchar_key`) and (`subquery1_t1`.`pk` > 1)) ), <primary_index_lookup>(`table3`.`col_int_nokey` in <temporary table> on <auto_key> where ((`table3`.`col_int_nokey` = `materialized-subquery`.`subquery1_field1`))))))
10106SELECT * FROM v1;
10107field1
10108v
10109v
10110v
10111v
10112v
10113v
10114v
10115v
10116v
10117v
10118v
10119v
10120v
10121v
10122v
10123v
10124v
10125v
10126v
10127v
10128DROP VIEW v1;
10129DROP TABLE t1,t2,t3;
10130# End of test for bug#13855925.
10131#
10132# Bug#13897959: Segfault in setup_semijoin_dups_elimination()
10133#
10134CREATE TABLE t1 (
10135col_datetime_key DATETIME DEFAULT NULL,
10136KEY col_datetime_key (col_datetime_key)
10137) ENGINE=MyISAM;
10138INSERT INTO t1 VALUES
10139('2001-04-18 00:00:00'), ('2008-12-18 19:39:55'),
10140('2000-08-01 12:19:39'), ('2004-09-25 21:29:06'),
10141('2009-09-20 09:11:48'), ('2004-03-27 09:32:04');
10142CREATE TABLE t2 (
10143col_date_nokey date DEFAULT NULL,
10144col_time_key time DEFAULT NULL,
10145col_datetime_key datetime DEFAULT NULL,
10146col_varchar_key varchar(1) DEFAULT NULL,
10147col_varchar_nokey varchar(1) DEFAULT NULL,
10148KEY col_time_key (col_time_key),
10149KEY col_datetime_key (col_datetime_key),
10150KEY col_varchar_key(col_varchar_key)
10151) ENGINE=MyISAM;
10152INSERT INTO t2 VALUES ('1900-01-01',NULL,'2001-11-04 19:07:55','x','x');
10153SELECT grandparent1.col_varchar_nokey
10154FROM t2 AS grandparent1 LEFT JOIN t1 USING (col_datetime_key)
10155WHERE grandparent1.col_varchar_nokey IN (
10156SELECT col_varchar_nokey
10157FROM t2 AS parent1
10158WHERE parent1.col_time_key > grandparent1.col_date_nokey
10159);
10160col_varchar_nokey
10161DROP TABLE t1, t2;
10162# End of test for bug#13897959.
10163#
10164# Bug#13898625 ASSERT `(REMAINING_TABLES_AFTER != 0) ...' IN
10165# BEST_EXTENSION_BY_LIMITED_SEARCH
10166#
10167CREATE TABLE t1 (
10168pk int(11) NOT NULL,
10169col_int_nokey INT,
10170col_int_key INT,
10171col_varchar_key VARCHAR(1),
10172col_varchar_nokey VARCHAR(1),
10173PRIMARY KEY (pk),
10174KEY col_int_key (col_int_key),
10175KEY col_varchar_key (col_varchar_key,col_int_key)
10176);
10177INSERT INTO t1 VALUES (26,6,NULL,'f','f');
10178INSERT INTO t1 VALUES (29,6,8,'c','c');
10179CREATE TABLE t2 (
10180pk INT NOT NULL,
10181col_int_nokey INT,
10182col_int_key INT,
10183col_varchar_key VARCHAR(1),
10184col_varchar_nokey VARCHAR(1),
10185PRIMARY KEY (pk),
10186KEY col_int_key (col_int_key),
10187KEY col_varchar_key (col_varchar_key,col_int_key)
10188);
10189INSERT INTO t2 VALUES (1,2,4,'v','v');
10190INSERT INTO t2 VALUES (2,150,62,'v','v');
10191INSERT INTO t2 VALUES (5,5,0,'x','x');
10192INSERT INTO t2 VALUES (6,3,7,'i','i');
10193INSERT INTO t2 VALUES (7,1,7,'e','e');
10194CREATE VIEW view_c AS SELECT * FROM t2;
10195PREPARE prep_stmt_7430 FROM 'SELECT SUM( alias1.col_varchar_key ) AS field1
10196FROM t1 AS alias1
10197RIGHT JOIN t2 AS alias2
10198INNER JOIN t1 AS alias3
10199ON (alias3.col_varchar_key = alias2.col_varchar_key )
10200ON ( "v" ) IN (
10201SELECT sq1_alias1.col_varchar_nokey AS sq1_field1
10202FROM t1 AS sq1_alias1
10203)
10204WHERE alias3.pk IN (
10205SELECT sq2_alias1.col_int_key AS sq2_field1
10206FROM ( view_c AS sq2_alias1, t1 AS sq2_alias2 )
10207)
10208';
10209EXECUTE prep_stmt_7430;
10210field1
10211NULL
10212EXECUTE prep_stmt_7430;
10213field1
10214NULL
10215EXPLAIN SELECT SUM( alias1.col_varchar_key ) AS field1
10216FROM t1 AS alias1
10217RIGHT JOIN t2 AS alias2
10218INNER JOIN t1 AS alias3
10219ON (alias3.col_varchar_key = alias2.col_varchar_key )
10220ON ( "v" ) IN (
10221SELECT sq1_alias1.col_varchar_nokey AS sq1_field1
10222FROM t1 AS sq1_alias1
10223)
10224WHERE alias3.pk IN (
10225SELECT sq2_alias1.col_int_key AS sq2_field1
10226FROM ( view_c AS sq2_alias1, t1 AS sq2_alias2 )
10227)
10228;
10229id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
102301	PRIMARY	alias3	NULL	ALL	col_varchar_key	NULL	NULL	NULL	2	100.00	Using where
102311	PRIMARY	alias2	NULL	ref	col_varchar_key	col_varchar_key	4	test.alias3.col_varchar_key	2	100.00	Using index
102321	PRIMARY	alias1	NULL	index	NULL	col_varchar_key	9	NULL	2	100.00	Using where; Using index; Using join buffer (Block Nested Loop)
102333	SUBQUERY	sq2_alias2	NULL	index	NULL	PRIMARY	4	NULL	2	100.00	Using index
102343	SUBQUERY	t2	NULL	index	col_int_key	col_int_key	5	NULL	5	100.00	Using index; Using join buffer (Block Nested Loop)
102352	SUBQUERY	sq1_alias1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
10236Warnings:
10237Note	1003	/* select#1 */ select sum(`test`.`alias1`.`col_varchar_key`) AS `field1` from `test`.`t2` `alias2` join `test`.`t1` `alias3` left join `test`.`t1` `alias1` on(<in_optimizer>('v','v' in ( <materialize> (/* select#2 */ select `test`.`sq1_alias1`.`col_varchar_nokey` AS `sq1_field1` from `test`.`t1` `sq1_alias1` where (`test`.`sq1_alias1`.`col_varchar_nokey` = <cache>('v')) ), <primary_index_lookup>('v' in <temporary table> on <auto_key> where (('v' = `materialized-subquery`.`sq1_field1`)))))) where ((`test`.`alias2`.`col_varchar_key` = `test`.`alias3`.`col_varchar_key`) and <in_optimizer>(`test`.`alias3`.`pk`,`test`.`alias3`.`pk` in ( <materialize> (/* select#3 */ select `test`.`t2`.`col_int_key` AS `sq2_field1` from `test`.`t2` join `test`.`t1` `sq2_alias2` where 1 ), <primary_index_lookup>(`test`.`alias3`.`pk` in <temporary table> on <auto_key> where ((`test`.`alias3`.`pk` = `materialized-subquery`.`sq2_field1`))))))
10238PREPARE prep_stmt_7430 FROM 'SELECT SUM( alias1.col_varchar_key ) AS field1
10239FROM t1 AS alias1
10240RIGHT JOIN t2 AS alias2
10241INNER JOIN t1 AS alias3
10242ON (alias3.col_varchar_key = alias2.col_varchar_key )
10243ON ( "v" ) IN (
10244SELECT sq1_alias1.col_varchar_nokey AS sq1_field1
10245FROM t1 AS sq1_alias1
10246)
10247WHERE alias3.pk IN (
10248SELECT sq2_alias1.col_int_key AS sq2_field1
10249FROM ( view_c AS sq2_alias1 , t1 AS sq2_alias2 )
10250WHERE sq2_alias1.col_varchar_nokey <> alias2.col_varchar_key
10251AND sq2_alias1.col_varchar_key < "l"
10252  )
10253';
10254EXECUTE prep_stmt_7430;
10255field1
10256NULL
10257EXECUTE prep_stmt_7430;
10258field1
10259NULL
10260EXPLAIN SELECT SUM( alias1.col_varchar_key ) AS field1
10261FROM t1 AS alias1
10262RIGHT JOIN t2 AS alias2
10263INNER JOIN t1 AS alias3
10264ON (alias3.col_varchar_key = alias2.col_varchar_key )
10265ON ( "v" ) IN (
10266SELECT sq1_alias1.col_varchar_nokey AS sq1_field1
10267FROM t1 AS sq1_alias1
10268)
10269WHERE alias3.pk IN (
10270SELECT sq2_alias1.col_int_key AS sq2_field1
10271FROM ( view_c AS sq2_alias1 , t1 AS sq2_alias2 )
10272WHERE sq2_alias1.col_varchar_nokey <> alias2.col_varchar_key
10273AND sq2_alias1.col_varchar_key < "l"
10274  )
10275;
10276id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
102771	PRIMARY	alias3	NULL	ALL	col_varchar_key	NULL	NULL	NULL	2	100.00	Using where
102781	PRIMARY	alias2	NULL	ref	col_varchar_key	col_varchar_key	4	test.alias3.col_varchar_key	2	100.00	Using where; Using index
102791	PRIMARY	alias1	NULL	index	NULL	col_varchar_key	9	NULL	2	100.00	Using where; Using index; Using join buffer (Block Nested Loop)
102803	DEPENDENT SUBQUERY	t2	NULL	ref	col_int_key,col_varchar_key	col_int_key	5	func	2	32.00	Using where
102813	DEPENDENT SUBQUERY	sq2_alias2	NULL	index	NULL	PRIMARY	4	NULL	2	100.00	Using index; Using join buffer (Block Nested Loop)
102822	SUBQUERY	sq1_alias1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
10283Warnings:
10284Note	1276	Field or reference 'test.alias2.col_varchar_key' of SELECT #3 was resolved in SELECT #1
10285Note	1003	/* select#1 */ select sum(`test`.`alias1`.`col_varchar_key`) AS `field1` from `test`.`t2` `alias2` join `test`.`t1` `alias3` left join `test`.`t1` `alias1` on(<in_optimizer>('v','v' in ( <materialize> (/* select#2 */ select `test`.`sq1_alias1`.`col_varchar_nokey` AS `sq1_field1` from `test`.`t1` `sq1_alias1` where (`test`.`sq1_alias1`.`col_varchar_nokey` = <cache>('v')) ), <primary_index_lookup>('v' in <temporary table> on <auto_key> where (('v' = `materialized-subquery`.`sq1_field1`)))))) where ((`test`.`alias2`.`col_varchar_key` = `test`.`alias3`.`col_varchar_key`) and <in_optimizer>(`test`.`alias3`.`pk`,<exists>(/* select#3 */ select 1 from `test`.`t2` join `test`.`t1` `sq2_alias2` where ((`test`.`t2`.`col_varchar_nokey` <> `test`.`alias2`.`col_varchar_key`) and (`test`.`t2`.`col_varchar_key` < 'l') and (<cache>(`test`.`alias3`.`pk`) = `test`.`t2`.`col_int_key`)))))
10286DROP TABLE t1,t2;
10287DROP VIEW view_c;
10288#
10289# Bug#13902463 SEGFAULT IN BITMAP<64U>::MERGE OR ADD_KEY_FIELD
10290# ON SECOND EXEC OF PREP STMT
10291#
10292CREATE TABLE t1 (
10293pk INT,
10294col_int_nokey INT,
10295col_int_key INT,
10296col_varchar_key VARCHAR(1),
10297col_varchar_nokey VARCHAR(1),
10298KEY col_varchar_key (col_varchar_key)
10299);
10300CREATE VIEW view_b AS SELECT * FROM t1;
10301PREPARE prep_stmt_20421 FROM 'SELECT alias2.col_varchar_nokey AS field1
10302FROM t1 AS alias1
10303INNER JOIN t1 AS alias2
10304ON (alias1.col_varchar_key = alias2.col_varchar_nokey
10305AND ( alias1.col_int_key ) IN (
10306SELECT t1.col_int_nokey
10307FROM t1
10308)
10309)
10310WHERE alias1.col_varchar_key IN (
10311SELECT sq2_alias2.col_varchar_nokey AS sq2_field1
10312FROM view_b AS sq2_alias1
10313INNER JOIN t1 AS sq2_alias2
10314ON (sq2_alias2.col_varchar_key = sq2_alias1.col_varchar_key )
10315WHERE sq2_alias1.pk > alias2.pk
10316)
10317';
10318EXECUTE prep_stmt_20421;
10319field1
10320EXECUTE prep_stmt_20421;
10321field1
10322EXPLAIN SELECT alias2.col_varchar_nokey AS field1
10323FROM t1 AS alias1
10324INNER JOIN t1 AS alias2
10325ON (alias1.col_varchar_key = alias2.col_varchar_nokey
10326AND ( alias1.col_int_key ) IN (
10327SELECT t1.col_int_nokey
10328FROM t1
10329)
10330)
10331WHERE alias1.col_varchar_key IN (
10332SELECT sq2_alias2.col_varchar_nokey AS sq2_field1
10333FROM view_b AS sq2_alias1
10334INNER JOIN t1 AS sq2_alias2
10335ON (sq2_alias2.col_varchar_key = sq2_alias1.col_varchar_key )
10336WHERE sq2_alias1.pk > alias2.pk
10337)
10338;
10339id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
103401	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
103413	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
103422	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
10343Warnings:
10344Note	1276	Field or reference 'test.alias2.pk' of SELECT #3 was resolved in SELECT #1
10345Note	1003	/* select#1 */ select NULL AS `field1` from `test`.`t1` `alias1` join `test`.`t1` `alias2` where (<in_optimizer>(NULL,<exists>(/* select#3 */ select 1 from `test`.`t1` join `test`.`t1` `sq2_alias2` where ((NULL > NULL) and (<cache>(NULL) = NULL) and multiple equal(NULL, NULL)))) and <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t1` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`col_int_nokey`))))) and multiple equal(NULL, NULL))
10346ALTER TABLE t1 DROP INDEX col_varchar_key;
10347PREPARE prep_stmt_20421 FROM 'SELECT alias2.col_varchar_nokey AS field1
10348FROM t1 AS alias1
10349INNER JOIN t1 AS alias2
10350ON (alias1.col_varchar_key = alias2.col_varchar_nokey
10351AND ( alias1.col_int_key ) IN (
10352SELECT t1.col_int_nokey
10353FROM t1
10354)
10355)
10356WHERE alias1.col_varchar_key IN (
10357SELECT sq2_alias2.col_varchar_nokey AS sq2_field1
10358FROM view_b AS sq2_alias1
10359INNER JOIN t1 AS sq2_alias2
10360ON (sq2_alias2.col_varchar_key = sq2_alias1.col_varchar_key )
10361WHERE sq2_alias1.pk > alias2.pk
10362)
10363';
10364EXECUTE prep_stmt_20421;
10365field1
10366EXECUTE prep_stmt_20421;
10367field1
10368EXPLAIN SELECT alias2.col_varchar_nokey AS field1
10369FROM t1 AS alias1
10370INNER JOIN t1 AS alias2
10371ON (alias1.col_varchar_key = alias2.col_varchar_nokey
10372AND ( alias1.col_int_key ) IN (
10373SELECT t1.col_int_nokey
10374FROM t1
10375)
10376)
10377WHERE alias1.col_varchar_key IN (
10378SELECT sq2_alias2.col_varchar_nokey AS sq2_field1
10379FROM view_b AS sq2_alias1
10380INNER JOIN t1 AS sq2_alias2
10381ON (sq2_alias2.col_varchar_key = sq2_alias1.col_varchar_key )
10382WHERE sq2_alias1.pk > alias2.pk
10383)
10384;
10385id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
103861	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
103873	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
103882	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
10389Warnings:
10390Note	1276	Field or reference 'test.alias2.pk' of SELECT #3 was resolved in SELECT #1
10391Note	1003	/* select#1 */ select NULL AS `field1` from `test`.`t1` `alias1` join `test`.`t1` `alias2` where (<in_optimizer>(NULL,<exists>(/* select#3 */ select 1 from `test`.`t1` join `test`.`t1` `sq2_alias2` where ((NULL > NULL) and (<cache>(NULL) = NULL) and multiple equal(NULL, NULL)))) and <in_optimizer>(NULL,NULL in ( <materialize> (/* select#2 */ select NULL from `test`.`t1` where 1 ), <primary_index_lookup>(NULL in <temporary table> on <auto_key> where ((NULL = `materialized-subquery`.`col_int_nokey`))))) and multiple equal(NULL, NULL))
10392DROP TABLE t1;
10393DROP VIEW view_b;
10394#
10395# Bug#13907277: Segfault in evaluate_null_complemented_join_record
10396#
10397CREATE TABLE t1 (
10398pk INTEGER,
10399col_varchar_nokey VARCHAR(1),
10400col_varchar_key VARCHAR(1),
10401PRIMARY KEY (pk)
10402);
10403INSERT INTO t1 VALUES (1, 'x', 'x');
10404CREATE TABLE t2 (
10405pk INTEGER,
10406PRIMARY KEY (pk)
10407);
10408INSERT INTO t2 VALUES (1);
10409CREATE TABLE t3 (
10410pk INTEGER,
10411col_int_nokey INTEGER,
10412col_int_key INTEGER,
10413col_varchar_nokey VARCHAR(1),
10414PRIMARY KEY (pk)
10415);
10416INSERT INTO t3 VALUES (1, 6, 5, 'r');
10417explain SELECT outer_t1.pk, outer_t2.pk
10418FROM t3 AS outer_t1
10419RIGHT JOIN t2 AS outer_t2
10420ON outer_t1.col_int_nokey IN
10421(SELECT inner_t1.col_int_nokey
10422FROM t3 AS inner_t1
10423LEFT JOIN t1 AS inner_t2
10424INNER JOIN t1 AS inner_t3
10425ON inner_t3.pk = inner_t2.pk
10426ON inner_t3.col_varchar_nokey = inner_t2.col_varchar_key
10427);
10428id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
104291	PRIMARY	outer_t2	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
104301	PRIMARY	outer_t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
104312	DEPENDENT SUBQUERY	inner_t1	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
104322	DEPENDENT SUBQUERY	inner_t2	NULL	ALL	PRIMARY	NULL	NULL	NULL	1	100.00	Using where
104332	DEPENDENT SUBQUERY	inner_t3	NULL	eq_ref	PRIMARY	PRIMARY	4	test.inner_t2.pk	1	100.00	Using where
10434Warnings:
10435Note	1003	/* select#1 */ select '1' AS `pk`,'1' AS `pk` from `test`.`t3` `outer_t1` where 1
10436SELECT outer_t1.pk, outer_t2.pk
10437FROM t3 AS outer_t1
10438RIGHT JOIN t2 AS outer_t2
10439ON outer_t1.col_int_nokey IN
10440(SELECT inner_t1.col_int_nokey
10441FROM t3 AS inner_t1
10442LEFT JOIN t1 AS inner_t2
10443INNER JOIN t1 AS inner_t3
10444ON inner_t3.pk = inner_t2.pk
10445ON inner_t3.col_varchar_nokey = inner_t2.col_varchar_key
10446);
10447pk	pk
104481	1
10449DROP TABLE t1, t2, t3;
10450# End of test for bug#13907277.
10451#
10452# Bug#13955713: Assert 'JOIN->best_read < ...' on second execution
10453#
10454CREATE TABLE t1 (
10455pk INTEGER,
10456col_varchar_key VARCHAR(1),
10457col_varchar_nokey VARCHAR(1)
10458);
10459PREPARE stmt FROM "
10460SELECT MIN(alias2.col_varchar_key) AS field1
10461FROM t1 AS alias1
10462     INNER JOIN (t1 AS alias2
10463       INNER JOIN t1 AS alias3
10464       ON 8 IN
10465         (SELECT sq1_alias1.pk AS sq1_field2
10466          FROM t1 AS sq1_alias1
10467          WHERE 9 IN
10468             (SELECT SUM(t1_sq1_alias1.pk) AS t1_sq1_field2
10469              FROM t1 AS t1_sq1_alias1
10470             )
10471         )
10472     )
10473     ON alias3.col_varchar_nokey = alias2.col_varchar_key
10474WHERE EXISTS
10475   (SELECT sq2_alias1.pk AS sq2_field1
10476    FROM t1 AS sq2_alias1
10477    WHERE sq2_alias1.col_varchar_key < alias1.col_varchar_nokey
10478   )
10479";
10480EXECUTE stmt;
10481field1
10482NULL
10483EXECUTE stmt;
10484field1
10485NULL
10486DEALLOCATE PREPARE stmt;
10487DROP TABLE t1;
10488# End of test for bug#13955713.
10489#
10490# Bug#13956813: Segfault in memcpy from Join_cache::write_record_data()
10491#
10492CREATE TABLE t1 (
10493pk INT,
10494col_varchar_key VARCHAR(1),
10495col_varchar_nokey VARCHAR(1)
10496);
10497CREATE TABLE t2 (
10498pk INT,
10499col_varchar_key VARCHAR(1),
10500col_varchar_nokey VARCHAR(1)
10501);
10502INSERT INTO t2 VALUES
10503(10,'j','j'), (11,'z','z'), (12,'c','c'), (13,'a','a'),
10504(14,'q','q'), (15,'y','y'), (16,NULL,NULL), (17,'r','r'),
10505(18,'v','v'), (19,NULL,NULL), (20,'r','r');
10506CREATE TABLE t3 (
10507pk INT,
10508col_int_key INT,
10509col_varchar_key VARCHAR(1),
10510KEY col_int_key (col_int_key)
10511);
10512INSERT INTO t3 VALUES
10513(15,NULL,'u'), (16,1,'m'), (17,9,NULL), (18,2,'o'),
10514(19,9,'w'), (20,2,'m'), (21,4,'q'), (22,0,NULL),
10515(23,4,'d'), (24,8,'g'), (25,NULL,'x'), (26,NULL,'f'),
10516(27,0,'p'), (28,NULL,'j'), (29,8,'c');
10517CREATE VIEW view_inline_0 AS
10518SELECT t1.*
10519FROM t1 INNER JOIN t3
10520ON t1.pk = t3.pk;
10521CREATE VIEW view_inline_1 AS
10522SELECT sq2_alias2.col_varchar_key AS sq2_field1,
10523sq2_alias1.col_varchar_key AS sq2_field2
10524FROM t3 AS sq2_alias1 LEFT OUTER JOIN t3 AS sq2_alias2
10525ON sq2_alias1.pk = sq2_alias2.col_int_key;
10526CREATE VIEW view_inline_2 AS
10527SELECT 'p', 'p' UNION SELECT 'k', 's';
10528SET @optimizer_switch_saved= @@optimizer_switch;
10529SET @@optimizer_switch="derived_merge=off";
10530explain SELECT SUM(alias1.col_varchar_nokey) AS field2
10531FROM t2 AS alias2
10532LEFT JOIN (SELECT * FROM view_inline_0) AS alias1
10533ON alias2.col_varchar_key = alias1.col_varchar_key AND
10534(alias2.col_varchar_nokey, alias2.col_varchar_key) IN
10535(SELECT * FROM view_inline_1
10536)
10537WHERE (alias1.col_varchar_key, alias1.col_varchar_nokey) IN
10538(SELECT * FROM view_inline_2
10539);
10540id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
105411	PRIMARY	alias2	NULL	ALL	NULL	NULL	NULL	NULL	11	100.00	Using where
105421	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	4	test.alias2.col_varchar_key	2	100.00	Using where
105434	SUBQUERY	<derived7>	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
105447	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
105458	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
10546NULL	UNION RESULT	<union7,8>	NULL	ALL	NULL	NULL	NULL	NULL	NULL	NULL	Using temporary
105473	SUBQUERY	<derived6>	NULL	ALL	NULL	NULL	NULL	NULL	30	100.00	NULL
105486	DERIVED	sq2_alias1	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	NULL
105496	DERIVED	sq2_alias2	NULL	ref	col_int_key	col_int_key	5	test.sq2_alias1.pk	2	100.00	NULL
105502	DERIVED	<derived5>	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	NULL
105515	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
10552Warnings:
10553Note	1003	/* select#1 */ select sum(`alias1`.`col_varchar_nokey`) AS `field2` from `test`.`t2` `alias2` join (/* select#2 */ select `view_inline_0`.`pk` AS `pk`,`view_inline_0`.`col_varchar_key` AS `col_varchar_key`,`view_inline_0`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`view_inline_0`) `alias1` where ((`alias1`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`) and <in_optimizer>((`alias1`.`col_varchar_key`,`alias1`.`col_varchar_nokey`),(`alias1`.`col_varchar_key`,`alias1`.`col_varchar_nokey`) in ( <materialize> (/* select#4 */ select `view_inline_2`.`p`,`view_inline_2`.`My_exp_p` from `test`.`view_inline_2` where 1 ), <primary_index_lookup>(`alias1`.`col_varchar_key` in <temporary table> on <auto_key> where ((`alias1`.`col_varchar_key` = `materialized-subquery`.`p`) and (`alias1`.`col_varchar_nokey` = `materialized-subquery`.`My_exp_p`))))) and <in_optimizer>((`test`.`alias2`.`col_varchar_nokey`,`test`.`alias2`.`col_varchar_key`),(`test`.`alias2`.`col_varchar_nokey`,`test`.`alias2`.`col_varchar_key`) in ( <materialize> (/* select#3 */ select `view_inline_1`.`sq2_field1`,`view_inline_1`.`sq2_field2` from `test`.`view_inline_1` where 1 ), <primary_index_lookup>(`test`.`alias2`.`col_varchar_nokey` in <temporary table> on <auto_key> where ((`test`.`alias2`.`col_varchar_nokey` = `materialized-subquery`.`sq2_field1`) and (`test`.`alias2`.`col_varchar_key` = `materialized-subquery`.`sq2_field2`))))))
10554SELECT SUM(alias1.col_varchar_nokey) AS field2
10555FROM t2 AS alias2
10556LEFT JOIN (SELECT * FROM view_inline_0) AS alias1
10557ON alias2.col_varchar_key = alias1.col_varchar_key AND
10558(alias2.col_varchar_nokey, alias2.col_varchar_key) IN
10559(SELECT * FROM view_inline_1
10560)
10561WHERE (alias1.col_varchar_key, alias1.col_varchar_nokey) IN
10562(SELECT * FROM view_inline_2
10563);
10564field2
10565NULL
10566SET @@optimizer_switch= @optimizer_switch_saved;
10567DROP VIEW view_inline_0, view_inline_1, view_inline_2;
10568DROP TABLE t1, t2, t3;
10569# End of test for bug#13956813.
10570#
10571# Bug#13974177: Assert !(tab->table->regginfo.not_exists_optimize...
10572#
10573CREATE TABLE t1 (
10574pk INTEGER AUTO_INCREMENT,
10575col_int_nokey INTEGER,
10576col_int_key INTEGER,
10577col_varchar_key VARCHAR(1),
10578col_varchar_nokey VARCHAR(1),
10579PRIMARY KEY (pk),
10580KEY (col_int_key),
10581KEY (col_varchar_key, col_int_key)
10582);
10583INSERT INTO t1(col_int_key, col_int_nokey, col_varchar_key, col_varchar_nokey)
10584VALUES
10585(0, 4, 'j', 'j'), (8, 6, 'v', 'v'), (1, 3, 'c', 'c'), (8, 5, 'm', 'm'),
10586(9, 3, 'd', 'd'), (24, 246, 'd', 'd'), (6, 2, 'y', 'y'), (1, 9, 't', 't'),
10587(6, 3, 'd', 'd'), (2, 8, 's', 's'), (4, 1, 'r', 'r'), (8, 8, 'm', 'm'),
10588(4, 8, 'b', 'b'), (4, 5, 'x', 'x'), (7, 7, 'g', 'g'), (4, 5, 'p', 'p'),
10589(1, 1, 'q', 'q'), (9, 6, 'w', 'w'), (4, 2, 'd', 'd'), (8, 9, 'e', 'e');
10590CREATE TABLE t2 (
10591pk INTEGER AUTO_INCREMENT,
10592col_int_nokey INTEGER NOT NULL,
10593col_time_key TIME NOT NULL,
10594col_time_nokey TIME NOT NULL,
10595PRIMARY KEY (pk),
10596KEY (col_time_key)
10597) ENGINE=InnoDB;
10598INSERT INTO t2 (col_int_nokey, col_time_key, col_time_nokey) VALUES
10599(7, '00:00:00', '00:00:00'), (0, '00:00:00', '00:00:00'),
10600(9, '06:35:17', '06:35:17'), (3, '18:07:14', '18:07:14'),
10601(4, '20:36:52', '20:36:52'), (2, '21:29:07', '21:29:07'),
10602(5, '23:45:57', '23:45:57'), (3, '22:54:57', '22:54:57'),
10603(1, '18:45:09', '18:45:09'), (3, '14:30:46', '14:30:46'),
10604(6, '19:23:43', '19:23:43'), (7, '03:39:30', '03:39:30'),
10605(5, '23:37:52', '23:37:52'), (1, '16:59:30', '16:59:30'),
10606(204, '22:21:15', '22:21:15'), (224, '12:24:37', '12:24:37'),
10607(9, '15:02:08', '15:02:08'), (5, '23:59:59', '23:59:59'),
10608(0, '08:23:30', '08:23:30'), (3, '08:32:22', '08:32:22');
10609explain SELECT ot1.col_int_key AS x
10610FROM t1 AS ot2
10611LEFT JOIN t1 AS ot1
10612ON ot2.col_varchar_nokey > ot1.col_varchar_key
10613WHERE (ot1.col_int_nokey, ot1.pk) IN
10614(SELECT it1.pk AS x,
10615it1.col_int_nokey AS y
10616FROM t2 AS it2
10617LEFT JOIN t2 AS it1
10618ON it2.col_time_nokey = it1.col_time_key
10619) AND ot1.pk IS NULL
10620;
10621id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
106221	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
106232	SUBQUERY	it2	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	NULL
106242	SUBQUERY	it1	NULL	ref	PRIMARY,col_time_key	col_time_key	3	test.it2.col_time_nokey	1	100.00	NULL
10625Warnings:
10626Note	1003	/* select#1 */ select `test`.`ot1`.`col_int_key` AS `x` from `test`.`t1` `ot2` join `test`.`t1` `ot1` where (<in_optimizer>((`test`.`ot1`.`col_int_nokey`,`test`.`ot1`.`pk`),(`test`.`ot1`.`col_int_nokey`,`test`.`ot1`.`pk`) in ( <materialize> (/* select#2 */ select `test`.`it1`.`pk` AS `x`,`test`.`it1`.`col_int_nokey` AS `y` from `test`.`t2` `it2` join `test`.`t2` `it1` where (`test`.`it1`.`col_time_key` = `test`.`it2`.`col_time_nokey`) ), <primary_index_lookup>(`test`.`ot1`.`col_int_nokey` in <temporary table> on <auto_key> where ((`test`.`ot1`.`col_int_nokey` = `materialized-subquery`.`x`) and (`test`.`ot1`.`pk` = `materialized-subquery`.`y`))))) and isnull(`test`.`ot1`.`pk`) and (`test`.`ot2`.`col_varchar_nokey` > `test`.`ot1`.`col_varchar_key`))
10627SELECT ot1.col_int_key AS x
10628FROM t1 AS ot2
10629LEFT JOIN t1 AS ot1
10630ON ot2.col_varchar_nokey > ot1.col_varchar_key
10631WHERE (ot1.col_int_nokey, ot1.pk) IN
10632(SELECT it1.pk AS x,
10633it1.col_int_nokey AS y
10634FROM t2 AS it2
10635LEFT JOIN t2 AS it1
10636ON it2.col_time_nokey = it1.col_time_key
10637) AND ot1.pk IS NULL
10638;
10639x
10640DROP TABLE t1, t2;
10641# End of test for bug#13974177.
10642#
10643# Bug#13971022: Assert 'keyparts > 0' failed in create_ref_for_key...
10644#
10645CREATE TABLE t1 (
10646pk INT,
10647col_int_key INT,
10648col_varchar_key VARCHAR(1),
10649PRIMARY KEY (pk),
10650KEY col_varchar_key (col_varchar_key,col_int_key)
10651);
10652CREATE TABLE t2 (
10653pk INT,
10654col_int_key INT,
10655col_varchar_key VARCHAR(1),
10656col_varchar_nokey VARCHAR(1),
10657PRIMARY KEY (pk)
10658) ENGINE=InnoDB;
10659CREATE TABLE t3 (
10660i INT
10661);
10662SET @optimizer_switch_saved= @@optimizer_switch;
10663SET @@optimizer_switch="derived_merge=off";
10664explain SELECT table1.pk AS field1
10665FROM ( SELECT subquery1_t1. *
10666FROM t2 AS subquery1_t1
10667JOIN t2 AS subquery1_t2
10668ON subquery1_t2.pk = subquery1_t1.pk) AS table1
10669STRAIGHT_JOIN t2 AS table2
10670ON table1.col_int_key IN (SELECT 7 FROM t3)
10671WHERE table1.col_varchar_nokey IN
10672(SELECT subquery3_t1.col_varchar_key AS subquery3_field1
10673FROM t1 AS subquery3_t1
10674)
10675;
10676id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
106771	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
106781	PRIMARY	table2	NULL	index	NULL	PRIMARY	4	NULL	1	100.00	Using index; Using join buffer (Block Nested Loop)
106794	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
106803	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
106812	DERIVED	subquery1_t1	NULL	ALL	PRIMARY	NULL	NULL	NULL	1	100.00	NULL
106822	DERIVED	subquery1_t2	NULL	eq_ref	PRIMARY	PRIMARY	4	test.subquery1_t1.pk	1	100.00	Using index
10683Warnings:
10684Note	1003	/* select#1 */ select `table1`.`pk` AS `field1` from (/* select#2 */ select `test`.`subquery1_t1`.`pk` AS `pk`,`test`.`subquery1_t1`.`col_int_key` AS `col_int_key`,`test`.`subquery1_t1`.`col_varchar_key` AS `col_varchar_key`,`test`.`subquery1_t1`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`t2` `subquery1_t1` join `test`.`t2` `subquery1_t2` where (`test`.`subquery1_t2`.`pk` = `test`.`subquery1_t1`.`pk`)) `table1` straight_join `test`.`t2` `table2` where (<in_optimizer>(`table1`.`col_varchar_nokey`,`table1`.`col_varchar_nokey` in ( <materialize> (/* select#4 */ select NULL AS `subquery3_field1` from `test`.`t1` `subquery3_t1` where 1 ), <primary_index_lookup>(`table1`.`col_varchar_nokey` in <temporary table> on <auto_key> where ((`table1`.`col_varchar_nokey` = `materialized-subquery`.`subquery3_field1`))))) and <in_optimizer>(`table1`.`col_int_key`,`table1`.`col_int_key` in ( <materialize> (/* select#3 */ select 7 from `test`.`t3` where 1 ), <primary_index_lookup>(`table1`.`col_int_key` in <temporary table> on <auto_key> where ((`table1`.`col_int_key` = `materialized-subquery`.`7`))))))
10685SELECT table1.pk AS field1
10686FROM ( SELECT subquery1_t1. *
10687FROM t2 AS subquery1_t1
10688JOIN t2 AS subquery1_t2
10689ON subquery1_t2.pk = subquery1_t1.pk) AS table1
10690STRAIGHT_JOIN t2 AS table2
10691ON table1.col_int_key IN (SELECT 7 FROM t3)
10692WHERE table1.col_varchar_nokey IN
10693(SELECT subquery3_t1.col_varchar_key AS subquery3_field1
10694FROM t1 AS subquery3_t1
10695)
10696;
10697field1
10698SET @@optimizer_switch= @optimizer_switch_saved;
10699DROP TABLE t1, t2, t3;
10700# End of test for bug#13971022.
10701#
10702# Bug#13623473 "MISSING ROWS ON SELECT AND JOIN WITH
10703# TIME/DATETIME COMPARE" - Subquery part of test.
10704#
10705SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-31 10:14:35');
10706CREATE TABLE t1 (
10707pk INT NOT NULL,
10708col_int_nokey INT,
10709col_int_key INT NOT NULL,
10710PRIMARY KEY (pk),
10711KEY col_int_key (col_int_key)
10712) ENGINE=InnoDB;
10713INSERT INTO t1 VALUES (10,1,7), (11,7,0), (12,4,9), (13,7,3),
10714(14,0,4), (15,2,2), (16,9,5), (17,4,3), (18,0,1), (19,9,3), (20,1,6),
10715(21,3,7), (22,8,5), (23,8,1), (24,18,204), (25,84,224), (26,6,9),
10716(27,3,5), (28,6,0), (29,6,3);
10717CREATE TABLE t2 (
10718col_int_nokey INT NOT NULL,
10719col_datetime_key DATETIME NOT NULL,
10720col_varchar_key VARCHAR(1) NOT NULL,
10721KEY col_datetime_key (col_datetime_key),
10722KEY col_varchar_key (col_varchar_key)
10723) ENGINE=InnoDB;
10724INSERT INTO t2 VALUES (1,'2001-11-04 19:07:55','k');
10725CREATE TABLE t3 (
10726col_time_key TIME,
10727KEY col_time_key (col_time_key)
10728) ENGINE=InnoDB;
10729INSERT INTO t3 VALUES ('21:22:34'), ('10:50:38'), ('00:21:38'),
10730('04:08:02'), ('16:25:11'), ('10:14:58'), ('19:47:59'), ('11:14:24'),
10731('00:00:00'), ('00:00:00'), ('15:57:25'), ('07:05:51'), ('19:22:21'),
10732('03:53:16'), ('09:16:38'), ('15:37:26'), ('00:00:00'), ('05:03:03'),
10733('02:59:24'), ('00:01:58');
10734EXPLAIN EXTENDED SELECT outr.col_int_nokey
10735FROM t2 as outr
10736STRAIGHT_JOIN t3 AS outr2
10737ON outr2.col_time_key > outr.col_datetime_key
10738WHERE outr.col_int_nokey IN (
10739SELECT col_int_key
10740FROM t1 AS innr
10741WHERE innr.pk >= innr.col_int_nokey
10742) AND (
10743outr.col_int_nokey <= 6
10744OR
10745outr.col_varchar_key IS NULL
10746);
10747id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
107481	PRIMARY	outr	NULL	ALL	col_datetime_key	NULL	NULL	NULL	1	100.00	Using where
107491	PRIMARY	outr2	NULL	index	col_time_key	col_time_key	4	NULL	20	33.33	Using where; Using index; Using join buffer (Block Nested Loop)
107502	SUBQUERY	innr	NULL	ALL	col_int_key	NULL	NULL	NULL	20	33.33	Using where
10751Warnings:
10752Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
10753Warning	1739	Cannot use range access on index 'col_time_key' due to type or collation conversion on field 'col_time_key'
10754Note	1003	/* select#1 */ select `test`.`outr`.`col_int_nokey` AS `col_int_nokey` from `test`.`t2` `outr` straight_join `test`.`t3` `outr2` where (<in_optimizer>(`test`.`outr`.`col_int_nokey`,`test`.`outr`.`col_int_nokey` in ( <materialize> (/* select#2 */ select `test`.`innr`.`col_int_key` from `test`.`t1` `innr` where (`test`.`innr`.`pk` >= `test`.`innr`.`col_int_nokey`) ), <primary_index_lookup>(`test`.`outr`.`col_int_nokey` in <temporary table> on <auto_key> where ((`test`.`outr`.`col_int_nokey` = `materialized-subquery`.`col_int_key`))))) and (`test`.`outr`.`col_int_nokey` <= 6) and (`test`.`outr2`.`col_time_key` > `test`.`outr`.`col_datetime_key`))
10755SELECT outr.col_int_nokey
10756FROM t2 as outr
10757STRAIGHT_JOIN t3 AS outr2
10758ON outr2.col_time_key > outr.col_datetime_key
10759WHERE outr.col_int_nokey IN (
10760SELECT col_int_key
10761FROM t1 AS innr
10762WHERE innr.pk >= innr.col_int_nokey
10763) AND (
10764outr.col_int_nokey <= 6
10765OR
10766outr.col_varchar_key IS NULL
10767);
10768col_int_nokey
107691
107701
107711
107721
107731
107741
107751
107761
107771
107781
107791
107801
107811
107821
107831
107841
107851
107861
107871
107881
10789DROP TABLE t1,t2,t3;
10790SET TIMESTAMP = DEFAULT;
10791# End of test for bug#13623473.
10792#
10793# Bug#13980954: Missing data on left join + null value + where..in
10794#
10795CREATE TABLE t1 (
10796ik INT,
10797vc varchar(1)
10798);
10799INSERT INTO t1 VALUES (8, 'x'), (NULL, 'x');
10800CREATE TABLE t2 (
10801ik INT,
10802vc varchar(1)
10803);
10804INSERT INTO t2 VALUES
10805(0, 'x'), (7, 'i'), (7, 'e'), (1, 'p'), (7, 's'), (1, 'j');
10806explain format=json SELECT t2.vc, t2.ik AS t2_ik, t1.ik AS t1_ik
10807FROM t2 LEFT JOIN t1 ON t2.vc=t1.vc
10808WHERE t2.vc IN (SELECT vc FROM t2 AS t3);
10809EXPLAIN
10810{
10811  "query_block": {
10812    "select_id": 1,
10813    "cost_info": {
10814      "query_cost": "7.64"
10815    },
10816    "nested_loop": [
10817      {
10818        "table": {
10819          "table_name": "t2",
10820          "access_type": "ALL",
10821          "rows_examined_per_scan": 6,
10822          "rows_produced_per_join": 6,
10823          "filtered": "100.00",
10824          "cost_info": {
10825            "read_cost": "2.03",
10826            "eval_cost": "1.20",
10827            "prefix_cost": "3.23",
10828            "data_read_per_join": "48"
10829          },
10830          "used_columns": [
10831            "ik",
10832            "vc"
10833          ],
10834          "attached_condition": "<in_optimizer>(`test`.`t2`.`vc`,`test`.`t2`.`vc` in ( <materialize> (/* select#2 */ select `test`.`t3`.`vc` from `test`.`t2` `t3` where 1 ), <primary_index_lookup>(`test`.`t2`.`vc` in <temporary table> on <auto_key> where ((`test`.`t2`.`vc` = `materialized-subquery`.`vc`)))))",
10835          "attached_subqueries": [
10836            {
10837              "table": {
10838                "table_name": "<materialized_subquery>",
10839                "access_type": "eq_ref",
10840                "key": "<auto_key>",
10841                "key_length": "4",
10842                "rows_examined_per_scan": 1,
10843                "materialized_from_subquery": {
10844                  "using_temporary_table": true,
10845                  "dependent": true,
10846                  "cacheable": false,
10847                  "query_block": {
10848                    "select_id": 2,
10849                    "cost_info": {
10850                      "query_cost": "3.23"
10851                    },
10852                    "table": {
10853                      "table_name": "t3",
10854                      "access_type": "ALL",
10855                      "rows_examined_per_scan": 6,
10856                      "rows_produced_per_join": 6,
10857                      "filtered": "100.00",
10858                      "cost_info": {
10859                        "read_cost": "2.03",
10860                        "eval_cost": "1.20",
10861                        "prefix_cost": "3.23",
10862                        "data_read_per_join": "48"
10863                      },
10864                      "used_columns": [
10865                        "vc"
10866                      ]
10867                    }
10868                  }
10869                }
10870              }
10871            }
10872          ]
10873        }
10874      },
10875      {
10876        "table": {
10877          "table_name": "t1",
10878          "access_type": "ALL",
10879          "rows_examined_per_scan": 2,
10880          "rows_produced_per_join": 12,
10881          "filtered": "100.00",
10882          "using_join_buffer": "Block Nested Loop",
10883          "cost_info": {
10884            "read_cost": "2.01",
10885            "eval_cost": "2.40",
10886            "prefix_cost": "7.64",
10887            "data_read_per_join": "96"
10888          },
10889          "used_columns": [
10890            "ik",
10891            "vc"
10892          ],
10893          "attached_condition": "<if>(is_not_null_compl(t1), (`test`.`t1`.`vc` = `test`.`t2`.`vc`), true)"
10894        }
10895      }
10896    ]
10897  }
10898}
10899Warnings:
10900Note	1003	/* select#1 */ select `test`.`t2`.`vc` AS `vc`,`test`.`t2`.`ik` AS `t2_ik`,`test`.`t1`.`ik` AS `t1_ik` from `test`.`t2` left join `test`.`t1` on((`test`.`t1`.`vc` = `test`.`t2`.`vc`)) where <in_optimizer>(`test`.`t2`.`vc`,`test`.`t2`.`vc` in ( <materialize> (/* select#2 */ select `test`.`t3`.`vc` from `test`.`t2` `t3` where 1 ), <primary_index_lookup>(`test`.`t2`.`vc` in <temporary table> on <auto_key> where ((`test`.`t2`.`vc` = `materialized-subquery`.`vc`)))))
10901SELECT t2.vc, t2.ik AS t2_ik, t1.ik AS t1_ik
10902FROM t2 LEFT JOIN t1 ON t2.vc=t1.vc
10903WHERE t2.vc IN (SELECT vc FROM t2 AS t3);
10904vc	t2_ik	t1_ik
10905x	0	8
10906x	0	NULL
10907i	7	NULL
10908e	7	NULL
10909p	1	NULL
10910s	7	NULL
10911j	1	NULL
10912DROP TABLE t1, t2;
10913# End of test for bug#13980954.
10914#
10915# Bug#14048292: Segfault in Item_field::result_type on 2nd execution
10916#               of prep stmt with join of view
10917#
10918CREATE TABLE t1 (
10919col_int INT
10920);
10921INSERT INTO t1 VALUES (0), (1);
10922CREATE VIEW view_t1 AS SELECT * FROM t1;
10923explain SELECT alias1.col_int
10924FROM t1 AS alias1
10925LEFT JOIN view_t1 AS alias2
10926ON alias1.col_int IN
10927(SELECT sq1_alias1.col_int
10928FROM t1 AS sq1_alias1
10929);
10930id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
109311	PRIMARY	alias1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
109321	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
109332	SUBQUERY	sq1_alias1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
10934Warnings:
10935Note	1003	/* select#1 */ select `test`.`alias1`.`col_int` AS `col_int` from `test`.`t1` `alias1` left join (`test`.`t1`) on(<in_optimizer>(`test`.`alias1`.`col_int`,`test`.`alias1`.`col_int` in ( <materialize> (/* select#2 */ select `test`.`sq1_alias1`.`col_int` from `test`.`t1` `sq1_alias1` where 1 ), <primary_index_lookup>(`test`.`alias1`.`col_int` in <temporary table> on <auto_key> where ((`test`.`alias1`.`col_int` = `materialized-subquery`.`col_int`)))))) where 1
10936PREPARE stmt FROM "SELECT alias1.col_int
10937FROM t1 AS alias1
10938LEFT JOIN view_t1 AS alias2
10939ON alias1.col_int IN
10940(SELECT sq1_alias1.col_int
10941FROM t1 AS sq1_alias1
10942)";
10943EXECUTE stmt;
10944col_int
109450
109461
109470
109481
10949EXECUTE stmt;
10950col_int
109510
109521
109530
109541
10955DEALLOCATE PREPARE stmt;
10956DROP VIEW view_t1;
10957DROP TABLE t1;
10958# End of test for bug#14048292.
10959#
10960# Bug#14064201: Missing data on join of derived table + WHERE .. IN
10961#               with two operands
10962#
10963CREATE TABLE t1 (
10964col_varchar_nokey VARCHAR(1)
10965);
10966INSERT INTO t1 VALUES
10967('v'), ('s'), ('l'), ('y'), ('c'), ('i'), ('h'), ('q'), ('a'), ('v'),
10968('u'), ('s'), ('y'), ('z'), ('h'), ('p'), ('e'), ('i'), ('y'), ('w');
10969CREATE TABLE t2 (
10970col_varchar_key VARCHAR(1),
10971col_varchar_nokey VARCHAR(1),
10972KEY col_varchar_key(col_varchar_key)
10973);
10974INSERT INTO t2 VALUES
10975('j','j'), ('v','v'), ('c','c'), ('m','m'), ('d','d'), ('d','d'), ('y','y');
10976SET @optimizer_switch_saved= @@optimizer_switch;
10977SET @@optimizer_switch="derived_merge=off";
10978explain format=json SELECT *
10979FROM (SELECT * FROM t2) AS derived1
10980LEFT JOIN t1
10981USING (col_varchar_nokey)
10982WHERE (col_varchar_nokey, col_varchar_nokey) IN
10983(SELECT col_varchar_nokey, col_varchar_key
10984FROM t2 AS derived2
10985);
10986EXPLAIN
10987{
10988  "query_block": {
10989    "select_id": 1,
10990    "cost_info": {
10991      "query_cost": "41.85"
10992    },
10993    "nested_loop": [
10994      {
10995        "table": {
10996          "table_name": "derived1",
10997          "access_type": "ALL",
10998          "rows_examined_per_scan": 7,
10999          "rows_produced_per_join": 7,
11000          "filtered": "100.00",
11001          "cost_info": {
11002            "read_cost": "10.35",
11003            "eval_cost": "1.40",
11004            "prefix_cost": "11.75",
11005            "data_read_per_join": "112"
11006          },
11007          "used_columns": [
11008            "col_varchar_key",
11009            "col_varchar_nokey"
11010          ],
11011          "attached_condition": "<in_optimizer>((`derived1`.`col_varchar_nokey`,`derived1`.`col_varchar_nokey`),(`derived1`.`col_varchar_nokey`,`derived1`.`col_varchar_nokey`) in ( <materialize> (/* select#3 */ select `test`.`derived2`.`col_varchar_nokey`,`test`.`derived2`.`col_varchar_key` from `test`.`t2` `derived2` where 1 ), <primary_index_lookup>(`derived1`.`col_varchar_nokey` in <temporary table> on <auto_key> where ((`derived1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_nokey`) and (`derived1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_key`)))))",
11012          "attached_subqueries": [
11013            {
11014              "table": {
11015                "table_name": "<materialized_subquery>",
11016                "access_type": "eq_ref",
11017                "key": "<auto_key>",
11018                "key_length": "8",
11019                "rows_examined_per_scan": 1,
11020                "materialized_from_subquery": {
11021                  "using_temporary_table": true,
11022                  "dependent": true,
11023                  "cacheable": false,
11024                  "query_block": {
11025                    "select_id": 3,
11026                    "cost_info": {
11027                      "query_cost": "3.43"
11028                    },
11029                    "table": {
11030                      "table_name": "derived2",
11031                      "access_type": "ALL",
11032                      "possible_keys": [
11033                        "col_varchar_key"
11034                      ],
11035                      "rows_examined_per_scan": 7,
11036                      "rows_produced_per_join": 7,
11037                      "filtered": "100.00",
11038                      "cost_info": {
11039                        "read_cost": "2.03",
11040                        "eval_cost": "1.40",
11041                        "prefix_cost": "3.43",
11042                        "data_read_per_join": "56"
11043                      },
11044                      "used_columns": [
11045                        "col_varchar_key",
11046                        "col_varchar_nokey"
11047                      ]
11048                    }
11049                  }
11050                }
11051              }
11052            }
11053          ],
11054          "materialized_from_subquery": {
11055            "using_temporary_table": true,
11056            "dependent": false,
11057            "cacheable": true,
11058            "query_block": {
11059              "select_id": 2,
11060              "cost_info": {
11061                "query_cost": "3.43"
11062              },
11063              "table": {
11064                "table_name": "t2",
11065                "access_type": "ALL",
11066                "rows_examined_per_scan": 7,
11067                "rows_produced_per_join": 7,
11068                "filtered": "100.00",
11069                "cost_info": {
11070                  "read_cost": "2.03",
11071                  "eval_cost": "1.40",
11072                  "prefix_cost": "3.43",
11073                  "data_read_per_join": "56"
11074                },
11075                "used_columns": [
11076                  "col_varchar_key",
11077                  "col_varchar_nokey"
11078                ]
11079              }
11080            }
11081          }
11082        }
11083      },
11084      {
11085        "table": {
11086          "table_name": "t1",
11087          "access_type": "ALL",
11088          "rows_examined_per_scan": 20,
11089          "rows_produced_per_join": 140,
11090          "filtered": "100.00",
11091          "using_join_buffer": "Block Nested Loop",
11092          "cost_info": {
11093            "read_cost": "2.10",
11094            "eval_cost": "28.00",
11095            "prefix_cost": "41.85",
11096            "data_read_per_join": "1K"
11097          },
11098          "used_columns": [
11099            "col_varchar_nokey"
11100          ],
11101          "attached_condition": "<if>(is_not_null_compl(t1), (`test`.`t1`.`col_varchar_nokey` = `derived1`.`col_varchar_nokey`), true)"
11102        }
11103      }
11104    ]
11105  }
11106}
11107Warnings:
11108Note	1003	/* select#1 */ select `derived1`.`col_varchar_nokey` AS `col_varchar_nokey`,`derived1`.`col_varchar_key` AS `col_varchar_key` from (/* select#2 */ select `test`.`t2`.`col_varchar_key` AS `col_varchar_key`,`test`.`t2`.`col_varchar_nokey` AS `col_varchar_nokey` from `test`.`t2`) `derived1` left join `test`.`t1` on((`test`.`t1`.`col_varchar_nokey` = `derived1`.`col_varchar_nokey`)) where <in_optimizer>((`derived1`.`col_varchar_nokey`,`derived1`.`col_varchar_nokey`),(`derived1`.`col_varchar_nokey`,`derived1`.`col_varchar_nokey`) in ( <materialize> (/* select#3 */ select `test`.`derived2`.`col_varchar_nokey`,`test`.`derived2`.`col_varchar_key` from `test`.`t2` `derived2` where 1 ), <primary_index_lookup>(`derived1`.`col_varchar_nokey` in <temporary table> on <auto_key> where ((`derived1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_nokey`) and (`derived1`.`col_varchar_nokey` = `materialized-subquery`.`col_varchar_key`)))))
11109SELECT *
11110FROM (SELECT * FROM t2) AS derived1
11111LEFT JOIN t1
11112USING (col_varchar_nokey)
11113WHERE (col_varchar_nokey, col_varchar_nokey) IN
11114(SELECT col_varchar_nokey, col_varchar_key
11115FROM t2 AS derived2
11116);
11117col_varchar_nokey	col_varchar_key
11118v	v
11119y	y
11120c	c
11121v	v
11122y	y
11123y	y
11124j	j
11125m	m
11126d	d
11127d	d
11128SET @@optimizer_switch= @optimizer_switch_saved;
11129DROP TABLE t1, t2;
11130CREATE TABLE t1 (
11131col_int_nokey int NOT NULL,
11132col_int_key int NOT NULL,
11133KEY col_int_key (col_int_key)
11134);
11135INSERT INTO t1 VALUES
11136(1,7), (7,0), (4,9), (7,3), (0,4), (2,2), (9,5), (4,3), (0,1), (9,3),
11137(1,6), (3,7), (8,5), (8,1), (18,204), (84,224), (6,9), (3,5), (6,0), (6,3);
11138CREATE TABLE t2 (
11139col_int_nokey int NOT NULL,
11140col_int_key int NOT NULL,
11141KEY col_int_key (col_int_key)
11142);
11143INSERT INTO t2 VALUES
11144(4,0), (6,8), (3,1), (5,8), (3,9), (246,24), (2,6), (9,1), (3,6), (8,2),
11145(1,4), (8,8), (8,4), (5,4), (7,7), (5,4), (1,1), (6,9), (2,4), (9,8);
11146explain format=json SELECT grandparent1.*
11147FROM t1 AS grandparent1
11148LEFT JOIN t1 USING (col_int_nokey)
11149WHERE (col_int_nokey, col_int_nokey) IN
11150(SELECT col_int_nokey, col_int_key
11151FROM t2
11152);
11153EXPLAIN
11154{
11155  "query_block": {
11156    "select_id": 1,
11157    "cost_info": {
11158      "query_cost": "88.09"
11159    },
11160    "nested_loop": [
11161      {
11162        "table": {
11163          "table_name": "grandparent1",
11164          "access_type": "ALL",
11165          "rows_examined_per_scan": 20,
11166          "rows_produced_per_join": 20,
11167          "filtered": "100.00",
11168          "cost_info": {
11169            "read_cost": "2.04",
11170            "eval_cost": "4.00",
11171            "prefix_cost": "6.04",
11172            "data_read_per_join": "320"
11173          },
11174          "used_columns": [
11175            "col_int_nokey",
11176            "col_int_key"
11177          ],
11178          "attached_condition": "<in_optimizer>((`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_nokey`),(`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_nokey`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`col_int_nokey`,`test`.`t2`.`col_int_key` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`grandparent1`.`col_int_nokey` in <temporary table> on <auto_key> where ((`test`.`grandparent1`.`col_int_nokey` = `materialized-subquery`.`col_int_nokey`) and (`test`.`grandparent1`.`col_int_nokey` = `materialized-subquery`.`col_int_key`)))))",
11179          "attached_subqueries": [
11180            {
11181              "table": {
11182                "table_name": "<materialized_subquery>",
11183                "access_type": "eq_ref",
11184                "key": "<auto_key>",
11185                "key_length": "8",
11186                "rows_examined_per_scan": 1,
11187                "materialized_from_subquery": {
11188                  "using_temporary_table": true,
11189                  "dependent": true,
11190                  "cacheable": false,
11191                  "query_block": {
11192                    "select_id": 2,
11193                    "cost_info": {
11194                      "query_cost": "6.04"
11195                    },
11196                    "table": {
11197                      "table_name": "t2",
11198                      "access_type": "ALL",
11199                      "possible_keys": [
11200                        "col_int_key"
11201                      ],
11202                      "rows_examined_per_scan": 20,
11203                      "rows_produced_per_join": 20,
11204                      "filtered": "100.00",
11205                      "cost_info": {
11206                        "read_cost": "2.04",
11207                        "eval_cost": "4.00",
11208                        "prefix_cost": "6.04",
11209                        "data_read_per_join": "320"
11210                      },
11211                      "used_columns": [
11212                        "col_int_nokey",
11213                        "col_int_key"
11214                      ]
11215                    }
11216                  }
11217                }
11218              }
11219            }
11220          ]
11221        }
11222      },
11223      {
11224        "table": {
11225          "table_name": "t1",
11226          "access_type": "ALL",
11227          "rows_examined_per_scan": 20,
11228          "rows_produced_per_join": 400,
11229          "filtered": "100.00",
11230          "using_join_buffer": "Block Nested Loop",
11231          "cost_info": {
11232            "read_cost": "2.05",
11233            "eval_cost": "80.00",
11234            "prefix_cost": "88.09",
11235            "data_read_per_join": "6K"
11236          },
11237          "used_columns": [
11238            "col_int_nokey"
11239          ],
11240          "attached_condition": "<if>(is_not_null_compl(t1), (`test`.`t1`.`col_int_nokey` = `test`.`grandparent1`.`col_int_nokey`), true)"
11241        }
11242      }
11243    ]
11244  }
11245}
11246Warnings:
11247Note	1003	/* select#1 */ select `test`.`grandparent1`.`col_int_nokey` AS `col_int_nokey`,`test`.`grandparent1`.`col_int_key` AS `col_int_key` from `test`.`t1` `grandparent1` left join `test`.`t1` on((`test`.`t1`.`col_int_nokey` = `test`.`grandparent1`.`col_int_nokey`)) where <in_optimizer>((`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_nokey`),(`test`.`grandparent1`.`col_int_nokey`,`test`.`grandparent1`.`col_int_nokey`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`col_int_nokey`,`test`.`t2`.`col_int_key` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`grandparent1`.`col_int_nokey` in <temporary table> on <auto_key> where ((`test`.`grandparent1`.`col_int_nokey` = `materialized-subquery`.`col_int_nokey`) and (`test`.`grandparent1`.`col_int_nokey` = `materialized-subquery`.`col_int_key`)))))
11248SELECT grandparent1.*
11249FROM t1 AS grandparent1
11250LEFT JOIN t1 USING (col_int_nokey)
11251WHERE (col_int_nokey, col_int_nokey) IN
11252(SELECT col_int_nokey, col_int_key
11253FROM t2
11254);
11255col_int_nokey	col_int_key
112561	7
112571	6
112587	0
112597	3
112607	0
112617	3
112621	7
112631	6
112648	5
112658	1
112668	5
112678	1
11268DROP TABLE t1, t2;
11269CREATE TABLE t1 (
11270pk int,
11271col_int_key int,
11272col_datetime_key datetime,
11273col_varchar_key varchar(1),
11274col_varchar_nokey varchar(1),
11275PRIMARY KEY (pk),
11276KEY col_int_key (col_int_key),
11277KEY col_datetime_key (col_datetime_key),
11278KEY col_varchar_key (col_varchar_key,col_int_key)
11279) engine=MyISAM;
11280INSERT INTO t1 VALUES
11281(10,7,'2004-06-06 04:22:12','v','v'), (11,0,'2005-11-13 01:12:31','s','s'),
11282(12,9,'2002-05-04 01:50:00','l','l'), (13,3,'2004-10-27 10:28:45','y','y'),
11283(14,4,'2006-07-22 05:24:23','c','c'), (15,2,'2002-05-16 21:34:03','i','i'),
11284(16,5,'2008-04-17 10:45:30','h','h'), (17,3,'2009-04-21 02:58:02','q','q'),
11285(18,1,'2008-01-11 11:01:51','a','a'), (19,3,'1900-01-01 00:00:00','v','v'),
11286(20,6,'2007-05-17 18:24:57','u','u'), (21,7,'2007-08-07 00:00:00','s','s'),
11287(22,5,'2001-08-28 00:00:00','y','y'), (23,1,'2004-04-16 00:27:28','z','z'),
11288(24,204,'2005-05-03 07:06:22','h','h'), (25,224,'2009-03-11 17:09:50','p','p'),
11289(26,9,'2007-12-08 01:54:28','e','e'), (27,5,'2009-07-28 18:19:54','i','i'),
11290(28,0,'2008-06-08 00:00:00','y','y'), (29,3,'2005-02-09 09:20:26','w','w');
11291CREATE TABLE t2 (
11292pk int,
11293col_int_key int,
11294col_datetime_key datetime,
11295col_varchar_key varchar(1),
11296col_varchar_nokey varchar(1),
11297PRIMARY KEY (pk),
11298KEY col_int_key (col_int_key),
11299KEY col_datetime_key (col_datetime_key),
11300KEY col_varchar_key (col_varchar_key,col_int_key)
11301) engine=MyISAM;
11302INSERT INTO t2 VALUES
11303(1,0,'2002-02-13 17:30:06','j','j'), (2,8,'2008-09-27 00:34:58','v','v'),
11304(3,1,'2007-05-28 00:00:00','c','c'), (4,8,'2009-07-25 09:21:20','m','m'),
11305(5,9,'2002-01-16 00:00:00','d','d'), (6,24,'2006-10-12 04:32:53','d','d'),
11306(7,6,'2001-02-15 03:08:38','y','y'), (8,1,'2004-10-02 20:31:15','t','t'),
11307(9,6,'2002-08-20 22:48:00','d','d'), (10,2,'1900-01-01 00:00:00','s','s'),
11308(11,4,'2005-08-15 00:00:00','r','r'), (12,8,'1900-01-01 00:00:00','m','m'),
11309(13,4,'2008-05-16 08:09:06','b','b'), (14,4,'2001-01-20 12:47:23','x','x'),
11310(15,7,'2008-07-02 00:00:00','g','g'), (16,4,'1900-01-01 00:00:00','p','p'),
11311(17,1,'2002-12-08 11:34:58','q','q'), (18,9,'1900-01-01 00:00:00','w','w'),
11312(19,4,'1900-01-01 00:00:00','d','d'), (20,8,'2002-08-25 20:35:06','e','e');
11313SELECT alias1.col_datetime_key
11314FROM t2 AS alias1
11315RIGHT JOIN t2 AS alias2
11316JOIN t2 AS alias3
11317ON alias3.pk = alias2.pk
11318ON alias3.col_varchar_nokey = alias2.col_varchar_key OR
11319alias2.col_varchar_nokey
11320WHERE (alias2.col_varchar_key, alias2.col_varchar_key) IN
11321(SELECT sq2_alias2.col_varchar_key, sq2_alias1.col_varchar_nokey
11322FROM t1 AS sq2_alias1, t1 AS sq2_alias2
11323WHERE sq2_alias2.col_int_key < 2);
11324col_datetime_key
113251900-01-01 00:00:00
113261900-01-01 00:00:00
113271900-01-01 00:00:00
113281900-01-01 00:00:00
113291900-01-01 00:00:00
113301900-01-01 00:00:00
113311900-01-01 00:00:00
113321900-01-01 00:00:00
113331900-01-01 00:00:00
113341900-01-01 00:00:00
113352001-01-20 12:47:23
113362001-01-20 12:47:23
113372001-02-15 03:08:38
113382001-02-15 03:08:38
113392002-01-16 00:00:00
113402002-01-16 00:00:00
113412002-02-13 17:30:06
113422002-02-13 17:30:06
113432002-08-20 22:48:00
113442002-08-20 22:48:00
113452002-08-25 20:35:06
113462002-08-25 20:35:06
113472002-12-08 11:34:58
113482002-12-08 11:34:58
113492004-10-02 20:31:15
113502004-10-02 20:31:15
113512005-08-15 00:00:00
113522005-08-15 00:00:00
113532006-10-12 04:32:53
113542006-10-12 04:32:53
113552007-05-28 00:00:00
113562007-05-28 00:00:00
113572008-05-16 08:09:06
113582008-05-16 08:09:06
113592008-07-02 00:00:00
113602008-07-02 00:00:00
113612008-09-27 00:34:58
113622008-09-27 00:34:58
113632009-07-25 09:21:20
113642009-07-25 09:21:20
11365ALTER TABLE t1 DISABLE KEYS;
11366ALTER TABLE t2 DISABLE KEYS;
11367explain format=json SELECT alias1.col_datetime_key
11368FROM t2 AS alias1
11369RIGHT JOIN t2 AS alias2
11370JOIN t2 AS alias3
11371ON alias3.pk = alias2.pk
11372ON alias3.col_varchar_nokey = alias2.col_varchar_key OR
11373alias2.col_varchar_nokey
11374WHERE (alias2.col_varchar_key, alias2.col_varchar_key) IN
11375(SELECT sq2_alias2.col_varchar_key, sq2_alias1.col_varchar_nokey
11376FROM t1 AS sq2_alias1, t1 AS sq2_alias2
11377WHERE sq2_alias2.col_int_key < 2);
11378EXPLAIN
11379{
11380  "query_block": {
11381    "select_id": 1,
11382    "cost_info": {
11383      "query_cost": "112.23"
11384    },
11385    "nested_loop": [
11386      {
11387        "table": {
11388          "table_name": "alias2",
11389          "access_type": "ALL",
11390          "possible_keys": [
11391            "PRIMARY"
11392          ],
11393          "rows_examined_per_scan": 20,
11394          "rows_produced_per_join": 20,
11395          "filtered": "100.00",
11396          "cost_info": {
11397            "read_cost": "2.12",
11398            "eval_cost": "4.00",
11399            "prefix_cost": "6.12",
11400            "data_read_per_join": "480"
11401          },
11402          "used_columns": [
11403            "pk",
11404            "col_varchar_key",
11405            "col_varchar_nokey"
11406          ],
11407          "attached_condition": "<in_optimizer>((`test`.`alias2`.`col_varchar_key`,`test`.`alias2`.`col_varchar_key`),(`test`.`alias2`.`col_varchar_key`,`test`.`alias2`.`col_varchar_key`) in ( <materialize> (/* select#2 */ select `test`.`sq2_alias2`.`col_varchar_key`,`test`.`sq2_alias1`.`col_varchar_nokey` from `test`.`t1` `sq2_alias1` join `test`.`t1` `sq2_alias2` where (`test`.`sq2_alias2`.`col_int_key` < 2) ), <primary_index_lookup>(`test`.`alias2`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`alias2`.`col_varchar_key` = `materialized-subquery`.`col_varchar_key`) and (`test`.`alias2`.`col_varchar_key` = `materialized-subquery`.`col_varchar_nokey`)))))",
11408          "attached_subqueries": [
11409            {
11410              "table": {
11411                "table_name": "<materialized_subquery>",
11412                "access_type": "eq_ref",
11413                "key": "<auto_key>",
11414                "key_length": "8",
11415                "rows_examined_per_scan": 1,
11416                "materialized_from_subquery": {
11417                  "using_temporary_table": true,
11418                  "dependent": true,
11419                  "cacheable": false,
11420                  "query_block": {
11421                    "select_id": 2,
11422                    "cost_info": {
11423                      "query_cost": "34.89"
11424                    },
11425                    "nested_loop": [
11426                      {
11427                        "table": {
11428                          "table_name": "sq2_alias2",
11429                          "access_type": "ALL",
11430                          "rows_examined_per_scan": 20,
11431                          "rows_produced_per_join": 6,
11432                          "filtered": "33.33",
11433                          "cost_info": {
11434                            "read_cost": "4.78",
11435                            "eval_cost": "1.33",
11436                            "prefix_cost": "6.12",
11437                            "data_read_per_join": "159"
11438                          },
11439                          "used_columns": [
11440                            "col_int_key",
11441                            "col_varchar_key"
11442                          ],
11443                          "attached_condition": "(`test`.`sq2_alias2`.`col_int_key` < 2)"
11444                        }
11445                      },
11446                      {
11447                        "table": {
11448                          "table_name": "sq2_alias1",
11449                          "access_type": "ALL",
11450                          "rows_examined_per_scan": 20,
11451                          "rows_produced_per_join": 133,
11452                          "filtered": "100.00",
11453                          "using_join_buffer": "Block Nested Loop",
11454                          "cost_info": {
11455                            "read_cost": "2.12",
11456                            "eval_cost": "26.66",
11457                            "prefix_cost": "34.89",
11458                            "data_read_per_join": "3K"
11459                          },
11460                          "used_columns": [
11461                            "col_varchar_nokey"
11462                          ]
11463                        }
11464                      }
11465                    ]
11466                  }
11467                }
11468              }
11469            }
11470          ]
11471        }
11472      },
11473      {
11474        "table": {
11475          "table_name": "alias3",
11476          "access_type": "eq_ref",
11477          "possible_keys": [
11478            "PRIMARY"
11479          ],
11480          "key": "PRIMARY",
11481          "used_key_parts": [
11482            "pk"
11483          ],
11484          "key_length": "4",
11485          "ref": [
11486            "test.alias2.pk"
11487          ],
11488          "rows_examined_per_scan": 1,
11489          "rows_produced_per_join": 20,
11490          "filtered": "100.00",
11491          "cost_info": {
11492            "read_cost": "20.00",
11493            "eval_cost": "4.00",
11494            "prefix_cost": "30.12",
11495            "data_read_per_join": "480"
11496          },
11497          "used_columns": [
11498            "pk",
11499            "col_varchar_nokey"
11500          ]
11501        }
11502      },
11503      {
11504        "table": {
11505          "table_name": "alias1",
11506          "access_type": "ALL",
11507          "rows_examined_per_scan": 20,
11508          "rows_produced_per_join": 400,
11509          "filtered": "100.00",
11510          "using_join_buffer": "Block Nested Loop",
11511          "cost_info": {
11512            "read_cost": "2.12",
11513            "eval_cost": "80.00",
11514            "prefix_cost": "112.24",
11515            "data_read_per_join": "9K"
11516          },
11517          "used_columns": [
11518            "col_datetime_key"
11519          ],
11520          "attached_condition": "<if>(is_not_null_compl(alias1), ((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`) or `test`.`alias2`.`col_varchar_nokey`), true)"
11521        }
11522      }
11523    ]
11524  }
11525}
11526Warnings:
11527Note	1003	/* select#1 */ select `test`.`alias1`.`col_datetime_key` AS `col_datetime_key` from `test`.`t2` `alias2` join `test`.`t2` `alias3` left join `test`.`t2` `alias1` on(((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`) or `test`.`alias2`.`col_varchar_nokey`)) where ((`test`.`alias3`.`pk` = `test`.`alias2`.`pk`) and <in_optimizer>((`test`.`alias2`.`col_varchar_key`,`test`.`alias2`.`col_varchar_key`),(`test`.`alias2`.`col_varchar_key`,`test`.`alias2`.`col_varchar_key`) in ( <materialize> (/* select#2 */ select `test`.`sq2_alias2`.`col_varchar_key`,`test`.`sq2_alias1`.`col_varchar_nokey` from `test`.`t1` `sq2_alias1` join `test`.`t1` `sq2_alias2` where (`test`.`sq2_alias2`.`col_int_key` < 2) ), <primary_index_lookup>(`test`.`alias2`.`col_varchar_key` in <temporary table> on <auto_key> where ((`test`.`alias2`.`col_varchar_key` = `materialized-subquery`.`col_varchar_key`) and (`test`.`alias2`.`col_varchar_key` = `materialized-subquery`.`col_varchar_nokey`))))))
11528SELECT alias1.col_datetime_key
11529FROM t2 AS alias1
11530RIGHT JOIN t2 AS alias2
11531JOIN t2 AS alias3
11532ON alias3.pk = alias2.pk
11533ON alias3.col_varchar_nokey = alias2.col_varchar_key OR
11534alias2.col_varchar_nokey
11535WHERE (alias2.col_varchar_key, alias2.col_varchar_key) IN
11536(SELECT sq2_alias2.col_varchar_key, sq2_alias1.col_varchar_nokey
11537FROM t1 AS sq2_alias1, t1 AS sq2_alias2
11538WHERE sq2_alias2.col_int_key < 2);
11539col_datetime_key
115402002-02-13 17:30:06
115412002-02-13 17:30:06
115422008-09-27 00:34:58
115432008-09-27 00:34:58
115442007-05-28 00:00:00
115452007-05-28 00:00:00
115462009-07-25 09:21:20
115472009-07-25 09:21:20
115482002-01-16 00:00:00
115492002-01-16 00:00:00
115502006-10-12 04:32:53
115512006-10-12 04:32:53
115522001-02-15 03:08:38
115532001-02-15 03:08:38
115542004-10-02 20:31:15
115552004-10-02 20:31:15
115562002-08-20 22:48:00
115572002-08-20 22:48:00
115581900-01-01 00:00:00
115591900-01-01 00:00:00
115602005-08-15 00:00:00
115612005-08-15 00:00:00
115621900-01-01 00:00:00
115631900-01-01 00:00:00
115642008-05-16 08:09:06
115652008-05-16 08:09:06
115662001-01-20 12:47:23
115672001-01-20 12:47:23
115682008-07-02 00:00:00
115692008-07-02 00:00:00
115701900-01-01 00:00:00
115711900-01-01 00:00:00
115722002-12-08 11:34:58
115732002-12-08 11:34:58
115741900-01-01 00:00:00
115751900-01-01 00:00:00
115761900-01-01 00:00:00
115771900-01-01 00:00:00
115782002-08-25 20:35:06
115792002-08-25 20:35:06
11580DROP TABLE t1, t2;
11581# End of test for bug#14064201.
11582#
11583# Bug#18223655:ASSERTION FAILED: (INT)IDX >= 0
11584#               && IDX < PARENT_JOIN->TABLES
11585#
11586CREATE TABLE b (d INT);
11587CREATE TABLE c (a INT, b INT,c INT,d BLOB NOT NULL);
11588SELECT(SELECT  1
11589FROM b WHERE(SELECT 1 IN (SELECT 1 FROM b WHERE 1 NOT BETWEEN d AND 1)
11590FROM  b) IN (SELECT d FROM c)) as cc FROM  b;
11591cc
11592INSERT INTO b VALUE(1);
11593INSERT INTO c VALUES(1,2,3,'1'),(2,3,4,'1'),(3,4,5,'C');
11594SELECT(SELECT d FROM b WHERE(SELECT d IN
11595(SELECT d FROM b WHERE 1 NOT BETWEEN d AND 1) FROM b) IN
11596(SELECT d FROM c)) as cc FROM  c;
11597cc
115981
115991
116001
11601DROP TABLE b,c;
11602#
11603# Bug#18447874:WRONG RESULT COMING FROM SEMI-JOIN
11604#
11605CREATE TABLE b (
11606d INT(11)
11607);
11608CREATE TABLE c (
11609d BLOB
11610) ;
11611CREATE TABLE d (
11612b INT(11)
11613);
11614INSERT INTO b VALUES(1),(2),(4);
11615INSERT INTO c VALUES(1),(2),(3);
11616SELECT  1 FROM b  WHERE (SELECT 1 FROM d ) IN (SELECT d FROM c) ;
116171
11618INSERT INTO d VALUES(2);
11619SELECT  1 FROM b  WHERE (SELECT 1 FROM d ) IN (SELECT d FROM c) ;
116201
116211
116221
116231
11624DROP TABLE b,c,d;
11625#
11626# Bug#17292723:INCORRECT RESULT FOR (SELECT...) IN (SELECT...) STATEMENT
11627#
11628CREATE TABLE t1 (
11629ID int(11) NOT NULL AUTO_INCREMENT,
11630id2 int(11) DEFAULT NULL,
11631id3 int(11) DEFAULT NULL,
11632id4 varchar(150) COLLATE utf8_spanish_ci NOT NULL,
11633id5 int(11) DEFAULT NULL,
11634PRIMARY KEY (ID),
11635KEY id2 (id2),
11636KEY id3 (id3),
11637KEY id5 (id5)
11638) ENGINE=InnoDB;
11639INSERT INTO t1 VALUES
11640(123,1,1,'1',NULL),
11641(124,1,1,'2',NULL),
11642(125,1,1,'4',NULL),
11643(126,1,1,'3',NULL),
11644(127,1,1,'6',NULL),
11645(128,1,1,'8',NULL);
11646CREATE TABLE t2 (
11647id6 int(11) NOT NULL,
11648id7 int(11) NOT NULL,
11649PRIMARY KEY (id6,id7),
11650KEY id7 (id7)
11651) ENGINE=InnoDB;
11652INSERT INTO t2 VALUES (126,123),(130,123),(135,123);
11653SELECT ID
11654FROM t1 p0
11655WHERE  p0.id3=1
11656AND ( (SELECT p1.id FROM t1 p1 WHERE p1.id=123) IN (SELECT p3.id FROM t2
11657p2, t1 p3 WHERE p0.id=p2.id6 AND p2.id7=p3.id));
11658ID
11659126
11660DROP TABLE t1,t2;
11661set @@optimizer_switch=@old_opt_switch;
11662# End of 5.6 tests
11663#
11664# Bug#19336348 DEBUG CRASH AT SETUP_SEMIJOIN_DUPS_ELIMINATION IN SQL/SQL_SELECT.CC
11665#
11666CREATE TABLE t1 (
11667col_varchar_nokey varchar(1)
11668) ENGINE=InnoDB;
11669INSERT INTO t1 VALUES ('c'),(NULL),('x');
11670CREATE TABLE t2 (
11671pk int,
11672col_varchar_key varchar(1),
11673PRIMARY KEY (pk),
11674KEY col_varchar_key (col_varchar_key)
11675) ENGINE=InnoDB;
11676INSERT INTO t2 VALUES (10,'l'),(11,'p');
11677ANALYZE TABLE t1,t2;
11678Table	Op	Msg_type	Msg_text
11679test.t1	analyze	status	OK
11680test.t2	analyze	status	OK
11681EXPLAIN SELECT 1
11682FROM t1 AS outr
11683WHERE outr.col_varchar_nokey IN
11684(
11685SELECT innr.col_varchar_key
11686FROM t2 AS innr
11687WHERE innr.pk <= 7
11688)
11689;
11690id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
116911	PRIMARY	outr	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
116922	DEPENDENT SUBQUERY	innr	NULL	index_subquery	PRIMARY,col_varchar_key	col_varchar_key	4	func	1	50.00	Using where; Using index
11693Warnings:
11694Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t1` `outr` where <in_optimizer>(`test`.`outr`.`col_varchar_nokey`,<exists>(<index_lookup>(<cache>(`test`.`outr`.`col_varchar_nokey`) in t2 on col_varchar_key where ((`test`.`innr`.`pk` <= 7) and (<cache>(`test`.`outr`.`col_varchar_nokey`) = `test`.`innr`.`col_varchar_key`)))))
11695SELECT 1
11696FROM t1 AS outr
11697WHERE outr.col_varchar_nokey IN
11698(
11699SELECT innr.col_varchar_key
11700FROM t2 AS innr
11701WHERE innr.pk <= 7
11702)
11703;
117041
11705DROP TABLE t1,t2;
11706#
11707# Bug#18174394 BLOBS: CRASH AFTER UNINITIALIZED VALUES IN ITEM_FIELD::STR_RESULT
11708#
11709CREATE TABLE t1(d BLOB, b BLOB);
11710INSERT INTO t1(d,b) VALUES ('aaaa',''),('bnbb','');
11711SELECT 1 FROM t1
11712WHERE (SELECT b FROM t1) IN (SELECT (d>=1) FROM t1);
11713ERROR 21000: Subquery returns more than 1 row
11714DROP TABLE t1;
11715#
11716# Bug#19779600: ASSERT FAILED IN REPLACE_SUBCONDITION WITH IN
11717#               PREDICATE INSIDE IN PREDICATE
11718#
11719CREATE TABLE t(X INT) ENGINE=InnoDB;
11720INSERT INTO t VALUES (1);
11721ANALYZE TABLE t;
11722Table	Op	Msg_type	Msg_text
11723test.t	analyze	status	OK
11724EXPLAIN SELECT 1 FROM t WHERE (1 IN (SELECT 1 FROM t)) IN (SELECT 1 FROM t);
11725id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
117261	PRIMARY	t	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
117273	DEPENDENT SUBQUERY	t	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
117282	SUBQUERY	t	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
11729Warnings:
11730Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t` where <in_optimizer>(<in_optimizer>(1,<exists>(/* select#2 */ select 1 from `test`.`t` where 1)),<exists>(/* select#3 */ select 1 from `test`.`t` where (<cache>(<in_optimizer>(1,<exists>(/* select#2 */ select 1 from `test`.`t` where 1))) = 1)))
11731SELECT 1 FROM t WHERE (1 IN (SELECT 1 FROM t)) IN (SELECT 1 FROM t);
117321
117331
11734DROP TABLE t;
11735#
11736# Bug#19465034 ASSERT ON SETUP_SEMIJOIN_DUPS_ELIMINATION IN SQL/SQL_SELECT.CC
11737#
11738CREATE TABLE t1 (
11739pk INTEGER NOT NULL,
11740i1 INTEGER NOT NULL,
11741PRIMARY KEY (pk)
11742) ENGINE=InnoDB;
11743INSERT INTO t1 VALUES (1,1);
11744CREATE TABLE t2 (
11745pk INTEGER NOT NULL,
11746c1 VARCHAR(1) NOT NULL,
11747PRIMARY KEY (pk),
11748KEY c1_key (c1)
11749) ENGINE=InnoDB;
11750INSERT INTO t2 VALUES (1,'j'),(2,'v'),(3,'c');
11751CREATE TABLE t3 (
11752pk INTEGER NOT NULL,
11753c1 VARCHAR(1) NOT NULL,
11754PRIMARY KEY (pk),
11755KEY c1_key (c1)
11756) ENGINE=InnoDB;
11757INSERT INTO t3 VALUES (10,'v'),(11,'s');
11758ANALYZE TABLE t1, t2, t3;
11759Table	Op	Msg_type	Msg_text
11760test.t1	analyze	status	OK
11761test.t2	analyze	status	OK
11762test.t3	analyze	status	OK
11763EXPLAIN SELECT *
11764FROM t1 JOIN t2 ON t1.i1 >= t2.pk
11765WHERE t2.c1 IN (
11766SELECT  t3.c1
11767FROM t3
11768WHERE t3.pk < 3
11769);
11770id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
117711	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
117721	PRIMARY	t2	NULL	ALL	PRIMARY	NULL	NULL	NULL	3	33.33	Range checked for each record (index map: 0x1)
117732	DEPENDENT SUBQUERY	t3	NULL	index_subquery	PRIMARY,c1_key	c1_key	3	func	1	50.00	Using where; Using index
11774Warnings:
11775Note	1003	/* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i1` AS `i1`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c1` AS `c1` from `test`.`t1` join `test`.`t2` where (<in_optimizer>(`test`.`t2`.`c1`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`c1`) in t3 on c1_key where ((`test`.`t3`.`pk` < 3) and (<cache>(`test`.`t2`.`c1`) = `test`.`t3`.`c1`))))) and (`test`.`t1`.`i1` >= `test`.`t2`.`pk`))
11776SELECT *
11777FROM t1 JOIN t2 ON t1.i1 >= t2.pk
11778WHERE t2.c1 IN (
11779SELECT  t3.c1
11780FROM t3
11781WHERE t3.pk < 3
11782);
11783pk	i1	pk	c1
11784DROP TABLE t1,t2,t3;
11785#
11786# Bug#19586047: CRASH IN ARG_COMPARATOR::SET_CMP_FUNC
11787#
11788CREATE TABLE t1(x INT) ENGINE=InnoDB;
11789INSERT INTO t1 VALUES (1);
11790ANALYZE TABLE t1;
11791Table	Op	Msg_type	Msg_text
11792test.t1	analyze	status	OK
11793EXPLAIN SELECT 1 FROM t1 WHERE EXISTS(SELECT 1) IN (SELECT 1 FROM t1);
11794id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
117951	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
117963	DEPENDENT SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
117972	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
11798Warnings:
11799Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t1` where <in_optimizer>(exists(/* select#2 */ select 1),<exists>(/* select#3 */ select 1 from `test`.`t1` where (<cache>(exists(/* select#2 */ select 1)) = 1)))
11800SELECT 1 FROM t1 WHERE EXISTS(SELECT 1) IN (SELECT 1 FROM t1);
118011
118021
11803EXPLAIN SELECT 1 FROM t1 WHERE (SELECT 1, 2 FROM t1) IN (SELECT 1, 2 FROM t1);
11804id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
118051	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
118063	DEPENDENT SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
118072	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
11808Warnings:
11809Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t1` where <in_optimizer>((/* select#2 */ select 1,2 from `test`.`t1`),<exists>(/* select#3 */ select 1,1 from `test`.`t1` where 1))
11810SELECT 1 FROM t1 WHERE (SELECT 1, 2 FROM t1) IN (SELECT 1, 2 FROM t1);
118111
118121
11813EXPLAIN SELECT 1 FROM t1 WHERE
11814(SELECT 1, 2 FROM t1 WHERE x = 2) IN (SELECT 1, 2 FROM t1);
11815id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
118161	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
118173	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
118182	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
11819Warnings:
11820Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t1` where <in_optimizer>((/* select#2 */ select 1,2 from `test`.`t1` where (`test`.`t1`.`x` = 2)),<exists>(/* select#3 */ select 1,2 from `test`.`t1` where 0))
11821SELECT 1 FROM t1 WHERE
11822(SELECT 1, 2 FROM t1 WHERE x = 2) IN (SELECT 1, 2 FROM t1);
118231
11824DROP TABLE t1;
11825#
11826#Bug#20119743 ASSERTIONQEP_TAB->USE_ORDER() IN ENUM_NESTED_LOOP_STATE
11827#             EVALUATE_JOIN_RECORD
11828#
11829CREATE TABLE t1 (
11830pk int(11) NOT NULL,
11831col_varchar_nokey varchar(1) DEFAULT NULL,
11832PRIMARY KEY (pk)
11833);
11834INSERT INTO t1 VALUES (1,'x');
11835CREATE TABLE t2 (
11836col_date_key date DEFAULT NULL,
11837col_int_key int(11) DEFAULT NULL,
11838col_varchar_key varchar(1) DEFAULT NULL,
11839col_varchar_nokey varchar(1) DEFAULT NULL,
11840KEY col_int_key (col_int_key),
11841KEY col_date_key (col_date_key),
11842KEY col_varchar_key (col_varchar_key,col_int_key)
11843);
11844INSERT INTO t2 VALUES ('2000-12-03', 8, 'x', 'x'),('2008-05-03', 7, 'd', 'd'),
11845('2005-12-06', 1, 'r', 'r'),('2000-04-10', 7, 'f', 'f'),
11846('2002-11-05', 9, 'y', 'y'),('2000-09-06', NULL, 'u', 'u'),
11847(NULL, 1, 'm', 'm'),('2007-06-14', 9, NULL, NULL),
11848('2007-11-17', 2, 'o', 'o'),('2009-02-23', 9, 'w', 'w'),
11849('2007-01-08', 2, 'm', 'm'), ('2008-06-10', 4, 'q', 'q'),
11850('2002-10-20', 0, NULL, NULL),('2008-09-12', 4, 'd', 'd'),
11851('2006-06-16', 8, 'g', 'g'),('2004-09-18', NULL, 'x', 'x'),
11852('1900-01-01', NULL, 'f', 'f'),('2005-09-13', 0, 'p', 'p'),
11853('2007-04-09', NULL, 'j', 'j'),('2000-09-20', 8, 'c', 'c');
11854CREATE TABLE t3 (
11855pk int(11) NOT NULL,
11856col_varchar_nokey varchar(1) DEFAULT NULL,
11857PRIMARY KEY (pk)
11858);
11859INSERT INTO t3 VALUES (1, 'c'),(2, 'c'),(3, 'q'),(4, 'g'),(5, 'e'),(6, 'l'),
11860(7, NULL),(8, 'v'),(9, 'c'),(10, 'u'),(11, 'x'),(12, 'x'),(13, 'x'),(14, 'l'),
11861(15, 'e'),(16, 's'),(17, 'k'),(18, 'm'),(19, 'x'),(20, 's');
11862ANALYZE TABLE t1,t2,t3;
11863Table	Op	Msg_type	Msg_text
11864test.t1	analyze	status	OK
11865test.t2	analyze	status	OK
11866test.t3	analyze	status	OK
11867EXPLAIN SELECT r1.col_date_key
11868FROM t2 AS r1
11869WHERE r1.col_int_key NOT IN
11870(SELECT ir2.pk
11871FROM t2 AS ir1 STRAIGHT_JOIN t1 AS ir2
11872ON ir2.col_varchar_nokey = ir1.col_varchar_key
11873WHERE ir2.col_varchar_nokey > r1.col_varchar_nokey
11874AND ir2.pk IN
11875(SELECT iir2.pk
11876FROM t2 AS iir1 RIGHT JOIN t3 AS iir2
11877ON iir2.col_varchar_nokey = iir1.col_varchar_key))
11878ORDER BY r1.col_date_key;
11879id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
118801	PRIMARY	r1	NULL	ALL	NULL	NULL	NULL	NULL	20	100.00	Using where; Using filesort
118812	DEPENDENT SUBQUERY	ir1	NULL	index	col_varchar_key	col_varchar_key	9	NULL	20	100.00	Using where; Using index
118822	DEPENDENT SUBQUERY	ir2	NULL	eq_ref	PRIMARY	PRIMARY	4	func	1	100.00	Using where; Full scan on NULL key
118833	SUBQUERY	iir2	NULL	ALL	PRIMARY	NULL	NULL	NULL	20	100.00	NULL
118843	SUBQUERY	iir1	NULL	ref	col_varchar_key	col_varchar_key	4	test.iir2.col_varchar_nokey	1	100.00	Using index
11885SELECT r1.col_date_key
11886FROM t2 AS r1
11887WHERE r1.col_int_key NOT IN
11888(SELECT ir2.pk
11889FROM t2 AS ir1 STRAIGHT_JOIN t1 AS ir2
11890ON ir2.col_varchar_nokey = ir1.col_varchar_key
11891WHERE ir2.col_varchar_nokey > r1.col_varchar_nokey
11892AND ir2.pk IN
11893(SELECT iir2.pk
11894FROM t2 AS iir1 RIGHT JOIN t3 AS iir2
11895ON iir2.col_varchar_nokey = iir1.col_varchar_key))
11896ORDER BY r1.col_date_key;
11897col_date_key
118982000-04-10
118992000-09-20
119002000-12-03
119012002-10-20
119022002-11-05
119032004-09-18
119042005-09-13
119052006-06-16
119062007-01-08
119072007-06-14
119082007-11-17
119092008-05-03
119102008-06-10
119112008-09-12
119122009-02-23
11913SELECT COUNT(r1.col_date_key) AS COUNT_NUM
11914FROM t2 AS r1
11915WHERE r1.col_int_key NOT IN
11916(SELECT ir2.pk
11917FROM t2 AS ir1 STRAIGHT_JOIN t1 AS ir2
11918ON ir2.col_varchar_nokey = ir1.col_varchar_key
11919WHERE ir2.col_varchar_nokey > r1.col_varchar_nokey
11920AND ir2.pk IN
11921(SELECT iir2.pk
11922FROM t2 AS iir1 RIGHT JOIN t3 AS iir2
11923ON iir2.col_varchar_nokey = iir1.col_varchar_key
11924WHERE iir2.pk<3));
11925COUNT_NUM
1192615
11927DROP TABLE t1,t2,t3;
11928#
11929# Bug#20554585 ASSERT JOIN()->TABLES == 0... IN JOIN_TAB::GET_SJ_STRATEGY ON SUBQUERY + VAR
11930#
11931CREATE TABLE t1 (
11932pk int NOT NULL,
11933PRIMARY KEY (pk)
11934);
11935CREATE TABLE t2 (
11936pk int NOT NULL,
11937col_int_key int,
11938col_varchar_key varchar(1),
11939PRIMARY KEY (pk),
11940KEY col_int_key (col_int_key),
11941KEY col_varchar_key (col_varchar_key)
11942);
11943CREATE TABLE t3 (
11944pk int NOT NULL,
11945col_int_key int,
11946col_varchar_key varchar(1),
11947col_varchar varchar(1),
11948PRIMARY KEY (pk),
11949KEY col_int_key (col_int_key),
11950KEY col_varchar_key (col_varchar_key)
11951);
11952INSERT INTO t3 VALUES (1,4,'c','g'),(20,1,'i','p');
11953CREATE TABLE t4 (
11954col_int int
11955);
11956CREATE TABLE t5 (
11957col_varchar_key varchar(1),
11958pk int NOT NULL,
11959col_int int,
11960PRIMARY KEY (pk),
11961KEY col_varchar_key (col_varchar_key)
11962);
11963SELECT table1.col_varchar_key AS field1
11964FROM (t3 AS table1
11965INNER JOIN (
11966SELECT SUBQUERY1_t1.*
11967FROM (t1 AS SUBQUERY1_t1
11968RIGHT JOIN (t2 AS SUBQUERY1_t2
11969INNER JOIN t3 AS SUBQUERY1_t3
11970ON (SUBQUERY1_t3.col_varchar_key = SUBQUERY1_t2.col_varchar_key)
11971) ON (SUBQUERY1_t3.col_int_key = SUBQUERY1_t2.pk)
11972)
11973WHERE SUBQUERY1_t2.col_varchar_key >= ANY (
11974SELECT CHILD_SUBQUERY1_t2.col_varchar AS CHILD_SUBQUERY1_field1
11975FROM (t2 AS CHILD_SUBQUERY1_t1
11976LEFT OUTER JOIN t3 AS CHILD_SUBQUERY1_t2
11977ON (CHILD_SUBQUERY1_t2.col_int_key = CHILD_SUBQUERY1_t1.col_int_key)
11978)
11979WHERE CHILD_SUBQUERY1_t1.pk >= SUBQUERY1_t2.pk
11980)
11981) AS table2
11982ON (table2.pk = table1.pk)
11983)
11984WHERE (EXISTS ((
11985SELECT DISTINCT SUBQUERY2_t2.col_int AS SUBQUERY2_field1
11986FROM (t4 AS SUBQUERY2_t1
11987LEFT OUTER JOIN t5 AS SUBQUERY2_t2
11988ON (SUBQUERY2_t2.pk = SUBQUERY2_t1.col_int)
11989)
11990WHERE SUBQUERY2_t2.col_varchar_key != @var4
11991)))
11992AND table1.col_int_key < (35 + 192)
11993ORDER BY field1
11994;
11995field1
11996DROP TABLE t1, t2, t3, t4, t5;
11997#
11998# Bug#18892055: MISSING DATA ON SELECT ... IN WITH JOINS AND INNODB
11999#               ENGINE
12000#
12001CREATE TABLE t1 (
12002col_int_key INT,
12003pk INT NOT NULL,
12004PRIMARY KEY (pk),
12005KEY col_int_key (col_int_key)
12006) ENGINE = INNODB;
12007INSERT INTO t1 VALUES
12008( 0, 3 ),
12009( 0, 4 ),
12010( 3, 1 ),
12011( 900000000, 2 ),
12012( 1368719360, 5 ),
12013( 1922236416, 6 ),
12014( 8,7 );
12015CREATE TABLE t2 (
12016pk INT NOT NULL,
12017col_int INT,
12018PRIMARY KEY (pk)
12019) ENGINE = INNODB;
12020INSERT INTO t2 VALUES
12021( 1, 3 ),
12022( 2, 2 ),
12023( 3, 8 ),
12024( 4, 7 );
12025CREATE TABLE t3 (
12026col_int_key INT,
12027col_int INT,
12028KEY (col_int_key)
12029) ENGINE = INNODB;
12030INSERT INTO t3 VALUES
12031( 5, 1 ),
12032( -1, -1 ),
12033( 300000000, 1 ),
12034( 8, 1 );
12035CREATE TABLE t4 ( col_int_key INT ) ENGINE = INNODB;
12036INSERT INTO t4 VALUES
12037(0),
12038(3),
12039(8),
12040(900000000),
12041(1368719360),
12042(1922236416);
12043ANALYZE TABLE t1, t2, t3, t4;
12044Table	Op	Msg_type	Msg_text
12045test.t1	analyze	status	OK
12046test.t2	analyze	status	OK
12047test.t3	analyze	status	OK
12048test.t4	analyze	status	OK
12049explain SELECT *
12050FROM t4
12051WHERE (col_int_key) IN (
12052SELECT t1.col_int_key
12053FROM t1 LEFT JOIN ( t2 JOIN t3 ON t3.col_int_key = t2.col_int ) USING ( pk )
12054WHERE t3.col_int IS NULL
12055)
12056ORDER BY col_int_key
12057;
12058id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
120591	PRIMARY	t4	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using where; Using filesort
120602	SUBQUERY	t1	NULL	index	col_int_key	col_int_key	5	NULL	7	100.00	Using index
120612	SUBQUERY	t3	NULL	ALL	col_int_key	NULL	NULL	NULL	4	25.00	Using where; Using join buffer (Block Nested Loop)
120622	SUBQUERY	t2	NULL	ALL	PRIMARY	NULL	NULL	NULL	4	100.00	Using where; Using join buffer (Block Nested Loop)
12063Warnings:
12064Note	1003	/* select#1 */ select `test`.`t4`.`col_int_key` AS `col_int_key` from `test`.`t4` where <in_optimizer>(`test`.`t4`.`col_int_key`,`test`.`t4`.`col_int_key` in ( <materialize> (/* select#2 */ select `test`.`t1`.`col_int_key` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`col_int` = `test`.`t3`.`col_int_key`) and (`test`.`t2`.`pk` = `test`.`t1`.`pk`))) where isnull(`test`.`t3`.`col_int`) ), <primary_index_lookup>(`test`.`t4`.`col_int_key` in <temporary table> on <auto_key> where ((`test`.`t4`.`col_int_key` = `materialized-subquery`.`col_int_key`))))) order by `test`.`t4`.`col_int_key`
12065SELECT *
12066FROM t4
12067WHERE (col_int_key) IN (
12068SELECT t1.col_int_key
12069FROM t1 LEFT JOIN ( t2 JOIN t3 ON t3.col_int_key = t2.col_int ) USING ( pk )
12070WHERE t3.col_int IS NULL
12071)
12072ORDER BY col_int_key
12073;
12074col_int_key
120750
120763
120778
12078900000000
120791368719360
120801922236416
12081DROP TABLE t1, t2, t3, t4;
12082#
12083# Bug#20835095 CRASH AT CREATE_REF_FOR_KEY IN SQL/SQL_SELECT.CC
12084#
12085CREATE TABLE t1 (
12086pk INTEGER,
12087var_10_latin1 VARCHAR(10) CHARACTER SET latin1,
12088var_255_utf8 VARCHAR(255) CHARACTER SET utf8,
12089var_255_latin1 VARCHAR(255) CHARACTER SET latin1,
12090var_10_utf8 VARCHAR(10) CHARACTER SET utf8,
12091PRIMARY KEY (pk)
12092);
12093CREATE VIEW v1 AS SELECT * FROM t1;
12094INSERT INTO t1 VALUES
12095(1,'FROCJ','korrhrspki','UAYVL','BPZIS'),
12096(2,'him','a','CHYKN','OZZQT'),
12097(3,'WBITK','ULWBF','have','rhrh'),
12098(4,'or','right','up','it'),
12099(5,'GGDCP','x','who','as'),
12100(6,'j','i','e','w');
12101CREATE TABLE tv
12102SELECT var_255_utf8 AS field1
12103FROM t1;
12104EXPLAIN SELECT * FROM tv
12105WHERE field1 IN (
12106SELECT tv1.var_255_utf8
12107FROM v1 AS tv1 LEFT JOIN v1 AS tv2 ON tv1.var_10_latin1=tv2.var_10_utf8);
12108id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
121091	PRIMARY	tv	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using where
121102	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
121112	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using where; Using join buffer (Block Nested Loop)
12112Warnings:
12113Note	1003	/* select#1 */ select `test`.`tv`.`field1` AS `field1` from `test`.`tv` where <in_optimizer>(`test`.`tv`.`field1`,`test`.`tv`.`field1` in ( <materialize> (/* select#2 */ select `test`.`t1`.`var_255_utf8` from `test`.`t1` left join (`test`.`t1`) on((convert(`test`.`t1`.`var_10_latin1` using utf8) = `test`.`t1`.`var_10_utf8`)) where 1 ), <primary_index_lookup>(`test`.`tv`.`field1` in <temporary table> on <auto_key> where ((`test`.`tv`.`field1` = `materialized-subquery`.`var_255_utf8`)))))
12114SELECT * FROM tv
12115WHERE field1 IN (
12116SELECT tv1.var_255_utf8
12117FROM v1 AS tv1 LEFT JOIN v1 AS tv2 ON tv1.var_10_latin1=tv2.var_10_utf8);
12118field1
12119korrhrspki
12120a
12121ULWBF
12122right
12123x
12124i
12125DROP VIEW v1;
12126DROP TABLE t1, tv;
12127# 17832047 Crash in calculate_materialization_costs
12128CREATE TABLE t1(a INTEGER PRIMARY KEY);
12129INSERT INTO t1 VALUES (0),(1),(2);
12130SELECT 1 FROM t1
12131WHERE 1 IN
12132(SELECT 1 BETWEEN (LENGTH(a) IN (SELECT 1 FROM t1)) AND 1
12133FROM t1
12134);
121351
121361
121371
121381
12139DROP TABLE t1;
12140# 17845989 Assertion failed: !(used_tables() & ...
12141CREATE TABLE a(b INTEGER) engine=innodb;
12142CREATE TABLE c(a INTEGER) engine=innodb;
12143SELECT 1
12144FROM a
12145WHERE 1 IN (SELECT (a.b IS NULL) IN (SELECT 1 FROM c) FROM c)
12146;
121471
12148DROP TABLE a, c;
12149#
12150# Bug#18194196: OPTIMIZER EXECUTES STATEMENT INPERFORMANT
12151#
12152CREATE TABLE t1 (uid INTEGER, fid INTEGER, INDEX(uid));
12153INSERT INTO t1 VALUES
12154(1,1), (1,2), (1,3), (1,4),
12155(2,5), (2,6), (2,7), (2,8),
12156(3,1), (3,2), (3,9);
12157CREATE TABLE t2 (uid INT PRIMARY KEY, name VARCHAR(128), INDEX(name));
12158INSERT INTO t2 VALUES
12159(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
12160(6, "F"), (7, "G"), (8, "H"), (9, "I");
12161CREATE TABLE t3 (uid INT, fid INT, INDEX(uid));
12162INSERT INTO t3 VALUES
12163(1,1), (1,2), (1,3),(1,4),
12164(2,5), (2,6), (2,7), (2,8),
12165(3,1), (3,2), (3,9);
12166CREATE TABLE t4 (uid INT PRIMARY KEY, name VARCHAR(128), INDEX(name));
12167INSERT INTO t4 VALUES
12168(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
12169(6, "F"), (7, "G"), (8, "H"), (9, "I");
12170ANALYZE TABLE t1,t2,t3,t4;
12171Table	Op	Msg_type	Msg_text
12172test.t1	analyze	status	OK
12173test.t2	analyze	status	OK
12174test.t3	analyze	status	OK
12175test.t4	analyze	status	OK
12176EXPLAIN SELECT name FROM t2, t1
12177WHERE t1.uid IN (SELECT t4.uid FROM t4, t3 WHERE t3.uid=1 AND t4.uid=t3.fid)
12178AND t2.uid=t1.fid;
12179id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
121801	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	11	100.00	Using where
121811	PRIMARY	t2	NULL	eq_ref	PRIMARY	PRIMARY	4	test.t1.fid	1	100.00	NULL
121822	SUBQUERY	t3	NULL	ref	uid	uid	5	const	4	100.00	Using where
121832	SUBQUERY	t4	NULL	eq_ref	PRIMARY	PRIMARY	4	test.t3.fid	1	100.00	Using index
12184Warnings:
12185Note	1003	/* select#1 */ select `test`.`t2`.`name` AS `name` from `test`.`t2` join `test`.`t1` where ((`test`.`t2`.`uid` = `test`.`t1`.`fid`) and <in_optimizer>(`test`.`t1`.`uid`,`test`.`t1`.`uid` in ( <materialize> (/* select#2 */ select `test`.`t4`.`uid` from `test`.`t4` join `test`.`t3` where ((`test`.`t4`.`uid` = `test`.`t3`.`fid`) and (`test`.`t3`.`uid` = 1)) ), <primary_index_lookup>(`test`.`t1`.`uid` in <temporary table> on <auto_key> where ((`test`.`t1`.`uid` = `materialized-subquery`.`uid`))))))
12186FLUSH STATUS;
12187SELECT name FROM t2, t1
12188WHERE t1.uid IN (SELECT t4.uid FROM t4, t3 WHERE t3.uid=1 AND t4.uid=t3.fid)
12189AND t2.uid=t1.fid;
12190name
12191A
12192B
12193C
12194D
12195E
12196F
12197G
12198H
12199A
12200B
12201I
12202SHOW STATUS LIKE '%handler_read%';
12203Variable_name	Value
12204Handler_read_first	0
12205Handler_read_key	19
12206Handler_read_last	0
12207Handler_read_next	4
12208Handler_read_prev	0
12209Handler_read_rnd	0
12210Handler_read_rnd_next	12
12211DROP TABLE t1,t2,t3,t4;
12212# End of test for Bug#18194196
12213#
12214# Bug#21184091 ASSERT `READ_ROWS >= 0.0' AT
12215#              COST_MODEL_SERVER::TMPTABLE_READWRITE_COST()
12216#
12217CREATE TABLE t1 (
12218pk INTEGER,
12219col_varchar varchar(1),
12220col_int INTEGER,
12221PRIMARY KEY (pk)
12222) ENGINE=MyISAM;
12223CREATE TABLE t2 (
12224col_int INTEGER,
12225col_varchar varchar(1)
12226) ENGINE=MyISAM;
12227INSERT INTO t2 VALUES (7,'x');
12228INSERT INTO t2 VALUES (4,'z');
12229SELECT t2.col_varchar
12230FROM t2 STRAIGHT_JOIN t1 ON t2.col_varchar = t1.col_varchar
12231JOIN t2 AS table3 ON t1.pk = table3.col_int
12232WHERE t1.pk IN (SELECT col_int FROM t1);
12233col_varchar
12234DROP TABLE t1,t2;
12235# End of test for Bug#21184091
12236# Bug#21139722: Assertion failed: !(used_tables() & ((table_map) 1) ...
12237CREATE TABLE t1(a INTEGER) engine=innodb;
12238CREATE TABLE t2(b INTEGER) engine=innodb;
12239explain SELECT 1
12240FROM (SELECT 1 IN (SELECT 1
12241FROM t1
12242WHERE (SELECT 1 FROM t2 HAVING b) NOT IN (SELECT 1 FROM t2)
12243)
12244FROM t2
12245) AS z;
12246id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
122471	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
122482	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
122493	DEPENDENT SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
122505	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
122514	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
12252Warnings:
12253Note	1276	Field or reference 'b' of SELECT #4 was resolved in SELECT #2
12254Note	1003	/* select#1 */ select 1 AS `1` from (/* select#2 */ select <in_optimizer>(1,<exists>(/* select#3 */ select 1 from `test`.`t1` where (not(<in_optimizer>((/* select#4 */ select 1 from `test`.`t2` having `test`.`t2`.`b`),<exists>(/* select#5 */ select 1 from `test`.`t2` where <if>(outer_field_is_not_null, (<cache>((/* select#4 */ select 1 from `test`.`t2` having `test`.`t2`.`b`)) = 1), true))))))) AS `1 IN (SELECT 1
12255FROM t1
12256WHERE (SELECT 1 FROM t2 HAVING b) NOT IN (SELECT 1 FROM t2)
12257)` from `test`.`t2`) `z`
12258SELECT 1
12259FROM (SELECT 1 IN (SELECT 1
12260FROM t1
12261WHERE (SELECT 1 FROM t2 HAVING b) NOT IN (SELECT 1 FROM t2)
12262)
12263FROM t2
12264) AS z;
122651
12266DROP TABLE t1, t2;
12267CREATE TABLE t1(a INTEGER) engine=innodb;
12268explain SELECT (SELECT a FROM t1 AS t2
12269WHERE a IN (SELECT t1.a+t2.a FROM t1 AS t3))
12270FROM t1 AS t1;
12271id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
122721	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	NULL
122732	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
122743	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
12275Warnings:
12276Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
12277Note	1276	Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #2
12278Note	1003	/* select#1 */ select (/* select#2 */ select `test`.`t2`.`a` from `test`.`t1` `t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#3 */ select 1 from `test`.`t1` `t3` where (<cache>(`test`.`t2`.`a`) = (`test`.`t1`.`a` + `test`.`t2`.`a`))))) AS `(SELECT a FROM t1 AS t2
12279WHERE a IN (SELECT t1.a+t2.a FROM t1 AS t3))` from `test`.`t1`
12280SELECT (SELECT a FROM t1 AS t2
12281WHERE a IN (SELECT t1.a+t2.a FROM t1 AS t3))
12282FROM t1 AS t1;
12283(SELECT a FROM t1 AS t2
12284WHERE a IN (SELECT t1.a+t2.a FROM t1 AS t3))
12285DROP TABLE t1;
12286# End of test for Bug#21139722
12287SET DEFAULT_STORAGE_ENGINE=INNODB;
12288#
12289# Bug#21139402 ASSERTION FAILED: LENGTH > 0 && KEYPARTS != 0, CRASH IN JOIN::OPTIMIZE_KEYUSE
12290#
12291CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
12292CREATE TABLE t2 (c INT PRIMARY KEY);
12293EXPLAIN SELECT 1 FROM t1
12294WHERE 1 IN
12295(SELECT (c IS NULL) IN (SELECT a FROM t1 WHERE b)  FROM t2);
12296id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
122971	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
122982	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
122993	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
12300Warnings:
12301Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t1` where 0
12302SELECT 1 FROM t1
12303WHERE 1 IN
12304(SELECT (c IS NULL) IN (SELECT a FROM t1 WHERE b)  FROM t2);
123051
12306DROP TABLE t1,t2;
12307#
12308# Bug#21619634 ACCESS OF DEALLOCATED ITEM_OUTER_REF CAUSES CRASH: PREPARED STMT
12309#
12310create table cc (i int) engine="innodb";
12311insert into cc values (1);
12312select (select count(i) from cc as cc_alias
12313where (cc.i in (select cc_alias.i from cc)))
12314from cc group by i;
12315(select count(i) from cc as cc_alias
12316where (cc.i in (select cc_alias.i from cc)))
123171
12318prepare stmt from
12319"select (select count(i) from cc as cc_alias
12320         where (cc.i in (select cc_alias.i from cc)))
12321     from cc group by i";
12322execute stmt;
12323(select count(i) from cc as cc_alias
12324         where (cc.i in (select cc_alias.i from cc)))
123251
12326execute stmt;
12327(select count(i) from cc as cc_alias
12328         where (cc.i in (select cc_alias.i from cc)))
123291
12330drop table cc;
12331#
12332# Bug #22305361: QUERY WITH MATERIALIZED TABLE RETURNS INCORRECT
12333#                RESULTS IN 5.6
12334#
12335CREATE TABLE t(a INT,b INT);
12336INSERT INTO t VALUES (1,0),(1,0),(1,0),(1,0),(1,1);
12337ANALYZE TABLE t;
12338Table	Op	Msg_type	Msg_text
12339test.t	analyze	status	OK
12340EXPLAIN extended SELECT *
12341FROM t AS t1
12342WHERE t1.a IN (SELECT t2.a
12343FROM t AS t2
12344WHERE CONCAT(t2.a,'') NOT IN (SELECT t3.a
12345FROM t AS t3
12346WHERE t3.b=1));
12347id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
123481	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
123492	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
123503	DEPENDENT SUBQUERY	t3	NULL	ALL	NULL	NULL	NULL	NULL	5	20.00	Using where
12351Warnings:
12352Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
12353Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t` `t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t` `t2` where (not(<in_optimizer>(concat(`test`.`t2`.`a`,''),<exists>(/* select#3 */ select 1 from `test`.`t` `t3` where ((`test`.`t3`.`b` = 1) and <if>(outer_field_is_not_null, ((<cache>(concat(`test`.`t2`.`a`,'')) = `test`.`t3`.`a`) or isnull(`test`.`t3`.`a`)), true)) having <if>(outer_field_is_not_null, <is_not_null_test>(`test`.`t3`.`a`), true))))) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`a`)))))
12354SELECT *
12355FROM t AS t1
12356WHERE t1.a IN (SELECT t2.a
12357FROM t AS t2
12358WHERE CONCAT(t2.a,'') NOT IN (SELECT t3.a
12359FROM t AS t3
12360WHERE t3.b=1));
12361a	b
12362DROP TABLE t;
12363set optimizer_switch=default;
12364