diff --git a/mysql-test/r/explain_non_select.result b/mysql-test/r/explain_non_select.result index 8e336a0f8c0..5a6b9f841c2 100644 --- a/mysql-test/r/explain_non_select.result +++ b/mysql-test/r/explain_non_select.result @@ -247,3 +247,29 @@ CHECK TABLE t1; Table Op Msg_type Msg_text test.t1 check status OK DROP TABLE t1, t2; +# +# MDEV-8321: Assertion `! is_set()' failed in Diagnostics_area::set_eof_status on EXPLAIN INSERT ... UNION +# +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (b INT); +CREATE TABLE t3 (c INT); +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (3),(4); +INSERT INTO t3 VALUES (5),(6); +EXPLAIN INSERT INTO t1 SELECT * FROM t2 UNION SELECT * FROM t3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +2 UNION t3 ALL NULL NULL NULL NULL 2 +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +drop table t1,t2,t3; +# +# MDEV-6223: Assertion `! is_set()' fails in Diagnostics_area::set_eof_status on EXPLAIN INSERT executed as a PS +# +CREATE TABLE t1 (a INT) ENGINE = MyISAM; +CREATE TABLE t2 (b INT) ENGINE = MyISAM; +INSERT INTO t2 VALUES (1),(2); +PREPARE stmt FROM 'EXPLAIN INSERT INTO t1 SELECT * FROM t2'; +EXECUTE stmt; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 +drop table t1,t2; diff --git a/mysql-test/t/explain_non_select.test b/mysql-test/t/explain_non_select.test index 52996a8c24a..d9ff0fb7245 100644 --- a/mysql-test/t/explain_non_select.test +++ b/mysql-test/t/explain_non_select.test @@ -224,3 +224,29 @@ CHECK TABLE t1; DROP TABLE t1, t2; +--echo # +--echo # MDEV-8321: Assertion `! is_set()' failed in Diagnostics_area::set_eof_status on EXPLAIN INSERT ... UNION +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (b INT); +CREATE TABLE t3 (c INT); + +# Data is not necessary, tables can be empty as well +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (3),(4); +INSERT INTO t3 VALUES (5),(6); + +EXPLAIN INSERT INTO t1 SELECT * FROM t2 UNION SELECT * FROM t3; +drop table t1,t2,t3; + +--echo # +--echo # MDEV-6223: Assertion `! is_set()' fails in Diagnostics_area::set_eof_status on EXPLAIN INSERT executed as a PS +--echo # +CREATE TABLE t1 (a INT) ENGINE = MyISAM; +CREATE TABLE t2 (b INT) ENGINE = MyISAM; +INSERT INTO t2 VALUES (1),(2); +PREPARE stmt FROM 'EXPLAIN INSERT INTO t1 SELECT * FROM t2'; +EXECUTE stmt; +drop table t1,t2; + diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 93e6bdebd53..b2636cfff95 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3533,7 +3533,10 @@ end_with_restore_list: lex->duplicates, lex->ignore))) { - res= handle_select(thd, lex, sel_result, OPTION_SETUP_TABLES_DONE); + if (explain) + res= mysql_explain_union(thd, &thd->lex->unit, sel_result); + else + res= handle_select(thd, lex, sel_result, OPTION_SETUP_TABLES_DONE); /* Invalidate the table in the query cache if something changed after unlocking when changes become visible. diff --git a/sql/sql_union.cc b/sql/sql_union.cc index a316fbad726..71875433c39 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -286,8 +286,6 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, { if (!(tmp_result= union_result= new select_union)) goto err; - if (describe) - tmp_result= sel_result; } else tmp_result= sel_result;