[Commits] 151f4e9: Fixed the bug mdev-12963.

IgorBabaev igor at mariadb.com
Thu Jun 8 02:29:55 EEST 2017


revision-id: 151f4e9b4adea020fbe19b640016845dfa65d820 (mariadb-5.5.56-16-g151f4e9)
parent(s): c258ca2463947fcc3d69bb50a8b5cf6906778508
author: Igor Babaev
committer: Igor Babaev
timestamp: 2017-06-07 16:29:55 -0700
message:

Fixed the bug mdev-12963.

This patch corrects the fix for bug mdev-7599.
When the min/max optimization of the function
opt_sum_query() optimizes away all tables of
a subquery it should not ever be rolled back.

---
 mysql-test/r/subselect_mat_cost_bugs.result | 17 +++++++++++++++++
 mysql-test/t/subselect_mat_cost_bugs.test   | 16 ++++++++++++++++
 sql/sql_select.cc                           |  1 +
 3 files changed, 34 insertions(+)

diff --git a/mysql-test/r/subselect_mat_cost_bugs.result b/mysql-test/r/subselect_mat_cost_bugs.result
index dba4d04..57b0526 100644
--- a/mysql-test/r/subselect_mat_cost_bugs.result
+++ b/mysql-test/r/subselect_mat_cost_bugs.result
@@ -485,3 +485,20 @@ FROM t2 AS t2a INNER JOIN t2 t2b INNER JOIN t3
 ON (f3 = t2b.f2) );
 f1
 DROP TABLE t1,t2,t3;
+#
+# MDEV-12963: min/max optimization optimizing away all tables employed
+#             for uncorrelated IN subquery used in a disjunct of WHERE
+#
+create table t1 (a int, index idx(a)) engine=myisam;
+insert into t1 values (4),(7),(1),(3),(9);
+select * from t1 where a in (select max(a) from t1 where a < 4) or a > 5;
+a
+3
+7
+9
+explain
+select * from t1 where a in (select max(a) from t1 where a < 4) or a > 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	index	idx	idx	5	NULL	5	Using where; Using index
+2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+drop table t1;
diff --git a/mysql-test/t/subselect_mat_cost_bugs.test b/mysql-test/t/subselect_mat_cost_bugs.test
index 9e3ac60..35f2b95 100644
--- a/mysql-test/t/subselect_mat_cost_bugs.test
+++ b/mysql-test/t/subselect_mat_cost_bugs.test
@@ -507,3 +507,19 @@ SELECT * FROM t1
                   ON (f3 = t2b.f2) );
 
 DROP TABLE t1,t2,t3;
+
+--echo #
+--echo # MDEV-12963: min/max optimization optimizing away all tables employed
+--echo #             for uncorrelated IN subquery used in a disjunct of WHERE
+--echo #
+
+create table t1 (a int, index idx(a)) engine=myisam;
+insert into t1 values (4),(7),(1),(3),(9);
+
+select * from t1 where a in (select max(a) from t1 where a < 4) or a > 5;
+explain
+select * from t1 where a in (select max(a) from t1 where a < 4) or a > 5;
+
+drop table t1;
+
+
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 86ba034..f2be17f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1195,6 +1195,7 @@ JOIN::optimize()
       DBUG_PRINT("info",("Select tables optimized away"));
       zero_result_cause= "Select tables optimized away";
       tables_list= 0;				// All tables resolved
+      select_lex->min_max_opt_list.empty();
       const_tables= top_join_tab_count= table_count;
       /*
         Extract all table-independent conditions and replace the WHERE


More information about the commits mailing list