Fixed the bug mdev-12812.
This is another correction of the patch for bug mdev-12670. If a derived table is merged into a select with STRAIGHT_JOIN modifier all IN subquery predicates contained in the specification of the derived table cannot be subject to conversion to semi-joins.
This commit is contained in:
parent
7e97163102
commit
efb9f2617b
@ -2617,5 +2617,26 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||||||
1 SIMPLE t2 ref idx idx 5 test.t1.a 140 Using index; FirstMatch(t1)
|
1 SIMPLE t2 ref idx idx 5 test.t1.a 140 Using index; FirstMatch(t1)
|
||||||
drop view v1;
|
drop view v1;
|
||||||
drop table t1,t2;
|
drop table t1,t2;
|
||||||
|
#
|
||||||
|
# Bug mdev-12812: mergeable derived / view with subqueries
|
||||||
|
# NOT subject to semi-join optimizations
|
||||||
|
#
|
||||||
|
CREATE TABLE t1 (c1 varchar(3)) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t1 VALUES ('foo'),('foo');
|
||||||
|
CREATE TABLE t2 (c2 varchar(3)) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t2 VALUES ('bar'),('qux'),('foo');
|
||||||
|
SELECT STRAIGHT_JOIN *
|
||||||
|
FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq;
|
||||||
|
c1
|
||||||
|
foo
|
||||||
|
foo
|
||||||
|
EXPLAIN EXTENDED SELECT STRAIGHT_JOIN *
|
||||||
|
FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq;
|
||||||
|
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||||
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||||
|
3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
|
||||||
|
Warnings:
|
||||||
|
Note 1003 select straight_join `test`.`t1`.`c1` AS `c1` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`c1`,<exists>(select `test`.`t2`.`c2` from `test`.`t2` where (<cache>(`test`.`t1`.`c1`) = `test`.`t2`.`c2`)))
|
||||||
|
DROP TABLE t1, t2;
|
||||||
set optimizer_switch=@exit_optimizer_switch;
|
set optimizer_switch=@exit_optimizer_switch;
|
||||||
set join_cache_level=@exit_join_cache_level;
|
set join_cache_level=@exit_join_cache_level;
|
||||||
|
@ -1911,6 +1911,26 @@ explain select * from v1;
|
|||||||
drop view v1;
|
drop view v1;
|
||||||
drop table t1,t2;
|
drop table t1,t2;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # Bug mdev-12812: mergeable derived / view with subqueries
|
||||||
|
--echo # NOT subject to semi-join optimizations
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c1 varchar(3)) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t1 VALUES ('foo'),('foo');
|
||||||
|
|
||||||
|
CREATE TABLE t2 (c2 varchar(3)) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t2 VALUES ('bar'),('qux'),('foo');
|
||||||
|
|
||||||
|
let $q=
|
||||||
|
SELECT STRAIGHT_JOIN *
|
||||||
|
FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq;
|
||||||
|
|
||||||
|
eval $q;
|
||||||
|
eval EXPLAIN EXTENDED $q;
|
||||||
|
|
||||||
|
DROP TABLE t1, t2;
|
||||||
|
|
||||||
# The following command must be the last one the file
|
# The following command must be the last one the file
|
||||||
set optimizer_switch=@exit_optimizer_switch;
|
set optimizer_switch=@exit_optimizer_switch;
|
||||||
set join_cache_level=@exit_join_cache_level;
|
set join_cache_level=@exit_join_cache_level;
|
||||||
|
@ -1162,6 +1162,16 @@ bool convert_join_subqueries_to_semijoins(JOIN *join)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (join->select_options & SELECT_STRAIGHT_JOIN)
|
||||||
|
{
|
||||||
|
/* Block conversion to semijoins for all candidates */
|
||||||
|
li.rewind();
|
||||||
|
while ((in_subq= li++))
|
||||||
|
{
|
||||||
|
in_subq->block_conversion_to_sj();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
li.rewind();
|
li.rewind();
|
||||||
/* First, convert child join's subqueries. We proceed bottom-up here */
|
/* First, convert child join's subqueries. We proceed bottom-up here */
|
||||||
while ((in_subq= li++))
|
while ((in_subq= li++))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user