cleanup st_select_lex_unit::explainable

This commit is contained in:
Sergei Golubchik 2019-10-07 20:25:55 +02:00
parent 721a9df751
commit 57a09a72a3
6 changed files with 18 additions and 63 deletions

View File

@ -199,23 +199,12 @@ bool Update_plan::save_explain_data_intern(MEM_ROOT *mem_root,
&explain->mrr_type);
}
bool skip= updating_a_view;
/* Save subquery children */
for (SELECT_LEX_UNIT *unit= select_lex->first_inner_unit();
unit;
unit= unit->next_unit())
{
if (skip)
{
skip= false;
continue;
}
/*
Display subqueries only if they are not parts of eliminated WHERE/ON
clauses.
*/
if (!(unit->item && unit->item->eliminated))
if (unit->explainable())
explain->add_child(unit->first_select()->select_number);
}
return 0;
@ -395,7 +384,6 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
table->map=1;
query_plan.select_lex= thd->lex->first_select_lex();
query_plan.table= table;
query_plan.updating_a_view= MY_TEST(table_list->view);
if (mysql_prepare_delete(thd, table_list, select_lex->with_wild,
select_lex->item_list, &conds,

View File

@ -657,24 +657,12 @@ static void save_insert_query_plan(THD* thd, TABLE_LIST *table_list)
thd->lex->explain->add_insert_plan(explain);
/* See Update_plan::updating_a_view for details */
bool skip= MY_TEST(table_list->view);
/* Save subquery children */
for (SELECT_LEX_UNIT *unit= thd->lex->first_select_lex()->first_inner_unit();
unit;
unit= unit->next_unit())
{
if (skip)
{
skip= false;
continue;
}
/*
Table elimination doesn't work for INSERTS, but let's still have this
here for consistency
*/
if (!(unit->item && unit->item->eliminated))
if (unit->explainable())
explain->add_child(unit->first_select()->select_number);
}
}

View File

@ -5225,10 +5225,8 @@ int st_select_lex_unit::save_union_explain_part2(Explain_query *output)
for (SELECT_LEX_UNIT *unit= fake_select_lex->first_inner_unit();
unit; unit= unit->next_unit())
{
if (!(unit->item && unit->item->eliminated))
{
if (unit->explainable())
eu->add_child(unit->first_select()->select_number);
}
}
fake_select_lex->join->explain= &eu->fake_select_lex_explain;
}

View File

@ -995,6 +995,19 @@ public:
int save_union_explain_part2(Explain_query *output);
unit_common_op common_op();
bool explainable()
{
/*
Save plans for child subqueries, when
(1) they are not parts of eliminated WHERE/ON clauses.
(2) they are not merged derived tables
(3) they are not hanging CTEs (they are needed for execution)
*/
return !(item && item->eliminated) &&
!(derived && !derived->is_materialized_derived()) &&
!(with_element && (!derived || !derived->derived_result));
}
void reset_distinct();
void fix_distinct();
@ -2942,15 +2955,6 @@ protected:
bool impossible_where;
bool no_partitions;
public:
/*
When single-table UPDATE updates a VIEW, that VIEW's select is still
listed as the first child. When we print EXPLAIN, it looks like a
subquery.
In order to get rid of it, updating_a_view=TRUE means that first child
select should not be shown when printing EXPLAIN.
*/
bool updating_a_view;
/* Allocate things there */
MEM_ROOT *mem_root;

View File

@ -26745,21 +26745,8 @@ int JOIN::save_explain_data_intern(Explain_query *output,
tmp_unit;
tmp_unit= tmp_unit->next_unit())
{
/*
Display subqueries only if
(1) they are not parts of ON clauses that were eliminated by table
elimination.
(2) they are not merged derived tables
(3) they are not hanging CTEs (they are needed for execution)
*/
if (!(tmp_unit->item && tmp_unit->item->eliminated) && // (1)
(!tmp_unit->derived ||
tmp_unit->derived->is_materialized_derived()) && // (2)
!(tmp_unit->with_element &&
(!tmp_unit->derived || !tmp_unit->derived->derived_result))) // (3)
{
if (tmp_unit->explainable())
explain->add_child(tmp_unit->first_select()->select_number);
}
}
if (select_lex->is_top_level_node())
@ -26813,16 +26800,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
DBUG_ASSERT(ref == unit->item);
}
/*
Save plans for child subqueries, when
(1) they are not parts of eliminated WHERE/ON clauses.
(2) they are not VIEWs that were "merged for INSERT".
(3) they are not hanging CTEs (they are needed for execution)
*/
if (!(unit->item && unit->item->eliminated) && // (1)
!(unit->derived && unit->derived->merged_for_insert) && // (2)
!(unit->with_element &&
(!unit->derived || !unit->derived->derived_result))) // (3)
if (unit->explainable())
{
if (mysql_explain_union(thd, unit, result))
DBUG_VOID_RETURN;

View File

@ -438,7 +438,6 @@ int mysql_update(THD *thd,
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "UPDATE");
DBUG_RETURN(1);
}
query_plan.updating_a_view= MY_TEST(table_list->view);
/* Calculate "table->covering_keys" based on the WHERE */
table->covering_keys= table->s->keys_in_use;