diff --git a/mysql-test/r/explain_slowquerylog.result b/mysql-test/r/explain_slowquerylog.result index 62c742c5932..9d25cf06275 100644 --- a/mysql-test/r/explain_slowquerylog.result +++ b/mysql-test/r/explain_slowquerylog.result @@ -26,3 +26,16 @@ SELECT 1; EXPLAIN PARTITIONS SELECT 1 ; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +# +# MDEV-5106: Server crashes in Explain_union::print_explain on ER_TOO_BIG_SELECT with explain in slow log +# +CREATE TABLE t1 (i INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES +(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +SET max_join_size = 10; +( SELECT ta.* FROM t1 ta, t1 tb ) UNION ( SELECT * FROM t1 ); +ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay +SELECT 'Server still alive?' as 'Yes'; +Yes +Server still alive? +DROP TABLE t1; diff --git a/mysql-test/t/explain_non_select.test b/mysql-test/t/explain_non_select.test index 7220a00bd2a..316cc1bf8d2 100644 --- a/mysql-test/t/explain_non_select.test +++ b/mysql-test/t/explain_non_select.test @@ -169,4 +169,3 @@ explain insert into t2 values (11, 1+(select max(a+1) from t1)); drop table t1,t2; - diff --git a/mysql-test/t/explain_slowquerylog.test b/mysql-test/t/explain_slowquerylog.test index 23e31166e32..8c8be555640 100644 --- a/mysql-test/t/explain_slowquerylog.test +++ b/mysql-test/t/explain_slowquerylog.test @@ -35,3 +35,15 @@ SELECT 1; EXPLAIN PARTITIONS SELECT 1 ; +--echo # +--echo # MDEV-5106: Server crashes in Explain_union::print_explain on ER_TOO_BIG_SELECT with explain in slow log +--echo # +CREATE TABLE t1 (i INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES +(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +SET max_join_size = 10; +--error ER_TOO_BIG_SELECT +( SELECT ta.* FROM t1 ta, t1 tb ) UNION ( SELECT * FROM t1 ); +SELECT 'Server still alive?' as 'Yes'; + +DROP TABLE t1; diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 91a73cfb7d3..f8d544a52e9 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -157,6 +157,10 @@ bool print_explain_query(LEX *lex, THD *thd, String *str) } +/* + Return tabular EXPLAIN output as a text string +*/ + bool Explain_query::print_explain_str(THD *thd, String *out_str) { List fields; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 72ba3853110..8ffda3190b6 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -630,7 +630,7 @@ bool st_select_lex_unit::exec() saved_error= optimize(); - if (!was_executed && thd->lex->explain) + if (!saved_error && !was_executed && thd->lex->explain) save_union_explain(thd->lex->explain); if (uncacheable || !item || !item->assigned() || describe)