summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2019-10-07 20:25:55 +0200
committerSergei Golubchik <serg@mariadb.org>2019-10-14 10:29:31 +0200
commit57a09a72a31331c2bcbf57369fc396f0a96cfb09 (patch)
tree15b592c46c466e087f22e68c05b403f6442bb06b
parent721a9df75137bd1a41dc1547d5c615781754aec6 (diff)
downloadmariadb-git-57a09a72a31331c2bcbf57369fc396f0a96cfb09.tar.gz
cleanup st_select_lex_unit::explainable
-rw-r--r--sql/sql_delete.cc14
-rw-r--r--sql/sql_insert.cc14
-rw-r--r--sql/sql_lex.cc4
-rw-r--r--sql/sql_lex.h22
-rw-r--r--sql/sql_select.cc26
-rw-r--r--sql/sql_update.cc1
6 files changed, 18 insertions, 63 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index d0c9167a484..6a58dab9394 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -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,
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index ddbdc45f3d7..e7f746263db 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -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);
}
}
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index f60c396d064..c2ca6c41e21 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -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;
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 1a8d5ececde..ebc66418937 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -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;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index c68ee97c179..6b87f4a3c48 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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;
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 296197524eb..1b589d941b2 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -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;