summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2017-05-29 00:27:14 -0700
committerIgor Babaev <igor@askmonty.org>2017-05-29 00:27:14 -0700
commitaf4421e82d3d458ea8f19cda6376503be6c49143 (patch)
tree7048ccae979d06d6f4bf61717b856ba4d776bf1f
parente4d10e09cf318aad237143254c45458d16009f70 (diff)
downloadmariadb-git-af4421e82d3d458ea8f19cda6376503be6c49143.tar.gz
Fixed the bug mdev-12931.mariadb-10.1.24
This corrects the patch for mdev-10006. The current code supports only those semi-join nests that are placed at the join top level. So such nests cannot depend on other tables or nests.
-rw-r--r--mysql-test/r/subselect_innodb.result39
-rw-r--r--mysql-test/t/subselect_innodb.test35
-rw-r--r--sql/sql_select.cc3
3 files changed, 76 insertions, 1 deletions
diff --git a/mysql-test/r/subselect_innodb.result b/mysql-test/r/subselect_innodb.result
index 01257c33361..240a6ab47e4 100644
--- a/mysql-test/r/subselect_innodb.result
+++ b/mysql-test/r/subselect_innodb.result
@@ -576,3 +576,42 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL #
2 DEPENDENT SUBQUERY t2 ref key1 key1 5 test.t1.a # Using where; Using filesort
drop table t1,t2;
+#
+# mdev-12931: semi-join in ON expression of STRAIGHT_JOIN
+# joining a base table and a mergeable derived table
+#
+CREATE TABLE t1 (f1 int) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (3),(2);
+CREATE TABLE t2 (f2 int) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1),(4);
+CREATE TABLE t3 (f3 int) ENGINE=InnoDB;
+INSERT INTO t3 VALUES (5),(6);
+CREATE TABLE t4 (f4 int) ENGINE=InnoDB;
+INSERT INTO t4 VALUES (1),(8);
+SELECT *
+FROM t1
+INNER JOIN
+( t2 STRAIGHT_JOIN ( SELECT * FROM t3 ) AS sq
+ON ( 1 IN ( SELECT f4 FROM t4 ) ) )
+ON ( f1 >= f2 );
+f1 f2 f3
+3 1 5
+2 1 5
+3 1 6
+2 1 6
+EXPLAIN EXTENDED
+SELECT *
+FROM t1
+INNER JOIN
+( t2 STRAIGHT_JOIN ( SELECT * FROM t3 ) AS sq
+ON ( 1 IN ( SELECT f4 FROM t4 ) ) )
+ON ( f1 >= f2 );
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join)
+3 MATERIALIZED t4 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` semi join (`test`.`t4`) join `test`.`t3` where ((`test`.`t4`.`f4` = 1) and (`test`.`t1`.`f1` >= `test`.`t2`.`f2`))
+DROP TABLE t1,t2,t3,t4;
diff --git a/mysql-test/t/subselect_innodb.test b/mysql-test/t/subselect_innodb.test
index 2451bc60fee..544bcd994ed 100644
--- a/mysql-test/t/subselect_innodb.test
+++ b/mysql-test/t/subselect_innodb.test
@@ -576,3 +576,38 @@ from
t1;
drop table t1,t2;
+
+--echo #
+--echo # mdev-12931: semi-join in ON expression of STRAIGHT_JOIN
+--echo # joining a base table and a mergeable derived table
+--echo #
+
+CREATE TABLE t1 (f1 int) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (3),(2);
+
+CREATE TABLE t2 (f2 int) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1),(4);
+
+CREATE TABLE t3 (f3 int) ENGINE=InnoDB;
+INSERT INTO t3 VALUES (5),(6);
+
+CREATE TABLE t4 (f4 int) ENGINE=InnoDB;
+INSERT INTO t4 VALUES (1),(8);
+
+SELECT *
+FROM t1
+ INNER JOIN
+ ( t2 STRAIGHT_JOIN ( SELECT * FROM t3 ) AS sq
+ ON ( 1 IN ( SELECT f4 FROM t4 ) ) )
+ ON ( f1 >= f2 );
+
+EXPLAIN EXTENDED
+SELECT *
+FROM t1
+ INNER JOIN
+ ( t2 STRAIGHT_JOIN ( SELECT * FROM t3 ) AS sq
+ ON ( 1 IN ( SELECT f4 FROM t4 ) ) )
+ ON ( f1 >= f2 );
+
+DROP TABLE t1,t2,t3,t4;
+
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 559473b8c19..50f121ce47f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -14493,7 +14493,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
table->table->maybe_null= FALSE;
table->outer_join= 0;
if (!(straight_join || table->straight))
- table->dep_tables= table->embedding? table->embedding->dep_tables: 0;
+ table->dep_tables= table->embedding && !table->embedding->sj_subq_pred ?
+ table->embedding->dep_tables : 0;
if (table->on_expr)
{
/* Add ON expression to the WHERE or upper-level ON condition. */