MDEV-3798: EXPLAIN UPDATE/DELETE

- Handle the case when EXPLAIN UPDATE/DELETE has pruned away all partitions.
This commit is contained in:
Sergey Petrunya 2013-10-05 13:44:01 +04:00
commit abcf14e595
7 changed files with 73 additions and 9 deletions

View file

@ -83,14 +83,22 @@ void Update_plan::save_explain_data_intern(Explain_query *query,
{
explain->select_type= "SIMPLE";
explain->table_name.append(table->pos_in_table_list->alias);
explain->impossible_where= false;
explain->no_partitions= false;
if (impossible_where)
{
explain->impossible_where= true;
return;
}
explain->impossible_where= false;
if (no_partitions)
{
explain->no_partitions= true;
return;
}
select_lex->set_explain_type(TRUE);
explain->select_type= select_lex->type;
/* Partitions */
@ -139,7 +147,8 @@ void Update_plan::save_explain_data_intern(Explain_query *query,
/* Calculate key_len */
if (select && select->quick)
{
select->quick->add_keys_and_lengths(&explain->key_str, &explain->key_len_str);
select->quick->add_keys_and_lengths(&explain->key_str,
&explain->key_len_str);
}
else
{
@ -356,8 +365,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (prune_partitions(thd, table, conds))
{
free_underlaid_joins(thd, select_lex);
// No matching record
//psergey-explain-todo: No-partitions used EXPLAIN here..
query_plan.set_no_partitions();
if (thd->lex->describe)
goto exit_without_my_ok;
my_ok(thd, 0);
DBUG_RETURN(0);
}

View file

@ -766,9 +766,11 @@ int Explain_update::print_explain(Explain_query *query,
uint8 explain_flags)
{
StringBuffer<64> extra_str;
if (impossible_where)
if (impossible_where || no_partitions)
{
const char *msg= "Impossible where";
const char *msg= impossible_where ?
"Impossible where" :
"No matching rows after partition pruning";
int res= print_explain_message_line(output, explain_flags,
1 /*select number*/,
select_type, msg);

View file

@ -460,6 +460,7 @@ public:
bool used_partitions_set;
bool impossible_where;
bool no_partitions;
StringBuffer<64> table_name;
enum join_type jtype;

View file

@ -2380,8 +2380,10 @@ class Update_plan
{
protected:
bool impossible_where;
bool no_partitions;
public:
bool updating_a_view;
TABLE *table;
SQL_SELECT *select;
uint index;
@ -2395,14 +2397,17 @@ public:
key_map possible_keys;
bool using_filesort;
/* Set this plan to be a plan to do nothing because of impossible WHRE*/
/* Set this plan to be a plan to do nothing because of impossible WHERE */
void set_impossible_where() { impossible_where= true; }
void set_no_partitions() { no_partitions= true; }
void save_explain_data(Explain_query *query);
void save_explain_data_intern(Explain_query *query, Explain_update *eu);
virtual ~Update_plan() {}
Update_plan() : impossible_where(false), using_filesort(false) {}
Update_plan() :
impossible_where(false), no_partitions(false), using_filesort(false)
{}
};

View file

@ -403,6 +403,11 @@ int mysql_update(THD *thd,
if (prune_partitions(thd, table, conds))
{
free_underlaid_joins(thd, select_lex);
query_plan.set_no_partitions();
if (thd->lex->describe)
goto exit_without_my_ok;
my_ok(thd); // No matching records
DBUG_RETURN(0);
}