Skip to content
Permalink
Browse files

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.
  • Loading branch information...
igorbabaev committed May 17, 2017
1 parent 7e97163 commit efb9f2617bde1654006a99af625859eb509d5448
Showing with 51 additions and 0 deletions.
  1. +21 −0 mysql-test/r/derived_view.result
  2. +20 −0 mysql-test/t/derived_view.test
  3. +10 −0 sql/opt_subselect.cc
@@ -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)
drop view v1;
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 join_cache_level=@exit_join_cache_level;
@@ -1911,6 +1911,26 @@ explain select * from v1;
drop view v1;
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
set optimizer_switch=@exit_optimizer_switch;
set join_cache_level=@exit_join_cache_level;
@@ -1161,6 +1161,16 @@ bool convert_join_subqueries_to_semijoins(JOIN *join)
in_subq->block_conversion_to_sj();
}
}

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();
/* First, convert child join's subqueries. We proceed bottom-up here */

0 comments on commit efb9f26

Please sign in to comment.
You can’t perform that action at this time.