Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
69719446
Commit
69719446
authored
Apr 08, 2015
by
Oleksandr Byelkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-7856: EXPLAIN FORMAT=JSON should show partitions
parent
abba4184
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
152 additions
and
40 deletions
+152
-40
mysql-test/r/explain_json_format_partitions.result
mysql-test/r/explain_json_format_partitions.result
+83
-0
mysql-test/t/explain_json_format_partitions.test
mysql-test/t/explain_json_format_partitions.test
+17
-0
sql/sql_delete.cc
sql/sql_delete.cc
+2
-1
sql/sql_explain.cc
sql/sql_explain.cc
+25
-33
sql/sql_explain.h
sql/sql_explain.h
+6
-0
sql/sql_partition.cc
sql/sql_partition.cc
+10
-1
sql/sql_partition.h
sql/sql_partition.h
+4
-1
sql/sql_select.cc
sql/sql_select.cc
+3
-2
sql/sql_update.cc
sql/sql_update.cc
+2
-2
No files found.
mysql-test/r/explain_json_format_partitions.result
0 → 100644
View file @
69719446
create table t2(a int);
insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (
a int not null
) partition by key(a);
insert into t1 select a from t2;
explain partitions select * from t1 where a in (2,3,4);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 10 Using where
explain format=json select * from t1 where a in (2,3,4);
EXPLAIN
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t1",
"partitions": ["p0"],
"access_type": "ALL",
"rows": 10,
"filtered": 100,
"attached_condition": "(t1.a in (2,3,4))"
}
}
}
analyze format=json select * from t1 where a in (2,3,4);
ANALYZE
{
"query_block": {
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"table": {
"table_name": "t1",
"partitions": ["p0"],
"access_type": "ALL",
"r_loops": 1,
"rows": 10,
"r_rows": 10,
"r_total_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 30,
"attached_condition": "(t1.a in (2,3,4))"
}
}
}
analyze format=json update t1 set a=a+10 where a in (2,3,4);
ANALYZE
{
"query_block": {
"select_id": 1,
"table": {
"update": 1,
"table_name": "t1",
"partitions": ["p0"],
"access_type": "ALL",
"rows": 10,
"r_rows": 3,
"r_filtered": 100,
"using_io_buffer": 1,
"r_total_time_ms": "REPLACED",
"attached_condition": "(t1.a in (2,3,4))"
}
}
}
analyze format=json delete from t1 where a in (20,30,40);
ANALYZE
{
"query_block": {
"select_id": 1,
"table": {
"delete": 1,
"table_name": "t1",
"partitions": ["p0"],
"access_type": "ALL",
"rows": 10,
"r_rows": 10,
"r_filtered": 0,
"r_total_time_ms": "REPLACED",
"attached_condition": "(t1.a in (20,30,40))"
}
}
}
drop table t1,t2;
mysql-test/t/explain_json_format_partitions.test
0 → 100644
View file @
69719446
--
source
include
/
have_partition
.
inc
create
table
t2
(
a
int
);
insert
into
t2
values
(
0
),(
1
),(
2
),(
3
),(
4
),(
5
),(
6
),(
7
),(
8
),(
9
);
create
table
t1
(
a
int
not
null
)
partition
by
key
(
a
);
insert
into
t1
select
a
from
t2
;
explain
partitions
select
*
from
t1
where
a
in
(
2
,
3
,
4
);
explain
format
=
json
select
*
from
t1
where
a
in
(
2
,
3
,
4
);
--
replace_regex
/
"r_total_time_ms"
:
[
0
-
9
]
*
[
.
]
?
[
0
-
9
]
*/
"r_total_time_ms"
:
"REPLACED"
/
analyze
format
=
json
select
*
from
t1
where
a
in
(
2
,
3
,
4
);
--
replace_regex
/
"r_total_time_ms"
:
[
0
-
9
]
*
[
.
]
?
[
0
-
9
]
*/
"r_total_time_ms"
:
"REPLACED"
/
analyze
format
=
json
update
t1
set
a
=
a
+
10
where
a
in
(
2
,
3
,
4
);
--
replace_regex
/
"r_total_time_ms"
:
[
0
-
9
]
*
[
.
]
?
[
0
-
9
]
*/
"r_total_time_ms"
:
"REPLACED"
/
analyze
format
=
json
delete
from
t1
where
a
in
(
20
,
30
,
40
);
drop
table
t1
,
t2
;
sql/sql_delete.cc
View file @
69719446
...
...
@@ -117,7 +117,8 @@ void Update_plan::save_explain_data_intern(MEM_ROOT *mem_root,
partition_info
*
part_info
;
if
((
part_info
=
table
->
part_info
))
{
make_used_partitions_str
(
part_info
,
&
explain
->
used_partitions
);
make_used_partitions_str
(
mem_root
,
part_info
,
&
explain
->
used_partitions
,
explain
->
used_partitions_list
);
explain
->
used_partitions_set
=
true
;
}
else
...
...
sql/sql_explain.cc
View file @
69719446
...
...
@@ -37,6 +37,18 @@ Explain_query::Explain_query(THD *thd_arg, MEM_ROOT *root) :
{
}
static
void
print_json_array
(
Json_writer
*
writer
,
const
char
*
title
,
String_list
&
list
)
{
List_iterator_fast
<
char
>
it
(
list
);
const
char
*
name
;
writer
->
add_member
(
title
).
start_array
();
while
((
name
=
it
++
))
writer
->
add_str
(
name
);
writer
->
end_array
();
}
Explain_query
::~
Explain_query
()
{
...
...
@@ -1219,17 +1231,9 @@ void add_json_keyset(Json_writer *writer, const char *elem_name,
String_list
*
keyset
)
{
if
(
!
keyset
->
is_empty
())
{
List_iterator_fast
<
char
>
it
(
*
keyset
);
const
char
*
name
;
writer
->
add_member
(
elem_name
).
start_array
();
while
((
name
=
it
++
))
writer
->
add_str
(
name
);
writer
->
end_array
();
}
print_json_array
(
writer
,
elem_name
,
*
keyset
);
}
void
Explain_table_access
::
print_explain_json
(
Explain_query
*
query
,
Json_writer
*
writer
,
bool
is_analyze
)
...
...
@@ -1252,7 +1256,10 @@ void Explain_table_access::print_explain_json(Explain_query *query,
writer
->
add_member
(
"table"
).
start_object
();
writer
->
add_member
(
"table_name"
).
add_str
(
table_name
);
// partitions
if
(
used_partitions_set
)
print_json_array
(
writer
,
"partitions"
,
used_partitions_list
);
writer
->
add_member
(
"access_type"
).
add_str
(
join_type_str
[
type
]);
add_json_keyset
(
writer
,
"possible_keys"
,
&
possible_keys
);
...
...
@@ -1281,14 +1288,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
parts_list
=
&
key
.
key_parts_list
;
if
(
parts_list
&&
!
parts_list
->
is_empty
())
{
List_iterator_fast
<
char
>
it
(
*
parts_list
);
const
char
*
name
;
writer
->
add_member
(
"used_key_parts"
).
start_array
();
while
((
name
=
it
++
))
writer
->
add_str
(
name
);
writer
->
end_array
();
}
print_json_array
(
writer
,
"used_key_parts"
,
*
parts_list
);
if
(
quick_info
&&
!
quick_info
->
is_basic
())
{
...
...
@@ -1299,14 +1299,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
/* `ref` */
if
(
!
ref_list
.
is_empty
())
{
List_iterator_fast
<
char
>
it
(
ref_list
);
const
char
*
str
;
writer
->
add_member
(
"ref"
).
start_array
();
while
((
str
=
it
++
))
writer
->
add_str
(
str
);
writer
->
end_array
();
}
print_json_array
(
writer
,
"ref"
,
ref_list
);
/* r_loops (not present in tabular output) */
if
(
is_analyze
)
...
...
@@ -1554,13 +1547,8 @@ void Explain_quick_select::print_json(Json_writer *writer)
writer
->
add_member
(
"range"
).
start_object
();
writer
->
add_member
(
"key"
).
add_str
(
range
.
get_key_name
());
List_iterator_fast
<
char
>
it
(
range
.
key_parts_list
);
const
char
*
name
;
writer
->
add_member
(
"used_key_parts"
).
start_array
();
while
((
name
=
it
++
))
writer
->
add_str
(
name
);
writer
->
end_array
();
print_json_array
(
writer
,
"used_key_parts"
,
range
.
key_parts_list
);
writer
->
end_object
();
}
...
...
@@ -1845,6 +1833,10 @@ void Explain_update::print_explain_json(Explain_query *query,
writer
->
add_member
(
"delete"
).
add_ll
(
1
);
writer
->
add_member
(
"table_name"
).
add_str
(
table_name
);
if
(
used_partitions_set
)
print_json_array
(
writer
,
"partitions"
,
used_partitions_list
);
writer
->
add_member
(
"access_type"
).
add_str
(
join_type_str
[
jtype
]);
if
(
!
possible_keys
.
is_empty
())
...
...
sql/sql_explain.h
View file @
69719446
...
...
@@ -51,6 +51,9 @@ it into the slow query log.
*/
#ifndef SQL_EXPLAIN_INCLUDED
#define SQL_EXPLAIN_INCLUDED
class
String_list
:
public
List
<
char
>
{
public:
...
...
@@ -646,6 +649,7 @@ public:
/* id and 'select_type' are cared-of by the parent Explain_select */
StringBuffer
<
32
>
table_name
;
StringBuffer
<
32
>
used_partitions
;
String_list
used_partitions_list
;
// valid with ET_USING_MRR
StringBuffer
<
32
>
mrr_type
;
StringBuffer
<
32
>
firstmatch_table_name
;
...
...
@@ -768,6 +772,7 @@ public:
const
char
*
select_type
;
StringBuffer
<
32
>
used_partitions
;
String_list
used_partitions_list
;
bool
used_partitions_set
;
bool
impossible_where
;
...
...
@@ -863,3 +868,4 @@ public:
};
#endif //SQL_EXPLAIN_INCLUDED
sql/sql_partition.cc
View file @
69719446
...
...
@@ -68,6 +68,7 @@
// mysql_*_alter_copy_data
#include "opt_range.h" // store_key_image_to_rec
#include "sql_alter.h" // Alter_table_ctx
#include "sql_select.h"
#include <algorithm>
using
std
::
max
;
...
...
@@ -7290,8 +7291,10 @@ void mem_alloc_error(size_t size)
/**
Return comma-separated list of used partitions in the provided given string.
@param mem_root Where to allocate following list
@param part_info Partitioning info
@param[out] parts The resulting list of string to fill
@param[out] used_partitions_list result list to fill
Generate a list of used partitions (from bits in part_info->read_partitions
bitmap), and store it into the provided String object.
...
...
@@ -7302,7 +7305,10 @@ void mem_alloc_error(size_t size)
that was written or locked.
*/
void
make_used_partitions_str
(
partition_info
*
part_info
,
String
*
parts_str
)
void
make_used_partitions_str
(
MEM_ROOT
*
alloc
,
partition_info
*
part_info
,
String
*
parts_str
,
String_list
&
used_partitions_list
)
{
parts_str
->
length
(
0
);
partition_element
*
pe
;
...
...
@@ -7321,6 +7327,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str)
{
if
(
parts_str
->
length
())
parts_str
->
append
(
','
);
uint
index
=
parts_str
->
length
();
parts_str
->
append
(
head_pe
->
partition_name
,
strlen
(
head_pe
->
partition_name
),
system_charset_info
);
...
...
@@ -7328,6 +7335,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str)
parts_str
->
append
(
pe
->
partition_name
,
strlen
(
pe
->
partition_name
),
system_charset_info
);
used_partitions_list
.
append_str
(
alloc
,
parts_str
->
ptr
()
+
index
);
}
partition_id
++
;
}
...
...
@@ -7341,6 +7349,7 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str)
{
if
(
parts_str
->
length
())
parts_str
->
append
(
','
);
used_partitions_list
.
append_str
(
alloc
,
pe
->
partition_name
);
parts_str
->
append
(
pe
->
partition_name
,
strlen
(
pe
->
partition_name
),
system_charset_info
);
}
...
...
sql/sql_partition.h
View file @
69719446
...
...
@@ -74,6 +74,7 @@ typedef struct {
uint32
end_part
;
}
part_id_range
;
class
String_list
;
struct
st_partition_iter
;
#define NOT_A_PARTITION_ID UINT_MAX32
...
...
@@ -114,7 +115,9 @@ bool mysql_unpack_partition(THD *thd, char *part_buf,
TABLE
*
table
,
bool
is_create_table_ind
,
handlerton
*
default_db_type
,
bool
*
work_part_info_used
);
void
make_used_partitions_str
(
partition_info
*
part_info
,
String
*
parts_str
);
void
make_used_partitions_str
(
MEM_ROOT
*
mem_root
,
partition_info
*
part_info
,
String
*
parts_str
,
String_list
&
used_partitions_list
);
uint32
get_list_array_idx_for_endpoint
(
partition_info
*
part_info
,
bool
left_endpoint
,
bool
include_endpoint
);
...
...
sql/sql_select.cc
View file @
69719446
...
...
@@ -23500,8 +23500,9 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab
partition_info
*
part_info
;
if
(
!
table
->
derived_select_number
&&
(
part_info
=
table
->
part_info
))
{
make_used_partitions_str
(
part_info
,
&
eta
->
used_partitions
);
{
//TODO: all thd->mem_root here should be fixed
make_used_partitions_str
(
thd
->
mem_root
,
part_info
,
&
eta
->
used_partitions
,
eta
->
used_partitions_list
);
eta
->
used_partitions_set
=
true
;
}
else
...
...
sql/sql_update.cc
View file @
69719446
...
...
@@ -517,7 +517,7 @@ int mysql_update(THD *thd,
*/
if
(
thd
->
lex
->
describe
)
goto
produce_explain_and_leave
;
explain
=
query_plan
.
save_explain_update_data
(
thd
->
mem_root
,
thd
);
explain
=
query_plan
.
save_explain_update_data
(
query_plan
.
mem_root
,
thd
);
ANALYZE_START_TRACKING
(
&
explain
->
command_tracker
);
...
...
@@ -1046,7 +1046,7 @@ produce_explain_and_leave:
We come here for various "degenerate" query plans: impossible WHERE,
no-partitions-used, impossible-range, etc.
*/
query_plan
.
save_explain_update_data
(
thd
->
mem_root
,
thd
);
query_plan
.
save_explain_update_data
(
query_plan
.
mem_root
,
thd
);
emit_explain_and_leave:
int
err2
=
thd
->
lex
->
explain
->
send_explain
(
thd
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment