Commit 5e4044e9 authored by Sergey Petrunya's avatar Sergey Petrunya

MDEV-5093, MDEV-5094:

- Make EXPLAIN {PARTITIONS,EXTENDED} {UPDATE,DELETE} work.
parent 6519ca51
......@@ -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;
#
# 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;
......@@ -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,
......
......@@ -454,6 +454,9 @@ class QPF_update : public QPF_node
const char *select_type;
StringBuffer<32> used_partitions;
bool used_partitions_set;
bool impossible_where;
StringBuffer<64> table_name;
......
......@@ -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)
{
......
......@@ -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;
......
......@@ -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,
......
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