summaryrefslogtreecommitdiff
path: root/sql/sql_lex.cc
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2015-03-25 18:27:10 +0100
committerOleksandr Byelkin <sanja@mariadb.com>2015-04-07 13:16:05 +0200
commitded3d706f8a6e615d2a6cfaee016e8917c0800cf (patch)
tree0adb77c0d347b922db91a7db522ad8aa7472cc45 /sql/sql_lex.cc
parent0df8c0aa5ed1a6d3869783a30cbe71521cffa4e4 (diff)
downloadmariadb-git-10.1-MDEV-7811.tar.gz
MDEV-7811: EXPLAIN/ANALYZE FORMAT=JSON should show subquery cache10.1-MDEV-7811
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r--sql/sql_lex.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index c30fcd95d73..a7215053a58 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -3502,6 +3502,8 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only)
bool empty_union_result= true;
bool is_correlated_unit= false;
+ bool first= true;
+ bool union_plan_saved= false;
/*
If the subquery is a UNION, optimize all the subqueries in the UNION. If
there is no UNION, then the loop will execute once for the subquery.
@@ -3509,6 +3511,17 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only)
for (SELECT_LEX *sl= un->first_select(); sl; sl= sl->next_select())
{
JOIN *inner_join= sl->join;
+ if (first)
+ first= false;
+ else
+ {
+ if (!union_plan_saved)
+ {
+ union_plan_saved= true;
+ if (un->save_union_explain(un->thd->lex->explain))
+ return true; /* Failure */
+ }
+ }
if (!inner_join)
continue;
SELECT_LEX *save_select= un->thd->lex->current_select;
@@ -4331,6 +4344,10 @@ void LEX::restore_set_statement_var()
int st_select_lex_unit::save_union_explain(Explain_query *output)
{
SELECT_LEX *first= first_select();
+
+ if (output->get_union(first->select_number))
+ return 0; /* Already added */
+
Explain_union *eu= new (output->mem_root) Explain_union(output->mem_root);
if (derived)