2017-08-25 19:06:13 +02:00
create table t1 (a int, b int);
2017-08-29 02:32:39 +02:00
insert into t1
2017-08-25 19:06:13 +02:00
values (1,2), (4,6), (9,7),
(1,1), (2,5), (7,8);
create table t2 (a int, b int, c int);
2017-08-29 02:32:39 +02:00
insert into t2
values (1,2,3), (5,1,2), (4,3,7),
2017-08-25 19:06:13 +02:00
(8,9,0), (10,7,1), (5,5,1);
2017-09-02 23:19:20 +02:00
create table t3 (a int, b varchar(16), index idx(a));
insert into t3 values
(1, "abc"), (3, "egh"), (8, "axxx"), (10, "abc"),
(2, "ccw"), (8, "wqqe"), (7, "au"), (9, "waa"),
(3, "rass"), (9, "ert"), (9, "lok"), (8, "aww"),
(1, "todd"), (3, "rew"), (8, "aww"), (3, "sw"),
(11, "llk"), (7, "rbw"), (1, "sm"), (2, "jyp"),
(4, "yq"), (5, "pled"), (12, "ligin"), (12, "toww"),
(6, "mxm"), (15, "wanone"), (9, "sunqq"), (2, "abe");
2017-08-25 19:06:13 +02:00
# optimization is not used
select * from t1 where a in (1,2);
a b
1 2
1 1
2 5
2017-09-02 23:19:20 +02:00
explain extended select * from t1 where a in (1,2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 6 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`a` in (1,2)
2017-08-25 19:06:13 +02:00
# set minimum number of values in VALUEs list when optimization works to 2
set @@in_subquery_conversion_threshold= 2;
# single IN-predicate in WHERE-part
select * from t1 where a in (1,2);
a b
1 2
1 1
2 5
2017-08-29 02:32:39 +02:00
select * from t1
where a in
2017-08-25 19:06:13 +02:00
(
2017-08-29 02:32:39 +02:00
select *
from (values (1),(2)) as tvc_0
2017-08-25 19:06:13 +02:00
);
a b
1 2
1 1
2 5
2017-08-29 02:32:39 +02:00
explain extended select * from t1 where a in (1,2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 2 100.00
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1`
explain extended select * from t1
where a in
(
select *
from (values (1),(2)) as tvc_0
2017-08-25 19:06:13 +02:00
);
2017-08-29 02:32:39 +02:00
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 2 100.00
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-25 19:06:13 +02:00
# AND-condition with IN-predicates in WHERE-part
2017-08-29 02:32:39 +02:00
select * from t1
where a in (1,2) and
2017-08-25 19:06:13 +02:00
b in (1,5);
a b
1 1
2 5
2017-08-29 02:32:39 +02:00
select * from t1
where a in
2017-08-25 19:06:13 +02:00
(
2017-08-29 02:32:39 +02:00
select *
from (values (1),(2)) as tvc_0
)
2017-08-25 19:06:13 +02:00
and b in
(
2017-08-29 02:32:39 +02:00
select *
from (values (1),(5)) as tvc_1
2017-08-25 19:06:13 +02:00
);
a b
1 1
2 5
2017-08-29 02:32:39 +02:00
explain extended select * from t1
where a in (1,2) and
2017-08-25 19:06:13 +02:00
b in (1,5);
2017-08-29 02:32:39 +02:00
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery4> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 21:03:15 +02:00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2017-08-29 02:32:39 +02:00
4 MATERIALIZED <derived5> ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 2 100.00
5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-08-29 21:03:15 +02:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) semi join ((values (1),(5)) `tvc_1`) where `test`.`t1`.`b` = `tvc_1`.`1`
2017-08-29 02:32:39 +02:00
explain extended select * from t1
where a in
(
select *
from (values (1),(2)) as tvc_0
)
2017-08-25 19:06:13 +02:00
and b in
(
2017-08-29 02:32:39 +02:00
select *
from (values (1),(5)) as tvc_1
);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery4> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 21:03:15 +02:00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2017-08-29 02:32:39 +02:00
4 MATERIALIZED <derived5> ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 2 100.00
5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-08-29 21:03:15 +02:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) semi join ((values (1),(5)) `tvc_1`) where `test`.`t1`.`b` = `tvc_1`.`1`
2017-08-29 02:32:39 +02:00
# subquery with IN-predicate
select * from t1
where a in
(
select a
from t2 where b in (3,4)
);
a b
4 6
select * from t1
where a in
(
select a from t2
where b in
(
select *
from (values (3),(4)) as tvc_0
)
2017-08-25 19:06:13 +02:00
);
2017-08-29 02:32:39 +02:00
a b
4 6
explain extended select * from t1
where a in
(
select a
from t2 where b in (3,4)
);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(4)) `tvc_0` join `test`.`t2`) where `test`.`t2`.`b` = `tvc_0`.`3`
explain extended select * from t1
where a in
(
select a from t2
where b in
(
select *
from (values (3),(4)) as tvc_0
)
);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(4)) `tvc_0` join `test`.`t2`) where `test`.`t2`.`b` = `tvc_0`.`3`
# derived table with IN-predicate
select * from
(
select *
from t1
where a in (1,2)
) as dr_table;
2017-08-25 19:06:13 +02:00
a b
1 2
1 1
2 5
2017-08-29 02:32:39 +02:00
select * from
2017-08-25 19:06:13 +02:00
(
2017-08-29 02:32:39 +02:00
select *
from t1
where a in
2017-08-25 19:06:13 +02:00
(
2017-08-29 02:32:39 +02:00
select *
from (values (1),(2))
as tvc_0
)
) as dr_table;
2017-08-25 19:06:13 +02:00
a b
1 2
1 1
2 5
2017-08-29 02:32:39 +02:00
explain extended select * from
2017-08-25 19:06:13 +02:00
(
2017-08-29 02:32:39 +02:00
select *
from t1
where a in (1,2)
) as dr_table;
id select_type table type possible_keys key key_len ref rows filtered Extra
2017-11-02 05:42:26 +01:00
1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 02:32:39 +02:00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-11-02 05:42:26 +01:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-29 02:32:39 +02:00
explain extended select * from
(
select *
from t1
where a in
(
select *
from (values (1),(2))
as tvc_0
2017-08-25 19:06:13 +02:00
)
2017-08-29 02:32:39 +02:00
) as dr_table;
id select_type table type possible_keys key key_len ref rows filtered Extra
2017-11-02 05:42:26 +01:00
1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 02:32:39 +02:00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-11-02 05:42:26 +01:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-29 02:32:39 +02:00
# non-recursive CTE with IN-predicate
with tvc_0 as
(
select *
from t1
where a in (1,2)
)
select * from tvc_0;
2017-08-25 19:06:13 +02:00
a b
2017-08-29 02:32:39 +02:00
1 2
1 1
2 5
select * from
(
select *
from t1
where a in
2017-08-25 19:06:13 +02:00
(
2017-08-29 02:32:39 +02:00
select *
from (values (1),(2))
as tvc_0
2017-08-25 19:06:13 +02:00
)
2017-08-29 02:32:39 +02:00
) as dr_table;
2017-08-25 19:06:13 +02:00
a b
2017-08-29 02:32:39 +02:00
1 2
1 1
2 5
explain extended with tvc_0 as
2017-08-25 19:06:13 +02:00
(
2017-08-29 02:32:39 +02:00
select *
from t1
where a in (1,2)
2017-08-25 19:06:13 +02:00
)
2017-08-29 02:32:39 +02:00
select * from tvc_0;
id select_type table type possible_keys key key_len ref rows filtered Extra
2017-11-02 05:42:26 +01:00
1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 02:32:39 +02:00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-11-02 05:42:26 +01:00
Note 1003 with tvc_0 as (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` in (1,2))/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-29 02:32:39 +02:00
explain extended select * from
(
select *
from t1
where a in
(
select *
from (values (1),(2))
as tvc_0
2017-08-25 19:06:13 +02:00
)
2017-08-29 02:32:39 +02:00
) as dr_table;
id select_type table type possible_keys key key_len ref rows filtered Extra
2017-11-02 05:42:26 +01:00
1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 02:32:39 +02:00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-11-02 05:42:26 +01:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-29 02:32:39 +02:00
# VIEW with IN-predicate
create view v1 as
select *
from t1
where a in (1,2);
create view v2 as
select *
from t1
where a in
(
select *
from (values (1),(2))
as tvc_0
2017-08-25 19:06:13 +02:00
)
;
2017-08-29 02:32:39 +02:00
select * from v1;
a b
1 2
1 1
2 5
select * from v2;
a b
1 2
1 1
2 5
explain extended select * from v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
2017-11-02 05:42:26 +01:00
1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 02:32:39 +02:00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-11-02 05:42:26 +01:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-29 02:32:39 +02:00
explain extended select * from v2;
id select_type table type possible_keys key key_len ref rows filtered Extra
2017-11-02 05:42:26 +01:00
1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 02:32:39 +02:00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-11-02 05:42:26 +01:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-29 02:32:39 +02:00
drop view v1,v2;
# subselect defined by derived table with IN-predicate
select * from t1
where a in
(
select 1
from
(
select *
from t1
where a in (1,2)
)
as dr_table
);
a b
1 2
1 1
select * from t1
where a in
(
select 1
from
(
select *
from t1
where a in
(
select *
from (values (1),(2))
as tvc_0
)
)
as dr_table
);
a b
1 2
1 1
explain extended select * from t1
where a in
(
select 1
from
(
select *
from t1
where a in (1,2)
)
as dr_table
);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2017-11-02 05:42:26 +01:00
2 MATERIALIZED <derived5> ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 02:32:39 +02:00
5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-11-02 05:42:26 +01:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0` join `test`.`t1`) where `test`.`t1`.`a` = 1 and `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-29 02:32:39 +02:00
explain extended select * from t1
where a in
(
select 1
from
(
select *
from t1
where a in
(
select *
from (values (1),(2))
as tvc_0
)
)
as dr_table
);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2017-11-02 05:42:26 +01:00
2 MATERIALIZED <derived5> ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2017-08-29 02:32:39 +02:00
5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-11-02 05:42:26 +01:00
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0` join `test`.`t1`) where `test`.`t1`.`a` = 1 and `test`.`t1`.`a` = `tvc_0`.`1`
2017-08-29 02:32:39 +02:00
# derived table with IN-predicate and group by
select * from
(
select max(a),b
from t1
where b in (3,5)
group by b
) as dr_table;
max(a) b
2 5
select * from
(
select max(a),b
from t1
where b in
(
select *
from (values (3),(5))
as tvc_0
)
group by b
) as dr_table;
max(a) b
2 5
explain extended select * from
(
select max(a),b
from t1
where b in (3,5)
group by b
) as dr_table;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 100.00
2 DERIVED t1 ALL NULL NULL NULL NULL 6 100.00 Using temporary; Using filesort
2017-08-29 21:03:15 +02:00
2 DERIVED <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
2017-08-29 02:32:39 +02:00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-08-29 21:03:15 +02:00
Note 1003 /* select#1 */ select `dr_table`.`max(a)` AS `max(a)`,`dr_table`.`b` AS `b` from (/* select#2 */ select max(`test`.`t1`.`a`) AS `max(a)`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(5)) `tvc_0`) where 1 group by `test`.`t1`.`b`) `dr_table`
2017-08-29 02:32:39 +02:00
explain extended select * from
(
select max(a),b
from t1
where b in
(
select *
from (values (3),(5))
as tvc_0
)
group by b
) as dr_table;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 100.00
2 DERIVED t1 ALL NULL NULL NULL NULL 6 100.00 Using temporary; Using filesort
2017-08-29 21:03:15 +02:00
2 DERIVED <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
2017-08-29 02:32:39 +02:00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2017-08-29 21:03:15 +02:00
Note 1003 /* select#1 */ select `dr_table`.`max(a)` AS `max(a)`,`dr_table`.`b` AS `b` from (/* select#2 */ select max(`test`.`t1`.`a`) AS `max(a)`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(5)) `tvc_0`) where 1 group by `test`.`t1`.`b`) `dr_table`
2017-09-01 19:01:06 +02:00
# prepare statement
prepare stmt from "select * from t1 where a in (1,2)";
execute stmt;
a b
1 2
1 1
2 5
execute stmt;
a b
1 2
1 1
2 5
deallocate prepare stmt;
2017-09-02 23:19:20 +02:00
# use inside out access from tvc rows
set @@in_subquery_conversion_threshold= default;
select * from t3 where a in (1,4,10);
a b
1 abc
1 todd
1 sm
4 yq
10 abc
explain extended select * from t3 where a in (1,4,10);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 range idx idx 5 NULL 5 100.00 Using index condition
Warnings:
Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t3` where `test`.`t3`.`a` in (1,4,10)
set @@in_subquery_conversion_threshold= 2;
select * from t3 where a in (1,4,10);
a b
1 abc
1 todd
1 sm
4 yq
10 abc
explain extended select * from t3 where a in (1,4,10);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t3 ref idx idx 5 tvc_0.1 3 100.00
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 2 100.00
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t3` semi join ((values (1),(4),(10)) `tvc_0`) where `test`.`t3`.`a` = `tvc_0`.`1`
# use vectors in IN predeicate
set @@in_subquery_conversion_threshold= 4;
select * from t1 where (a,b) in ((1,2),(3,4));
a b
1 2
explain extended select * from t1 where (a,b) in ((1,2),(3,4));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 2 100.00
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1,2),(3,4)) `tvc_0`) where `test`.`t1`.`a` = `tvc_0`.`1` and `test`.`t1`.`b` = `tvc_0`.`2`
set @@in_subquery_conversion_threshold= 2;
# trasformation works for the one IN predicate and doesn't work for the other
set @@in_subquery_conversion_threshold= 5;
select * from t2
where (a,b) in ((1,2),(8,9)) and
(a,c) in ((1,3),(8,0),(5,1));
a b c
1 2 3
8 9 0
explain extended select * from t2
where (a,b) in ((1,2),(8,9)) and
(a,c) in ((1,3),(8,0),(5,1));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join)
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 2 100.00
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` semi join ((values (1,3),(8,0),(5,1)) `tvc_0`) where `test`.`t2`.`a` = `tvc_0`.`1` and `test`.`t2`.`c` = `tvc_0`.`3` and (`tvc_0`.`1`,`test`.`t2`.`b`) in (<cache>((1,2)),<cache>((8,9)))
set @@in_subquery_conversion_threshold= 2;
drop table t1, t2, t3;
2017-08-25 19:06:13 +02:00
set @@in_subquery_conversion_threshold= default;