diff --git a/mysql-test/r/show_explain.result b/mysql-test/r/show_explain.result index d4161a6ac06..c6a740353df 100644 --- a/mysql-test/r/show_explain.result +++ b/mysql-test/r/show_explain.result @@ -888,4 +888,42 @@ a+SLEEP(0.01) 0 set debug_dbug=''; drop table t1; +# +# MDEV-298: SHOW EXPLAIN: Plan returned by SHOW EXPLAIN only contains +# 'Using temporary' while the standard EXPLAIN says 'Using temporary; Using filesort' +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9), +(10),(11),(12),(13),(14),(15),(16); +INSERT INTO t1 SELECT t11.a FROM t1 t11, t1 t12, t1 t13; +EXPLAIN SELECT a FROM t1 GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4112 Using temporary; Using filesort +set @show_explain_probe_select_id=1; +set debug_dbug='d,show_explain_probe_join_exec_start'; +SELECT a FROM t1 GROUP BY a; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4112 Using temporary; Using filesort +Warnings: +Note 1003 SELECT a FROM t1 GROUP BY a +a +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +set debug_dbug=''; +drop table t1; drop table t0; diff --git a/mysql-test/t/show_explain.test b/mysql-test/t/show_explain.test index 61d1a9398c4..43c2f617214 100644 --- a/mysql-test/t/show_explain.test +++ b/mysql-test/t/show_explain.test @@ -919,5 +919,33 @@ reap; set debug_dbug=''; drop table t1; + +--echo # +--echo # MDEV-298: SHOW EXPLAIN: Plan returned by SHOW EXPLAIN only contains +--echo # 'Using temporary' while the standard EXPLAIN says 'Using temporary; Using filesort' +--echo # +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9), + (10),(11),(12),(13),(14),(15),(16); +INSERT INTO t1 SELECT t11.a FROM t1 t11, t1 t12, t1 t13; + +EXPLAIN SELECT a FROM t1 GROUP BY a; + +set @show_explain_probe_select_id=1; +set debug_dbug='d,show_explain_probe_join_exec_start'; +--send +SELECT a FROM t1 GROUP BY a; + +connection default; +--source include/wait_condition.inc +evalp show explain for $thr2; + +connection con1; +reap; + +set debug_dbug=''; + +drop table t1; + drop table t0; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index f918439d45a..5ff7705706e 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -4100,7 +4100,8 @@ int st_select_lex::print_explain(select_result_sink *output, { res= join->print_explain(output, explain_flags, TRUE, join->need_tmp, // need_tmp_table - (join->order != 0 && !join->skip_sort_order), // bool need_order + !join->skip_sort_order && !join->no_order && + (join->order || join->group_list), // bool need_order join->select_distinct, // bool distinct NULL); //const char *message }