diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2015-07-01 20:03:29 +0300 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2015-07-01 20:03:29 +0300 |
commit | 9d2aa2b3093e315f02e42943589f47447c67bbd8 (patch) | |
tree | f2f73397e7d6b26e76971e702fbd6a6a01b95521 /sql/sql_explain.cc | |
parent | c6aee27b73232fc6ba3e8b55adbb0abba4f0171b (diff) | |
download | mariadb-git-9d2aa2b3093e315f02e42943589f47447c67bbd8.tar.gz |
MDEV-7811: EXPLAIN/ANALYZE FORMAT=JSON should show subquery cache
Fixes over the original patch:
- Fix variable/class/other names
- Fix the JSON output to be in line with the output of other JSON
constructs we produce
Diffstat (limited to 'sql/sql_explain.cc')
-rw-r--r-- | sql/sql_explain.cc | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 210700a2804..9f4b635fbf4 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -521,6 +521,8 @@ void Explain_union::print_explain_json(Explain_query *query, Json_writer_nesting_guard guard(writer); char table_name_buffer[SAFE_NAME_LEN]; + bool started_object= print_explain_json_cache(writer, is_analyze); + writer->add_member("query_block").start_object(); writer->add_member("union_result").start_object(); // using_temporary_table @@ -544,7 +546,6 @@ void Explain_union::print_explain_json(Explain_query *query, writer->add_null(); } - print_explain_json_cache(writer, is_analyze); writer->add_member("query_specifications").start_array(); for (int i= 0; i < (int) union_members.elements(); i++) @@ -562,6 +563,9 @@ void Explain_union::print_explain_json(Explain_query *query, writer->end_object(); // union_result writer->end_object(); // query_block + + if (started_object) + writer->end_object(); } @@ -642,27 +646,32 @@ void Explain_node::print_explain_json_for_children(Explain_query *query, } -void Explain_node::print_explain_json_cache(Json_writer *writer, +bool Explain_node::print_explain_json_cache(Json_writer *writer, bool is_analyze) { - if (cache_stat) + if (cache_tracker) + { + cache_tracker->fetch_current_stats(); + writer->add_member("expression_cache").start_object(); + if (cache_tracker->state != Expression_cache_tracker::OK) { - cache_stat->flush_stat(); - writer->add_member("expression_cache").start_object(); writer->add_member("state"). - add_str(Expression_cache_stat::state_str[cache_stat->state]); - if (is_analyze) + add_str(Expression_cache_tracker::state_str[cache_tracker->state]); + } + + if (is_analyze) + { + longlong cache_reads= cache_tracker->hit + cache_tracker->miss; + writer->add_member("r_loops").add_ll(cache_reads); + if (cache_reads != 0) { - writer->add_member("r_hit").add_ll(cache_stat->hit); - writer->add_member("r_miss").add_ll(cache_stat->miss); - writer->add_member("r_loops").add_ll(cache_stat->hit + - cache_stat->miss); - writer->add_member("r_hit_ratio").add_ll(((double)cache_stat->hit)/ - ((double)(cache_stat->hit + - cache_stat->miss)) * 100.0); + double hit_ratio= double(cache_tracker->hit) / cache_reads * 100.0; + writer->add_member("r_hit_ratio").add_double(hit_ratio); } - writer->end_object(); } + return true; + } + return false; } @@ -766,6 +775,8 @@ void Explain_select::print_explain_json(Explain_query *query, Json_writer *writer, bool is_analyze) { Json_writer_nesting_guard guard(writer); + + bool started_cache= print_explain_json_cache(writer, is_analyze); if (message) { @@ -795,7 +806,6 @@ void Explain_select::print_explain_json(Explain_query *query, writer->add_member("const_condition"); write_item(writer, exec_const_cond); } - print_explain_json_cache(writer, is_analyze); Filesort_tracker *first_table_sort= NULL; bool first_table_sort_used= false; @@ -887,6 +897,8 @@ void Explain_select::print_explain_json(Explain_query *query, writer->end_object(); } + if (started_cache) + writer->end_object(); } |