Commit abcf14e5 authored by Sergey Petrunya's avatar Sergey Petrunya

MDEV-3798: EXPLAIN UPDATE/DELETE

- Handle the case when EXPLAIN UPDATE/DELETE has pruned away all partitions.
parent 72bc6d73
......@@ -161,3 +161,23 @@ explain extended delete from t2 where a in (3,4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
drop table t1,t2;
#
# Check the special case where partition pruning removed all partitions
#
create table t1 (a int, b int)
partition by range (a) (
partition p0 values less than (10),
partition p1 values less than (20),
partition p2 values less than (30)
);
insert into t1 values (9,9), (19,19), (29,29);
explain partitions select * from t1 where a in (32,33);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
explain partitions delete from t1 where a in (32,33);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No matching rows after partition pruning
explain partitions update t1 set b=12345 where a in (32,33);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No matching rows after partition pruning
drop table t1;
......@@ -136,3 +136,22 @@ explain extended delete from t2 where a in (3,4);
drop table t1,t2;
--echo #
--echo # Check the special case where partition pruning removed all partitions
--echo #
create table t1 (a int, b int)
partition by range (a) (
partition p0 values less than (10),
partition p1 values less than (20),
partition p2 values less than (30)
);
insert into t1 values (9,9), (19,19), (29,29);
explain partitions select * from t1 where a in (32,33);
explain partitions delete from t1 where a in (32,33);
explain partitions update t1 set b=12345 where a in (32,33);
drop table t1;
......@@ -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);
}
......
......@@ -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);
......
......@@ -460,6 +460,7 @@ public:
bool used_partitions_set;
bool impossible_where;
bool no_partitions;
StringBuffer<64> table_name;
enum join_type jtype;
......
......@@ -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)
{}
};
......
......@@ -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);
}
......
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