Commit a356cfbe authored by Sergey Petrunya's avatar Sergey Petrunya

MDEV-3798: EXPLAIN UPDATE/DELETE

- eliminate join_save_qpf() function.
parent 1ec399ce
...@@ -1002,8 +1002,6 @@ bool JOIN::prepare_stage2() ...@@ -1002,8 +1002,6 @@ bool JOIN::prepare_stage2()
DBUG_RETURN(res); /* purecov: inspected */ DBUG_RETURN(res); /* purecov: inspected */
} }
void join_save_qpf(JOIN *join);
int JOIN::optimize() int JOIN::optimize()
{ {
bool was_optimized= optimized; bool was_optimized= optimized;
...@@ -1023,7 +1021,10 @@ int JOIN::optimize() ...@@ -1023,7 +1021,10 @@ int JOIN::optimize()
if (was_optimized != optimized && !res && have_query_plan != QEP_DELETED) if (was_optimized != optimized && !res && have_query_plan != QEP_DELETED)
{ {
have_query_plan= QEP_AVAILABLE; have_query_plan= QEP_AVAILABLE;
join_save_qpf(this); save_explain_data(thd->lex->explain, false /* can overwrite */,
need_tmp,
!skip_sort_order && !no_order && (order || group_list),
select_distinct);
} }
return res; return res;
} }
...@@ -2295,31 +2296,27 @@ JOIN::save_join_tab() ...@@ -2295,31 +2296,27 @@ JOIN::save_join_tab()
} }
void join_save_qpf(JOIN *join) void JOIN::save_explain_data(Explain_query *output, bool can_overwrite,
bool need_tmp_table, bool need_order,
bool distinct)
{ {
THD *thd= join->thd; if (select_lex->select_number != UINT_MAX &&
if (join->select_lex->select_number != UINT_MAX && select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ &&
join->select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ && have_query_plan != JOIN::QEP_NOT_PRESENT_YET &&
join->have_query_plan != JOIN::QEP_NOT_PRESENT_YET && have_query_plan != JOIN::QEP_DELETED && // this happens when there was
join->have_query_plan != JOIN::QEP_DELETED && // this happens when there was no QEP ever, but then // no QEP ever, but then
//cleanup() is called multiple times //cleanup() is called multiple times
thd->lex->explain && // for "SET" command in SPs. output && // for "SET" command in SPs.
!thd->lex->explain->get_select(join->select_lex->select_number)) (can_overwrite? true: !output->get_select(select_lex->select_number)))
{ {
const char *message= NULL; const char *message= NULL;
if (!table_count || !tables_list || zero_result_cause)
if (!join->table_count || !join->tables_list || join->zero_result_cause)
{ {
/* It's a degenerate join */ /* It's a degenerate join */
message= join->zero_result_cause ? join->zero_result_cause : "No tables used"; message= zero_result_cause ? zero_result_cause : "No tables used";
} }
save_explain_data_intern(thd->lex->explain, need_tmp_table, need_order,
join->save_explain_data(thd->lex->explain, distinct, message);
join->need_tmp,
!join->skip_sort_order && !join->no_order &&
(join->order || join->group_list),
join->select_distinct,
message);
} }
} }
...@@ -2336,26 +2333,10 @@ void JOIN::exec() ...@@ -2336,26 +2333,10 @@ void JOIN::exec()
if (!exec_saved_explain) if (!exec_saved_explain)
{ {
if (select_lex->select_number != UINT_MAX && save_explain_data(thd->lex->explain, true /* can overwrite */,
select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ && need_tmp,
have_query_plan != QEP_NOT_PRESENT_YET && order != 0 && !skip_sort_order,
have_query_plan != QEP_DELETED && // this happens when there was no QEP ever, but then select_distinct);
//cleanup() is called multiple times
thd->lex->explain)// for "SET" command in SPs.
{
const char *message= NULL;
if (!table_count || !tables_list || zero_result_cause)
{
/* It's a degenerate join */
message= zero_result_cause ? zero_result_cause : "No tables used";
}
save_explain_data(thd->lex->explain,
need_tmp,
order != 0 && !skip_sort_order,
select_distinct,
message);
}
exec_saved_explain= true; exec_saved_explain= true;
} }
...@@ -22497,6 +22478,7 @@ void append_possible_keys(String *str, TABLE *table, key_map possible_keys) ...@@ -22497,6 +22478,7 @@ void append_possible_keys(String *str, TABLE *table, key_map possible_keys)
} }
} }
/* /*
Save Query Plan Footprint Save Query Plan Footprint
...@@ -22504,9 +22486,9 @@ void append_possible_keys(String *str, TABLE *table, key_map possible_keys) ...@@ -22504,9 +22486,9 @@ void append_possible_keys(String *str, TABLE *table, key_map possible_keys)
Currently, this function may be called multiple times Currently, this function may be called multiple times
*/ */
int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table, int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
bool need_order, bool distinct, bool need_order, bool distinct,
const char *message) const char *message)
{ {
Explain_node *explain_node; Explain_node *explain_node;
JOIN *join= this; /* Legacy: this code used to be a non-member function */ JOIN *join= this; /* Legacy: this code used to be a non-member function */
...@@ -22514,7 +22496,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table, ...@@ -22514,7 +22496,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
const CHARSET_INFO *cs= system_charset_info; const CHARSET_INFO *cs= system_charset_info;
int quick_type; int quick_type;
int error= 0; int error= 0;
DBUG_ENTER("JOIN::save_explain_data"); DBUG_ENTER("JOIN::save_explain_data_intern");
DBUG_PRINT("info", ("Select 0x%lx, type %s, message %s", DBUG_PRINT("info", ("Select 0x%lx, type %s, message %s",
(ulong)join->select_lex, join->select_lex->type, (ulong)join->select_lex, join->select_lex->type,
message ? message : "NULL")); message ? message : "NULL"));
......
...@@ -1476,8 +1476,11 @@ class JOIN :public Sql_alloc ...@@ -1476,8 +1476,11 @@ class JOIN :public Sql_alloc
{ {
return (unit->item && unit->item->is_in_predicate()); return (unit->item && unit->item->is_in_predicate());
} }
int save_explain_data(Explain_query *output, bool need_tmp_table, void save_explain_data(Explain_query *output, bool can_overwrite,
bool need_order, bool distinct, const char *message); bool need_tmp_table, bool need_order, bool distinct);
int save_explain_data_intern(Explain_query *output, bool need_tmp_table,
bool need_order, bool distinct,
const char *message);
private: private:
/** /**
TRUE if the query contains an aggregate function but has no GROUP TRUE if the query contains an aggregate function but has no GROUP
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment