Skip to content

Commit

Permalink
MDEV-406: ANALYZE $stmt: more testcases, fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrunia committed Jun 25, 2014
1 parent 424d5de commit 3da81ab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mysql-test/r/analyze_stmt.result
Original file line number Diff line number Diff line change
Expand Up @@ -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 <derived2> 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;
20 changes: 20 additions & 0 deletions mysql-test/t/analyze_stmt.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3da81ab

Please sign in to comment.