Commit 2bbf3b89 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-7836: ANALYZE FORMAT=JSON should provide info about GROUP/ORDER BY

Fix EXPLAIN FORMAT=JSON to produce output that's not worse than
the tabular form.
parent cc8da9b7
...@@ -169,25 +169,27 @@ EXPLAIN ...@@ -169,25 +169,27 @@ EXPLAIN
{ {
"query_block": { "query_block": {
"select_id": 1, "select_id": 1,
"temporary_table": { "filesort": {
"function": "buffer", "temporary_table": {
"table": { "function": "buffer",
"table_name": "t0", "table": {
"access_type": "ALL", "table_name": "t0",
"rows": 10, "access_type": "ALL",
"filtered": 100, "rows": 10,
"attached_condition": "(t0.a is not null)" "filtered": 100,
}, "attached_condition": "(t0.a is not null)"
"table": { },
"table_name": "t2", "table": {
"access_type": "ref", "table_name": "t2",
"possible_keys": ["a"], "access_type": "ref",
"key": "a", "possible_keys": ["a"],
"key_length": "5", "key": "a",
"used_key_parts": ["a"], "key_length": "5",
"ref": ["test.t0.a"], "used_key_parts": ["a"],
"rows": 1, "ref": ["test.t0.a"],
"filtered": 100 "rows": 1,
"filtered": 100
}
} }
} }
} }
...@@ -240,6 +242,36 @@ select * from t0,t2 where t2.a=t0.a order by t0.a limit 4; ...@@ -240,6 +242,36 @@ select * from t0,t2 where t2.a=t0.a order by t0.a limit 4;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where; Using filesort 1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where; Using filesort
1 SIMPLE t2 ref a a 5 test.t0.a 1 1 SIMPLE t2 ref a a 5 test.t0.a 1
explain format=json
select * from t0,t2 where t2.a=t0.a order by t0.a limit 4;
EXPLAIN
{
"query_block": {
"select_id": 1,
"read_sorted_file": {
"filesort": {
"table": {
"table_name": "t0",
"access_type": "ALL",
"rows": 10,
"filtered": 100,
"attached_condition": "(t0.a is not null)"
}
}
},
"table": {
"table_name": "t2",
"access_type": "ref",
"possible_keys": ["a"],
"key": "a",
"key_length": "5",
"used_key_parts": ["a"],
"ref": ["test.t0.a"],
"rows": 1,
"filtered": 100
}
}
}
analyze format=json analyze format=json
select * from t0,t2 where t2.a=t0.a order by t0.a limit 4; select * from t0,t2 where t2.a=t0.a order by t0.a limit 4;
ANALYZE ANALYZE
......
...@@ -479,13 +479,15 @@ EXPLAIN ...@@ -479,13 +479,15 @@ EXPLAIN
"materialized": { "materialized": {
"query_block": { "query_block": {
"select_id": 2, "select_id": 2,
"temporary_table": { "filesort": {
"function": "buffer", "temporary_table": {
"table": { "function": "buffer",
"table_name": "t1", "table": {
"access_type": "ALL", "table_name": "t1",
"rows": 10, "access_type": "ALL",
"filtered": 100 "rows": 10,
"filtered": 100
}
} }
} }
} }
...@@ -521,13 +523,15 @@ EXPLAIN ...@@ -521,13 +523,15 @@ EXPLAIN
"materialized": { "materialized": {
"query_block": { "query_block": {
"select_id": 2, "select_id": 2,
"temporary_table": { "filesort": {
"function": "buffer", "temporary_table": {
"table": { "function": "buffer",
"table_name": "t1", "table": {
"access_type": "ALL", "table_name": "t1",
"rows": 10, "access_type": "ALL",
"filtered": 100 "rows": 10,
"filtered": 100
}
} }
} }
} }
......
...@@ -48,17 +48,19 @@ ANALYZE ...@@ -48,17 +48,19 @@ ANALYZE
{ {
"query_block": { "query_block": {
"select_id": 1, "select_id": 1,
"table": { "r_total_time_ms": "REPLACED",
"update": 1, "buffer": {
"table_name": "t1", "table": {
"partitions": ["p0"], "update": 1,
"access_type": "ALL", "table_name": "t1",
"rows": 10, "partitions": ["p0"],
"r_rows": 3, "access_type": "ALL",
"r_filtered": 100, "rows": 10,
"using_io_buffer": 1, "r_rows": 10,
"r_total_time_ms": "REPLACED", "r_filtered": 30,
"attached_condition": "(t1.a in (2,3,4))" "r_total_time_ms": "REPLACED",
"attached_condition": "(t1.a in (2,3,4))"
}
} }
} }
} }
...@@ -67,6 +69,7 @@ ANALYZE ...@@ -67,6 +69,7 @@ ANALYZE
{ {
"query_block": { "query_block": {
"select_id": 1, "select_id": 1,
"r_total_time_ms": "REPLACED",
"table": { "table": {
"delete": 1, "delete": 1,
"table_name": "t1", "table_name": "t1",
......
...@@ -63,8 +63,8 @@ select * from t0,t2 where t2.a=t0.a order by t2.b limit 4; ...@@ -63,8 +63,8 @@ select * from t0,t2 where t2.a=t0.a order by t2.b limit 4;
--echo # --echo #
explain explain
select * from t0,t2 where t2.a=t0.a order by t0.a limit 4; select * from t0,t2 where t2.a=t0.a order by t0.a limit 4;
## explain format=json explain format=json
## select * from t0,t2 where t2.a=t0.a order by t0.a limit 4; select * from t0,t2 where t2.a=t0.a order by t0.a limit 4;
--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/
analyze format=json analyze format=json
select * from t0,t2 where t2.a=t0.a order by t0.a limit 4; select * from t0,t2 where t2.a=t0.a order by t0.a limit 4;
......
...@@ -818,9 +818,19 @@ void Explain_select::print_explain_json(Explain_query *query, ...@@ -818,9 +818,19 @@ void Explain_select::print_explain_json(Explain_query *query,
if (using_temporary) if (using_temporary)
{ {
started_objects= 1; started_objects= 1;
if (using_filesort)
{
started_objects++;
writer->add_member("filesort").start_object();
}
writer->add_member("temporary_table").start_object(); writer->add_member("temporary_table").start_object();
writer->add_member("function").add_str("buffer"); writer->add_member("function").add_str("buffer");
} }
else
{
if (using_filesort)
first_table_sort= &ops_tracker.filesort_tracker[0];
}
} }
Explain_basic_join::print_explain_json_interns(query, writer, is_analyze, Explain_basic_join::print_explain_json_interns(query, writer, is_analyze,
...@@ -1293,7 +1303,12 @@ void add_json_keyset(Json_writer *writer, const char *elem_name, ...@@ -1293,7 +1303,12 @@ void add_json_keyset(Json_writer *writer, const char *elem_name,
/* /*
@param fs_tracker Normally NULL. When not NULL, it means that the join tab @param fs_tracker Normally NULL. When not NULL, it means that the join tab
used filesort. used filesort to pre-sort the data. Then, sorted data
was read and the rest of the join was executed.
@note
EXPLAIN command will check whether fs_tracker is present, but it can't use
any value from fs_tracker (these are only valid for ANALYZE).
*/ */
void Explain_table_access::print_explain_json(Explain_query *query, void Explain_table_access::print_explain_json(Explain_query *query,
...@@ -1330,7 +1345,8 @@ void Explain_table_access::print_explain_json(Explain_query *query, ...@@ -1330,7 +1345,8 @@ void Explain_table_access::print_explain_json(Explain_query *query,
} }
} }
writer->add_member("filesort").start_object(); writer->add_member("filesort").start_object();
fs_tracker->print_json(writer); if (is_analyze)
fs_tracker->print_json(writer);
} }
if (bka_type.is_using_jbuf()) if (bka_type.is_using_jbuf())
......
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