From d2bf101cbfae40b8719edee9f2bc74a3f0a0ca07 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 13 Nov 2017 09:41:29 +0100 Subject: [PATCH] MDEV-13723: Server crashes in ha_heap::find_unique_row or Assertion `0' failed in st_select_lex_unit::optimize with INTERSECT With INTERSECT/EXCEPT fact that subquery item of IN/ALL/ANY was not assigned value does not mean that temporary table used for calculating unit is empty (records could be deleted). --- mysql-test/r/except.result | 10 ++++++++++ mysql-test/r/intersect.result | 1 + mysql-test/t/except.test | 14 ++++++++++++++ mysql-test/t/intersect.test | 1 + sql/sql_union.cc | 10 +++++----- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/except.result b/mysql-test/r/except.result index fdaa625ea6532..594bb7118ebed 100644 --- a/mysql-test/r/except.result +++ b/mysql-test/r/except.result @@ -525,3 +525,13 @@ t3 CREATE TABLE `t3` ( `b1` blob DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop tables t1,t2,t3; +# +# MDEV-13723: Server crashes in ha_heap::find_unique_row or +# Assertion `0' failed in st_select_lex_unit::optimize with INTERSECT +# +CREATE TABLE t (i INT); +INSERT INTO t VALUES (1),(2); +SELECT * FROM t WHERE i != ANY ( SELECT 3 EXCEPT SELECT 3 ); +i +drop table t; +# End of 10.3 tests diff --git a/mysql-test/r/intersect.result b/mysql-test/r/intersect.result index 5dfb7fb687584..7a0301a23e64d 100644 --- a/mysql-test/r/intersect.result +++ b/mysql-test/r/intersect.result @@ -689,3 +689,4 @@ 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; +# End of 10.3 tests diff --git a/mysql-test/t/except.test b/mysql-test/t/except.test index e13137701a993..f88d9b29e35ff 100644 --- a/mysql-test/t/except.test +++ b/mysql-test/t/except.test @@ -81,3 +81,17 @@ create table t3 (select a,b,b1 from t1) except (select c,d,d1 from t2); show create table t3; drop tables t1,t2,t3; + +--echo # +--echo # MDEV-13723: Server crashes in ha_heap::find_unique_row or +--echo # Assertion `0' failed in st_select_lex_unit::optimize with INTERSECT +--echo # +CREATE TABLE t (i INT); +INSERT INTO t VALUES (1),(2); + +SELECT * FROM t WHERE i != ANY ( SELECT 3 EXCEPT SELECT 3 ); + +drop table t; + + +--echo # End of 10.3 tests diff --git a/mysql-test/t/intersect.test b/mysql-test/t/intersect.test index 6028b2fa498bb..99a5460629166 100644 --- a/mysql-test/t/intersect.test +++ b/mysql-test/t/intersect.test @@ -190,3 +190,4 @@ show create view v1; drop view v1; drop tables t1,t2,t3; +--echo # End of 10.3 tests diff --git a/sql/sql_union.cc b/sql/sql_union.cc index b978241608cb0..7a38c8260ec77 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1299,11 +1299,11 @@ bool st_select_lex_unit::optimize() { item->assigned(0); // We will reinit & rexecute unit item->reset(); - if (table->is_created()) - { - table->file->ha_delete_all_rows(); - table->file->info(HA_STATUS_VARIABLE); - } + } + if (table->is_created()) + { + table->file->ha_delete_all_rows(); + table->file->info(HA_STATUS_VARIABLE); } /* re-enabling indexes for next subselect iteration */ if (union_distinct && table->file->ha_enable_indexes(HA_KEY_SWITCH_ALL))