summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2017-11-10 17:57:26 +0100
committerOleksandr Byelkin <sanja@mariadb.com>2017-11-10 17:57:26 +0100
commita25aa2e47c2d65d733ae622c215ba5e99ba29468 (patch)
tree80dba2c48458ce2643086bd6a5765c96f0e7904d
parent0592d4d88a18bef33176444a07bc7fc1984d3f3c (diff)
downloadmariadb-git-bb-10.2c-MDEV-14346.tar.gz
MDEV-14346: incorrect result of intersect with ANY/ALL/IN subquerybb-10.2c-MDEV-14346
Reinit internal state of select_unit before using to correctly run it after first time.
-rw-r--r--mysql-test/r/intersect.result13
-rw-r--r--mysql-test/t/intersect.test15
-rw-r--r--sql/sql_class.h7
-rw-r--r--sql/sql_union.cc3
4 files changed, 38 insertions, 0 deletions
diff --git a/mysql-test/r/intersect.result b/mysql-test/r/intersect.result
index 7a0301a23e6..dc8b3bb0d13 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..68f366877fb 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 442890f52a9..714ae71fed2 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -5142,6 +5142,13 @@ public:
bool keep_row_order,
uint hidden);
TMP_TABLE_PARAM *get_tmp_table_param() { return &tmp_table_param; }
+ void start_select()
+ {
+ curr_step= prev_step= 0;
+ curr_sel= UINT_MAX;
+ step= UNION_TYPE;
+ records= 0;
+ }
void change_select();
};
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 7a38c8260ec..6c2195bde6a 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->start_select();
+
if (uncacheable || !item || !item->assigned() || describe)
{
if (!fake_select_lex && !(with_element && with_element->is_recursive))