Commit 3310076d authored by Galina Shalygina's avatar Galina Shalygina

Optimization that transforms IN-predicate in IN-subselect made.

Trasformation goes that way:
a in (1,2) ->
a in (select * from (values ((1),(2))) as new_tvc)

Special variable that controlls optimization added.
Now optimization works only in several cases.
New tests added.

Old tests corrected. Now with TVC explain can be used. TVC also can be used in recursive CTEs.
parent 9103ee3c
This diff is collapsed.
create table t1 (a int, b int);
insert into t1
values (1,2), (4,6), (9,7),
(1,1), (2,5), (7,8);
create table t2 (a int, b int, c int);
insert into t2
values (1,2,3), (5,1,2), (4,3,7),
(8,9,0), (10,7,1), (5,5,1);
--echo # optimization is not used
let $query= select * from t1 where a in (1,2);
eval $query;
eval explain $query;
eval explain format=json $query;
--echo # set minimum number of values in VALUEs list when optimization works to 2
set @@in_subquery_conversion_threshold= 2;
--echo # single IN-predicate in WHERE-part
let $query= select * from t1 where a in (1,2);
let $optimized_query=
select * from t1
where a in
(
select *
from (values (1),(2)) as new_tvc
);
eval $query;
eval $optimized_query;
eval explain $query;
eval explain $optimized_query;
eval explain format=json $query;
--echo # AND-condition with IN-predicates in WHERE-part
let $query=
select * from t1
where a in (1,2) and
b in (1,5);
let $optimized_query=
select * from t1
where a in
(
select *
from (values (1),(2)) as new_tvc
)
and b in
(
select *
from (values (1),(5)) as new_tvc
);
eval $query;
eval $optimized_query;
eval explain $query;
eval explain $optimized_query;
eval explain format=json $query;
--echo # OR-condition with IN-predicates in WHERE-part
let $query=
select * from t1
where a in (1,2) or
b in (4,5);
let $optimized_query=
select * from t1
where a in
(
select *
from (values (1),(2)) as new_tvc
)
or b in
(
select *
from (values (4),(5)) as new_tvc
);
eval $query;
eval $optimized_query;
eval explain $query;
eval explain $optimized_query;
eval explain format=json $query;
--echo # subquery with IN-predicate
let $query=
select * from t1
where a in
(
select a
from t2 where b in (3,4)
)
;
let $optimized_query=
select * from t1
where a in (
select a from t2
where b in
(
select *
from (values (3),(4)) as new_tvc)
)
;
eval $query;
eval $optimized_query;
eval explain $query;
eval explain $optimized_query;
eval explain format=json $query;
drop table t1;
set @@in_subquery_conversion_threshold= default;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment