Skip to content
Permalink
Browse files

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.
  • Loading branch information...
igorbabaev committed Jun 7, 2017
1 parent c258ca2 commit 151f4e9b4adea020fbe19b640016845dfa65d820
Showing with 34 additions and 0 deletions.
  1. +17 −0 mysql-test/r/subselect_mat_cost_bugs.result
  2. +16 −0 mysql-test/t/subselect_mat_cost_bugs.test
  3. +1 −0 sql/sql_select.cc
@@ -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;
@@ -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;


@@ -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

0 comments on commit 151f4e9

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