diff --git a/mysql-test/r/intersect.result b/mysql-test/r/intersect.result index 7a0301a23e6..05adaf160ed 100644 --- a/mysql-test/r/intersect.result +++ b/mysql-test/r/intersect.result @@ -689,4 +689,17 @@ View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (select 4 AS `4`,4 AS `4`) latin1 latin1_swedish_ci drop view v1; drop tables t1,t2,t3; +# +# MDEV-14346:incorrect result of intersect with ANY/ALL/IN subquery +# +CREATE TABLE t (i INT); +INSERT INTO t VALUES (1),(2); +SELECT * FROM t WHERE i != ANY ( SELECT 6 INTERSECT SELECT 3 ); +i +select i from t where +exists ((select 6 as r from dual having t.i <> 6) +intersect +(select 3 from dual having t.i <> 3)); +i +drop table t; # End of 10.3 tests diff --git a/mysql-test/t/intersect.test b/mysql-test/t/intersect.test index 99a54606291..98b6d1eb1c6 100644 --- a/mysql-test/t/intersect.test +++ b/mysql-test/t/intersect.test @@ -190,4 +190,19 @@ show create view v1; drop view v1; drop tables t1,t2,t3; +--echo # +--echo # MDEV-14346:incorrect result of intersect with ANY/ALL/IN subquery +--echo # +CREATE TABLE t (i INT); +INSERT INTO t VALUES (1),(2); +SELECT * FROM t WHERE i != ANY ( SELECT 6 INTERSECT SELECT 3 ); + +select i from t where + exists ((select 6 as r from dual having t.i <> 6) + intersect + (select 3 from dual having t.i <> 3)); + +drop table t; + + --echo # End of 10.3 tests diff --git a/sql/sql_class.h b/sql/sql_class.h index 71be5ad042e..8e99d57d0b4 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -5103,10 +5103,11 @@ public: select_unit(THD *thd_arg): select_result_interceptor(thd_arg), - curr_step(0), prev_step(0), curr_sel(UINT_MAX), - step(UNION_TYPE), intersect_mark(0), write_err(0), table(0), - records(0) - { tmp_table_param.init(); } + intersect_mark(0), table(0) + { + init(); + tmp_table_param.init(); + } int prepare(List &list, SELECT_LEX_UNIT *u); /** Do prepare() and prepare2() if they have been postponed until @@ -5130,6 +5131,14 @@ public: bool keep_row_order, uint hidden); TMP_TABLE_PARAM *get_tmp_table_param() { return &tmp_table_param; } + void init() + { + curr_step= prev_step= 0; + curr_sel= UINT_MAX; + step= UNION_TYPE; + write_err= 0; + records= 0; + } void change_select(); }; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 7a38c8260ec..6f8d7a0b67d 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1384,6 +1384,9 @@ bool st_select_lex_unit::exec() if (saved_error) DBUG_RETURN(saved_error); + if (union_result) + union_result->init(); + if (uncacheable || !item || !item->assigned() || describe) { if (!fake_select_lex && !(with_element && with_element->is_recursive))