diff --git a/mysql-test/r/analyze_format_json.result b/mysql-test/r/analyze_format_json.result index 2c339042f43..461dd35ef87 100644 --- a/mysql-test/r/analyze_format_json.result +++ b/mysql-test/r/analyze_format_json.result @@ -143,6 +143,7 @@ ANALYZE "attached_condition": "(tbl2.b < 60)" }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "r_filtered": 100 } @@ -180,6 +181,7 @@ ANALYZE "attached_condition": "(tbl2.b < 60)" }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "(tbl1.c > tbl2.c)", "r_filtered": 15.833 diff --git a/mysql-test/r/explain_json.result b/mysql-test/r/explain_json.result index 93220cb5fd7..65582912c93 100644 --- a/mysql-test/r/explain_json.result +++ b/mysql-test/r/explain_json.result @@ -365,6 +365,7 @@ EXPLAIN "attached_condition": "(tbl2.b < 5)" }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "(tbl2.a = tbl1.a)" } @@ -618,6 +619,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL" } } @@ -651,6 +653,7 @@ EXPLAIN "first_match": "t2" }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "((t1.b = t2.b) and (t1.a = t2.a))" } @@ -687,6 +690,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "((t1.b = t2.b) and (t1.a = t2.a))" } @@ -799,6 +803,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "((t2.b <> outer_t1.a) and trigcond((((outer_t1.a) = t1.a) or isnull(t1.a))))" } @@ -849,6 +854,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", + "buffer_size": "128Kb", "join_type": "BNL", "attached_condition": "(tbl2.b = tbl1.b)" } diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc index 7a3dc776093..e97db210da7 100644 --- a/sql/my_json_writer.cc +++ b/sql/my_json_writer.cc @@ -130,6 +130,27 @@ void Json_writer::add_ll(longlong val) } +/* Add a memory size, printing in Kb, Kb, Gb if necessary */ +void Json_writer::add_size(longlong val) +{ + char buf[64]; + if (val < 1024) + my_snprintf(buf, sizeof(buf), "%ld", val); + else if (val < 1024*1024*16) + { + /* Values less than 16MB are specified in KB for precision */ + size_t len= my_snprintf(buf, sizeof(buf), "%ld", val/1024); + strcpy(buf + len, "Kb"); + } + else + { + size_t len= my_snprintf(buf, sizeof(buf), "%ld", val/(1024*1024)); + strcpy(buf + len, "Mb"); + } + add_str(buf); +} + + void Json_writer::add_double(double val) { char buf[64]; diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index 3a7defc3566..8ab20b10d73 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -108,6 +108,7 @@ public: void add_str(const String &str); void add_ll(longlong val); + void add_size(longlong val); void add_double(double val); void add_bool(bool val); void add_null(); diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 3fbb720e6c5..2f421a22c40 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1360,6 +1360,7 @@ void Explain_table_access::print_explain_json(Explain_query *query, writer->end_object(); // "block-nl-join" writer->add_member("buffer_type").add_str(bka_type.incremental? "incremental":"flat"); + writer->add_member("buffer_size").add_size(bka_type.join_buffer_size); writer->add_member("join_type").add_str(bka_type.join_alg); if (bka_type.mrr_type.length()) writer->add_member("mrr_type").add_str(bka_type.mrr_type); diff --git a/sql/sql_explain.h b/sql/sql_explain.h index f4f421a76a4..aef4badf0e8 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -511,6 +511,8 @@ class EXPLAIN_BKA_TYPE public: EXPLAIN_BKA_TYPE() : join_alg(NULL) {} + size_t join_buffer_size; + bool incremental; /* diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index cec0755c9b0..23357ac871d 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -2582,6 +2582,8 @@ void JOIN_CACHE::save_explain_data(EXPLAIN_BKA_TYPE *explain) { explain->incremental= MY_TEST(prev_cache); + explain->join_buffer_size= get_join_buffer_size(); + switch (get_join_alg()) { case BNL_JOIN_ALG: explain->join_alg= "BNL";