diff --git a/mysql-test/r/analyze_stmt.result b/mysql-test/r/analyze_stmt.result index bf005801431..d5a9875f9fe 100644 --- a/mysql-test/r/analyze_stmt.result +++ b/mysql-test/r/analyze_stmt.result @@ -147,3 +147,25 @@ id select_type table type possible_keys key key_len ref rows r_rows filtered r_f 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 100.00 Using where 1 SIMPLE t2 ref key2x key2x 5 test.t1.a 1 0 100.00 40.00 Using where drop table t0,t1,t2; +# +# Check non-merged derived tables +# +create table t0 (a int, b int); +insert into t0 values +(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +update t0 set b=b/3; +analyze select * from (select count(*),max(a),b from t0 group by b) T; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY ALL NULL NULL NULL NULL 10 4 100.00 100.00 +2 DERIVED t0 ALL NULL NULL NULL NULL 10 10 100.00 100.00 Using temporary; Using filesort +drop table t0; +# +# Check ORDER/GROUP BY +# +create table t0 (a int, b int); +insert into t0 values +(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +analyze select count(*),max(a),b from t0 where a<7 group by b; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 70.00 Using where; Using temporary; Using filesort +drop table t0; diff --git a/mysql-test/t/analyze_stmt.test b/mysql-test/t/analyze_stmt.test index 9320f6f81a4..de1a3a812f5 100644 --- a/mysql-test/t/analyze_stmt.test +++ b/mysql-test/t/analyze_stmt.test @@ -107,3 +107,23 @@ analyze select * from t1,t2 where t2.key2x=t1.a and mod(t2.col1,4)=0; drop table t0,t1,t2; +--echo # +--echo # Check non-merged derived tables +--echo # +create table t0 (a int, b int); +insert into t0 values + (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); + +update t0 set b=b/3; +analyze select * from (select count(*),max(a),b from t0 group by b) T; +drop table t0; + +--echo # +--echo # Check ORDER/GROUP BY +--echo # +create table t0 (a int, b int); +insert into t0 values + (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); + +analyze select count(*),max(a),b from t0 where a<7 group by b; +drop table t0; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e5072792156..007f1c2b69b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5283,6 +5283,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) result= save_result; if (!result && !(result= new select_send())) return 1; + delete thd->protocol; thd->protocol= save_protocol; thd->lex->explain->send_explain(thd);