summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/explain_non_select.result20
-rw-r--r--mysql-test/t/explain_non_select.test19
-rw-r--r--sql/sql_delete.cc22
-rw-r--r--sql/sql_explain.cc6
-rw-r--r--sql/sql_explain.h1
-rw-r--r--sql/sql_lex.h9
-rw-r--r--sql/sql_update.cc5
7 files changed, 73 insertions, 9 deletions
diff --git a/mysql-test/r/explain_non_select.result b/mysql-test/r/explain_non_select.result
index 36e8197febe..3cc4d4f1e26 100644
--- a/mysql-test/r/explain_non_select.result
+++ b/mysql-test/r/explain_non_select.result
@@ -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;
diff --git a/mysql-test/t/explain_non_select.test b/mysql-test/t/explain_non_select.test
index 4da4b894d69..3c4c2d0739d 100644
--- a/mysql-test/t/explain_non_select.test
+++ b/mysql-test/t/explain_non_select.test
@@ -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;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 518bdc6ab43..a84d6795603 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -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);
}
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index 0623ef0be8e..28774ef2e99 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -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);
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index 66e8b1be109..87ae29678e9 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -460,6 +460,7 @@ public:
bool used_partitions_set;
bool impossible_where;
+ bool no_partitions;
StringBuffer<64> table_name;
enum join_type jtype;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 62d44f622ae..99a5b2d8ae3 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -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)
+ {}
};
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index cf6cc46e11c..81e0f6c0ebe 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -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);
}