summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorunknown <igor@olga.mysql.com>2007-06-02 11:44:16 -0700
committerunknown <igor@olga.mysql.com>2007-06-02 11:44:16 -0700
commitb7ce84adbbf7e2bb8f3deb83a8756cb815f747cc (patch)
tree605399328eb1eb328e136029e1025a67fc4159a3 /sql/sql_select.cc
parent211cac244ed87fe799362a47783db82e49de5c0b (diff)
downloadmariadb-git-b7ce84adbbf7e2bb8f3deb83a8756cb815f747cc.tar.gz
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. mysql-test/r/subselect.result: Added a test case for bug #28728. mysql-test/t/subselect.test: Added a test case for bug #28728. sql/sql_select.cc: Fixed bug #28728: a crash when executing EXPLAIN EXTENDED for a query using a derived table over a grouping subselect. 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 accomplished. The fix in JOIN::exec() ensures using existing objects when printing subselects for a derived tables by EXPLAIN EXTENDED.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 78d213a45c4..41688794721 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2075,6 +2075,17 @@ JOIN::exec()
thd->examined_row_count+= curr_join->examined_rows;
DBUG_PRINT("counts", ("thd->examined_row_count: %lu",
(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;
}