summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
authorunknown <gkodinov/kgeorge@magare.gmz>2007-05-04 10:48:51 +0300
committerunknown <gkodinov/kgeorge@magare.gmz>2007-05-04 10:48:51 +0300
commit0ad4e1b2a6f4919afbfc43a7cd71e828e3aeb74a (patch)
tree063e8080c776ed341a337770fb33a4588175b108 /sql/item_subselect.cc
parent5a35befff53cfde52bc5b19561504144aa2af2e7 (diff)
downloadmariadb-git-0ad4e1b2a6f4919afbfc43a7cd71e828e3aeb74a.tar.gz
Bug #27807.
Non-correlated scalar subqueries may get executed in EXPLAIN at the optimization phase if they are part of a right hand sargable expression. If the scalar subquery uses a temp table to materialize its results it will replace the subquery structure from the parser with a simple select from the materialization table. As a result the EXPLAIN will crash as the temporary materialization table is not to be shown in EXPLAIN at all. Fixed by preserving the original query structure right after calling optimize() for scalar subqueries with temp tables executed during EXPLAIN. mysql-test/r/subselect.result: Bug #27807: test case mysql-test/t/subselect.test: Bug #27807: test case sql/item_subselect.cc: Bug #27807: preserve the join structure sql/sql_select.cc: Bug #27807: introduce initialization function for tmp_join sql/sql_select.h: Bug #27807: introduce initialization function for tmp_join
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index b3744d6eb96..a4d07e08473 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1774,6 +1774,21 @@ int subselect_single_select_engine::exec()
thd->lex->current_select= save_select;
DBUG_RETURN(join->error ? join->error : 1);
}
+ if (!select_lex->uncacheable && thd->lex->describe &&
+ !(join->select_options & SELECT_DESCRIBE) &&
+ join->need_tmp && item->const_item())
+ {
+ /*
+ Force join->join_tmp creation, because this subquery will be replaced
+ by a simple select from the materialization temp table by optimize()
+ called by EXPLAIN and we need to preserve the initial query structure
+ so we can display it.
+ */
+ select_lex->uncacheable|= UNCACHEABLE_EXPLAIN;
+ select_lex->master_unit()->uncacheable|= UNCACHEABLE_EXPLAIN;
+ if (join->init_save_join_tab())
+ DBUG_RETURN(1);
+ }
if (item->engine_changed)
{
DBUG_RETURN(1);