@@ -23827,6 +23827,13 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
23827
23827
(ulong)join->select_lex, join->select_lex->type,
23828
23828
message ? message : "NULL"));
23829
23829
DBUG_ASSERT(have_query_plan == QEP_AVAILABLE);
23830
+ /* fake_select_lex is created/printed by Explain_union */
23831
+ DBUG_ASSERT(join->select_lex != join->unit->fake_select_lex);
23832
+
23833
+ /* There should be no attempts to save query plans for merged selects */
23834
+ DBUG_ASSERT(!join->select_lex->master_unit()->derived ||
23835
+ join->select_lex->master_unit()->derived->is_materialized_derived());
23836
+
23830
23837
/* Don't log this into the slow query log */
23831
23838
23832
23839
if (message)
@@ -23843,12 +23850,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
23843
23850
/* Setting xpl_sel->message means that all other members are invalid */
23844
23851
output->add_node(xpl_sel);
23845
23852
}
23846
- else if (join->select_lex == join->unit->fake_select_lex)
23847
- {
23848
- /* Do nothing, Explain_union will create and print fake_select_lex */
23849
- }
23850
- else if (!join->select_lex->master_unit()->derived ||
23851
- join->select_lex->master_unit()->derived->is_materialized_derived())
23853
+ else
23852
23854
{
23853
23855
Explain_select *xpl_sel;
23854
23856
explain_node= xpl_sel= new (output->mem_root) Explain_select(output->mem_root);
@@ -24013,10 +24015,12 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
24013
24015
}
24014
24016
24015
24017
/*
24016
- Display subqueries only if they are not parts of eliminated WHERE/ON
24017
- clauses.
24018
+ Save plans for child subqueries, when
24019
+ (1) they are not parts of eliminated WHERE/ON clauses.
24020
+ (2) they are not VIEWs that were "merged for INSERT".
24018
24021
*/
24019
- if (!(unit->item && unit->item->eliminated))
24022
+ if (!(unit->item && unit->item->eliminated) && // (1)
24023
+ !(unit->derived && unit->derived->merged_for_insert)) // (2)
24020
24024
{
24021
24025
if (mysql_explain_union(thd, unit, result))
24022
24026
DBUG_VOID_RETURN;
0 commit comments