diff options
author | unknown <gkodinov/kgeorge@magare.gmz> | 2008-05-16 17:05:55 +0300 |
---|---|---|
committer | unknown <gkodinov/kgeorge@magare.gmz> | 2008-05-16 17:05:55 +0300 |
commit | 0fb1527e9556940d30ab14b11742c03510db081d (patch) | |
tree | fa9c710bb7a7cf881050ea378fbd7bf5e1c32e83 | |
parent | 21c07eb7b5f970d10aa2ce961a901ba78358125e (diff) | |
download | mariadb-git-0fb1527e9556940d30ab14b11742c03510db081d.tar.gz |
Bug #36011: server crash with explain extended on query
with dependent subqueries
An IN subquery is executed on EXPLAIN when it's not correlated.
If the subquery required a temporary table for its execution
not all the internal structures were restored from pointing to
the items of the temporary table to point back to the items of
the subquery.
Fixed by restoring the ref array when a temp tables were used in
executing the IN subquery during EXPLAIN EXTENDED.
mysql-test/r/subselect.result:
Bug #36011: test case
mysql-test/t/subselect.test:
Bug #36011: test case
sql/sql_select.cc:
Bug #36011: restore the ref array after execution
when there were temp tables.
-rw-r--r-- | mysql-test/r/subselect.result | 15 | ||||
-rw-r--r-- | mysql-test/t/subselect.test | 11 | ||||
-rw-r--r-- | sql/sql_select.cc | 9 |
3 files changed, 31 insertions, 4 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index e56c2f07d80..12e3aac486e 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -4381,4 +4381,19 @@ 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 <in_optimizer>(1,<exists>(select 1 AS `1` from `test`.`t1` group by `test`.`t1`.`a` having (<cache>(1) = <ref_null_helper>(1)))) +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 AS `1` from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (<cache>(1) = <ref_null_helper>(1)))) +DROP TABLE t1; End of 5.0 tests. diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 527bd528f79..78b4de6e816 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -3271,5 +3271,16 @@ 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); +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a); +DROP TABLE t1; + --echo End of 5.0 tests. diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 11062998e6a..d1e5837329b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -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; |