Commit 5cbebf0a authored by igor@olga.mysql.com's avatar igor@olga.mysql.com

Fixed bug #28728: a crash when executing EXPLAIN EXTENDED for a query

using a derived table over a grouping subselect.

This crash happens only when materialization of the derived tables 
requires creation of auxiliary temporary table, for example when
a grouping operation is carried out with usage of a temporary table.

The crash happened because EXPLAIN EXTENDED when printing the query
expression made an attempt to use the objects created in the mem_root
of the temporary table which has been already freed by the moment
when printing is called.

This bug appeared after the method Item_field::print() had been 
introduced.    
parent 5a5410e4
...@@ -4071,4 +4071,14 @@ id st ...@@ -4071,4 +4071,14 @@ id st
2 GA 2 GA
4 FL 4 FL
DROP TABLE t1,t2; DROP TABLE t1,t2;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1), (2);
EXPLAIN EXTENDED
SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
2 DERIVED t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
Warnings:
Note 1003 select `res`.`count(*)` AS `count(*)` from (select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`a`) `res`
DROP TABLE t1;
End of 5.0 tests. End of 5.0 tests.
...@@ -2906,4 +2906,18 @@ SELECT id, st FROM t1 ...@@ -2906,4 +2906,18 @@ SELECT id, st FROM t1
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug #28728: crash with EXPLAIN EXTENDED for a query with a derived table
# over a grouping subselect
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1), (2);
EXPLAIN EXTENDED
SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res;
DROP TABLE t1;
--echo End of 5.0 tests. --echo End of 5.0 tests.
...@@ -2075,6 +2075,17 @@ JOIN::exec() ...@@ -2075,6 +2075,17 @@ JOIN::exec()
thd->examined_row_count+= curr_join->examined_rows; thd->examined_row_count+= curr_join->examined_rows;
DBUG_PRINT("counts", ("thd->examined_row_count: %lu", DBUG_PRINT("counts", ("thd->examined_row_count: %lu",
(ulong) thd->examined_row_count)); (ulong) thd->examined_row_count));
/*
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.
*/
if (items0 &&
(thd->lex->describe & DESCRIBE_EXTENDED) &&
select_lex->linkage == DERIVED_TABLE_TYPE)
set_items_ref_array(items0);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment