diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2013-10-04 18:50:47 +0400 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2013-10-04 18:50:47 +0400 |
commit | 5e4044e92c748c69965bd9b22f231815c9fa8e51 (patch) | |
tree | d874a92db35df46b362675503d4d850a82815d85 | |
parent | 6519ca51dd8815dc1f2d88708e540bd4032cb45e (diff) | |
download | mariadb-git-5e4044e92c748c69965bd9b22f231815c9fa8e51.tar.gz |
MDEV-5093, MDEV-5094:
- Make EXPLAIN {PARTITIONS,EXTENDED} {UPDATE,DELETE} work.
-rw-r--r-- | mysql-test/r/explain_non_select.result | 23 | ||||
-rw-r--r-- | mysql-test/t/explain_non_select.test | 21 | ||||
-rw-r--r-- | sql/opt_qpf.cc | 2 | ||||
-rw-r--r-- | sql/opt_qpf.h | 3 | ||||
-rw-r--r-- | sql/sql_delete.cc | 21 | ||||
-rw-r--r-- | sql/sql_select.cc | 17 | ||||
-rw-r--r-- | sql/sql_select.h | 2 |
7 files changed, 81 insertions, 8 deletions
diff --git a/mysql-test/r/explain_non_select.result b/mysql-test/r/explain_non_select.result index 5597e6a876e..36e8197febe 100644 --- a/mysql-test/r/explain_non_select.result +++ b/mysql-test/r/explain_non_select.result @@ -138,3 +138,26 @@ i i 0 0 9 9 DROP TABLE t1; +# +# MDEV-5093, MDEV-5094: EXPLAIN PARTITIONS and EXPLAIN EXTENDED do not +# work for EXPLAIN UPDATE. +# +create table t1 (i int); +explain partitions update t1 set i = 3; +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 0 +create table t2 (a int, b int) partition by hash(a) partitions 5; +insert into t2 values (0,0),(1,1),(2,2),(3,3),(4,4); +explain partitions update t2 set b=3 where a in (3,4); +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 2 Using where +explain partitions delete from t2 where a in (3,4); +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 2 Using where +explain extended update t2 set b=3 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 +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; diff --git a/mysql-test/t/explain_non_select.test b/mysql-test/t/explain_non_select.test index 2ca47ff8025..4da4b894d69 100644 --- a/mysql-test/t/explain_non_select.test +++ b/mysql-test/t/explain_non_select.test @@ -1,6 +1,8 @@ # # MariaDB tests for EXPLAIN UPDATE/DELETE. # +--source include/have_partition.inc + --disable_warnings drop table if exists t0, t1; --enable_warnings @@ -115,3 +117,22 @@ INSERT INTO t1 VALUES (7),(0),(9); SELECT * FROM t1 INNER JOIN ( SELECT DISTINCT * FROM t1 ) AS sq ON (sq.i = t1.i); DROP TABLE t1; + +--echo # +--echo # MDEV-5093, MDEV-5094: EXPLAIN PARTITIONS and EXPLAIN EXTENDED do not +--echo # work for EXPLAIN UPDATE. +--echo # +create table t1 (i int); +explain partitions update t1 set i = 3; + +create table t2 (a int, b int) partition by hash(a) partitions 5; +insert into t2 values (0,0),(1,1),(2,2),(3,3),(4,4); + +explain partitions update t2 set b=3 where a in (3,4); +explain partitions delete from t2 where a in (3,4); + +explain extended update t2 set b=3 where a in (3,4); +explain extended delete from t2 where a in (3,4); + +drop table t1,t2; + diff --git a/sql/opt_qpf.cc b/sql/opt_qpf.cc index 30aca13e446..43c00573c2d 100644 --- a/sql/opt_qpf.cc +++ b/sql/opt_qpf.cc @@ -796,7 +796,7 @@ int QPF_update::print_explain(QPF_query *query, select_result_sink *output, 1, /* id */ select_type, table_name.c_ptr(), - // partitions, + used_partitions_set? used_partitions.c_ptr() : NULL, jtype, possible_keys_line.length()? possible_keys_line.c_ptr(): NULL, key_str.length()? key_str.c_ptr() : NULL, diff --git a/sql/opt_qpf.h b/sql/opt_qpf.h index d5544e22650..d22135dcec0 100644 --- a/sql/opt_qpf.h +++ b/sql/opt_qpf.h @@ -454,6 +454,9 @@ public: const char *select_type; + StringBuffer<32> used_partitions; + bool used_partitions_set; + bool impossible_where; StringBuffer<64> table_name; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 25fe56d2e71..adc998be3a1 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -40,7 +40,7 @@ #include "records.h" // init_read_record, #include "sql_derived.h" // mysql_handle_list_of_derived // end_read_record - +#include "sql_partition.h" // make_used_partitions_str /* @brief @@ -92,7 +92,24 @@ void Update_plan::save_qpf_intern(QPF_query *query, QPF_update *qpf) select_lex->set_explain_type(TRUE); qpf->select_type= select_lex->type; - + /* Partitions */ + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_info *part_info; + if ((part_info= table->part_info)) + { + make_used_partitions_str(part_info, &qpf->used_partitions); + qpf->used_partitions_set= true; + } + else + qpf->used_partitions_set= false; +#else + /* just produce empty column if partitioning is not compiled in */ + qpf->used_partitions_set= false; +#endif + } + + /* Set jtype */ if (select && select->quick) { diff --git a/sql/sql_select.cc b/sql/sql_select.cc index afa99a5cd24..baaef14e7b9 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -22331,7 +22331,7 @@ int print_explain_row(select_result_sink *result, uint select_number, const char *select_type, const char *table_name, - //const char *partitions, (todo) + const char *partitions, enum join_type jtype, const char *possible_keys, const char *index, @@ -22351,7 +22351,15 @@ int print_explain_row(select_result_sink *result, item_list.push_back(new Item_string(table_name, strlen(table_name), cs)); if (options & DESCRIBE_PARTITIONS) - item_list.push_back(item_null); // psergey-todo: produce proper value + { + if (partitions) + { + item_list.push_back(new Item_string(partitions, + strlen(partitions), cs)); + } + else + item_list.push_back(item_null); + } const char *jtype_str= join_type_str[jtype]; item_list.push_back(new Item_string(jtype_str, @@ -22377,8 +22385,9 @@ int print_explain_row(select_result_sink *result, item_list.push_back(new Item_int(rows, MY_INT64_NUM_DECIMAL_DIGITS)); /* 'filtered' */ + const double filtered=100.0; if (options & DESCRIBE_EXTENDED) - item_list.push_back(item_null); + item_list.push_back(new Item_float(filtered, 2)); /* 'Extra' */ item_list.push_back(new Item_string(extra, strlen(extra), cs)); @@ -22489,7 +22498,7 @@ void explain_append_mrr_info(QUICK_RANGE_SELECT *quick, String *res) /////////////////////////////////////////////////////////////////////////////// - +// TODO: join with make_possible_keys_line ? void append_possible_keys(String *str, TABLE *table, key_map possible_keys) { uint j; diff --git a/sql/sql_select.h b/sql/sql_select.h index 75d2aaf6631..b3177333d12 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1853,7 +1853,7 @@ int print_explain_row(select_result_sink *result, uint select_number, const char *select_type, const char *table_name, - //const char *partitions, (todo) + const char *partitions, enum join_type jtype, const char *possible_keys, const char *index, |