From: Date: May 16 2008 3:28pm Subject: bk commit into 5.0 tree (gkodinov:1.2626) BUG#36011 List-Archive: http://lists.mysql.com/commits/46770 X-Bug: 36011 Message-Id: <200805161328.m4GDSPvh007649@magare.gmz> Below is the list of changes that have just been committed into a local 5.0 repository of gkodinov. When gkodinov does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2008-05-16 16:28:22+03:00, gkodinov@stripped +3 -0 Bug #36011: server crash with explain extended on query with dependent subqueries An IN subquery is executed on EXPLAIN when it's not correlated. But if the subquery contained a derived table the internal structures were not restored. Fixed by restoring the ref array when a temp tables were used in executing the IN subquery. mysql-test/r/subselect.result@stripped, 2008-05-16 16:28:21+03:00, gkodinov@stripped +9 -0 Bug #36011: test case mysql-test/t/subselect.test@stripped, 2008-05-16 16:28:21+03:00, gkodinov@stripped +10 -0 Bug #36011: test case sql/sql_select.cc@stripped, 2008-05-16 16:28:21+03:00, gkodinov@stripped +5 -4 Bug #36011: restore the ref array after execution when there were temp tables. diff -Nrup a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result --- a/mysql-test/r/subselect.result 2008-04-23 12:20:50 +03:00 +++ b/mysql-test/r/subselect.result 2008-05-16 16:28:21 +03:00 @@ -4381,4 +4381,13 @@ t1.a= (select b from t2 limit 1) and not t1.a= (select a from t2 limit 1) ; a drop table t1, t2; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 GROUP BY a); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` where (1,(select 1 AS `1` from `test`.`t1` group by `test`.`t1`.`a` having ((1) = (1)))) +DROP TABLE t1; End of 5.0 tests. diff -Nrup a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test --- a/mysql-test/t/subselect.test 2008-04-23 12:22:04 +03:00 +++ b/mysql-test/t/subselect.test 2008-05-16 16:28:21 +03:00 @@ -3271,5 +3271,15 @@ select t1.a from t1 where drop table t1, t2; +# +# Bug #36011: Server crash with explain extended on query with dependent +# subqueries +# + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 GROUP BY a); +DROP TABLE t1; + --echo End of 5.0 tests. diff -Nrup a/sql/sql_select.cc b/sql/sql_select.cc --- a/sql/sql_select.cc 2008-04-23 00:23:55 +03:00 +++ b/sql/sql_select.cc 2008-05-16 16:28:21 +03:00 @@ -2104,11 +2104,12 @@ JOIN::exec() /* With EXPLAIN EXTENDED we have to restore original ref_array for a derived table which is always materialized. - Otherwise we would not be able to print the query correctly. + We also need to do this when we have temp table(s). + Otherwise we would not be able to print the query correctly. */ - if (items0 && - (thd->lex->describe & DESCRIBE_EXTENDED) && - select_lex->linkage == DERIVED_TABLE_TYPE) + if (items0 && (thd->lex->describe & DESCRIBE_EXTENDED) && + (select_lex->linkage == DERIVED_TABLE_TYPE || + exec_tmp_table1 || exec_tmp_table2)) set_items_ref_array(items0); DBUG_VOID_RETURN;