Skip to content

Commit 57a09a7

Browse files
committed
cleanup st_select_lex_unit::explainable
1 parent 721a9df commit 57a09a7

File tree

6 files changed

+18
-63
lines changed

6 files changed

+18
-63
lines changed

sql/sql_delete.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,12 @@ bool Update_plan::save_explain_data_intern(MEM_ROOT *mem_root,
199199
&explain->mrr_type);
200200
}
201201

202-
bool skip= updating_a_view;
203-
204202
/* Save subquery children */
205203
for (SELECT_LEX_UNIT *unit= select_lex->first_inner_unit();
206204
unit;
207205
unit= unit->next_unit())
208206
{
209-
if (skip)
210-
{
211-
skip= false;
212-
continue;
213-
}
214-
/*
215-
Display subqueries only if they are not parts of eliminated WHERE/ON
216-
clauses.
217-
*/
218-
if (!(unit->item && unit->item->eliminated))
207+
if (unit->explainable())
219208
explain->add_child(unit->first_select()->select_number);
220209
}
221210
return 0;
@@ -395,7 +384,6 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
395384
table->map=1;
396385
query_plan.select_lex= thd->lex->first_select_lex();
397386
query_plan.table= table;
398-
query_plan.updating_a_view= MY_TEST(table_list->view);
399387

400388
if (mysql_prepare_delete(thd, table_list, select_lex->with_wild,
401389
select_lex->item_list, &conds,

sql/sql_insert.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -657,24 +657,12 @@ static void save_insert_query_plan(THD* thd, TABLE_LIST *table_list)
657657

658658
thd->lex->explain->add_insert_plan(explain);
659659

660-
/* See Update_plan::updating_a_view for details */
661-
bool skip= MY_TEST(table_list->view);
662-
663660
/* Save subquery children */
664661
for (SELECT_LEX_UNIT *unit= thd->lex->first_select_lex()->first_inner_unit();
665662
unit;
666663
unit= unit->next_unit())
667664
{
668-
if (skip)
669-
{
670-
skip= false;
671-
continue;
672-
}
673-
/*
674-
Table elimination doesn't work for INSERTS, but let's still have this
675-
here for consistency
676-
*/
677-
if (!(unit->item && unit->item->eliminated))
665+
if (unit->explainable())
678666
explain->add_child(unit->first_select()->select_number);
679667
}
680668
}

sql/sql_lex.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5225,10 +5225,8 @@ int st_select_lex_unit::save_union_explain_part2(Explain_query *output)
52255225
for (SELECT_LEX_UNIT *unit= fake_select_lex->first_inner_unit();
52265226
unit; unit= unit->next_unit())
52275227
{
5228-
if (!(unit->item && unit->item->eliminated))
5229-
{
5228+
if (unit->explainable())
52305229
eu->add_child(unit->first_select()->select_number);
5231-
}
52325230
}
52335231
fake_select_lex->join->explain= &eu->fake_select_lex_explain;
52345232
}

sql/sql_lex.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,19 @@ class st_select_lex_unit: public st_select_lex_node {
995995
int save_union_explain_part2(Explain_query *output);
996996
unit_common_op common_op();
997997

998+
bool explainable()
999+
{
1000+
/*
1001+
Save plans for child subqueries, when
1002+
(1) they are not parts of eliminated WHERE/ON clauses.
1003+
(2) they are not merged derived tables
1004+
(3) they are not hanging CTEs (they are needed for execution)
1005+
*/
1006+
return !(item && item->eliminated) &&
1007+
!(derived && !derived->is_materialized_derived()) &&
1008+
!(with_element && (!derived || !derived->derived_result));
1009+
}
1010+
9981011
void reset_distinct();
9991012
void fix_distinct();
10001013

@@ -2942,15 +2955,6 @@ class Update_plan
29422955
bool impossible_where;
29432956
bool no_partitions;
29442957
public:
2945-
/*
2946-
When single-table UPDATE updates a VIEW, that VIEW's select is still
2947-
listed as the first child. When we print EXPLAIN, it looks like a
2948-
subquery.
2949-
In order to get rid of it, updating_a_view=TRUE means that first child
2950-
select should not be shown when printing EXPLAIN.
2951-
*/
2952-
bool updating_a_view;
2953-
29542958
/* Allocate things there */
29552959
MEM_ROOT *mem_root;
29562960

sql/sql_select.cc

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26745,21 +26745,8 @@ int JOIN::save_explain_data_intern(Explain_query *output,
2674526745
tmp_unit;
2674626746
tmp_unit= tmp_unit->next_unit())
2674726747
{
26748-
/*
26749-
Display subqueries only if
26750-
(1) they are not parts of ON clauses that were eliminated by table
26751-
elimination.
26752-
(2) they are not merged derived tables
26753-
(3) they are not hanging CTEs (they are needed for execution)
26754-
*/
26755-
if (!(tmp_unit->item && tmp_unit->item->eliminated) && // (1)
26756-
(!tmp_unit->derived ||
26757-
tmp_unit->derived->is_materialized_derived()) && // (2)
26758-
!(tmp_unit->with_element &&
26759-
(!tmp_unit->derived || !tmp_unit->derived->derived_result))) // (3)
26760-
{
26748+
if (tmp_unit->explainable())
2676126749
explain->add_child(tmp_unit->first_select()->select_number);
26762-
}
2676326750
}
2676426751

2676526752
if (select_lex->is_top_level_node())
@@ -26813,16 +26800,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
2681326800
DBUG_ASSERT(ref == unit->item);
2681426801
}
2681526802

26816-
/*
26817-
Save plans for child subqueries, when
26818-
(1) they are not parts of eliminated WHERE/ON clauses.
26819-
(2) they are not VIEWs that were "merged for INSERT".
26820-
(3) they are not hanging CTEs (they are needed for execution)
26821-
*/
26822-
if (!(unit->item && unit->item->eliminated) && // (1)
26823-
!(unit->derived && unit->derived->merged_for_insert) && // (2)
26824-
!(unit->with_element &&
26825-
(!unit->derived || !unit->derived->derived_result))) // (3)
26803+
if (unit->explainable())
2682626804
{
2682726805
if (mysql_explain_union(thd, unit, result))
2682826806
DBUG_VOID_RETURN;

sql/sql_update.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ int mysql_update(THD *thd,
438438
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "UPDATE");
439439
DBUG_RETURN(1);
440440
}
441-
query_plan.updating_a_view= MY_TEST(table_list->view);
442441

443442
/* Calculate "table->covering_keys" based on the WHERE */
444443
table->covering_keys= table->s->keys_in_use;

0 commit comments

Comments
 (0)