Skip to content

Commit 702aee6

Browse files
committed
MDEV-6323: ‘explain_node’ may be used uninitialized in this function
- Remove the compiler warning, add assert statements. - make select_describe() not call mysql_explain_union() for views that were "merged for INSERT".
1 parent da181fe commit 702aee6

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

sql/sql_select.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23827,6 +23827,13 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
2382723827
(ulong)join->select_lex, join->select_lex->type,
2382823828
message ? message : "NULL"));
2382923829
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+
2383023837
/* Don't log this into the slow query log */
2383123838

2383223839
if (message)
@@ -23843,12 +23850,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
2384323850
/* Setting xpl_sel->message means that all other members are invalid */
2384423851
output->add_node(xpl_sel);
2384523852
}
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
2385223854
{
2385323855
Explain_select *xpl_sel;
2385423856
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,
2401324015
}
2401424016

2401524017
/*
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".
2401824021
*/
24019-
if (!(unit->item && unit->item->eliminated))
24022+
if (!(unit->item && unit->item->eliminated) && // (1)
24023+
!(unit->derived && unit->derived->merged_for_insert)) // (2)
2402024024
{
2402124025
if (mysql_explain_union(thd, unit, result))
2402224026
DBUG_VOID_RETURN;

0 commit comments

Comments
 (0)