summaryrefslogtreecommitdiff
path: root/sql/sql_lex.cc
diff options
context:
space:
mode:
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)