summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2015-04-08 20:14:48 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2015-04-09 14:51:23 +0200
commitb05383cb1440d2a6508d5254e0617e0dccf49898 (patch)
tree643f7efaaa07049f839b58e059da7ffa708fd448 /sql
parent697194461ad2031420bc1aaf8a03432dbf2acd66 (diff)
downloadmariadb-git-b05383cb1440d2a6508d5254e0617e0dccf49898.tar.gz
MDEV-7835: ANALYZE FORMAT=JSON should show buffer sizes
Diffstat (limited to 'sql')
-rw-r--r--sql/my_json_writer.cc21
-rw-r--r--sql/my_json_writer.h1
-rw-r--r--sql/sql_explain.cc1
-rw-r--r--sql/sql_explain.h2
-rw-r--r--sql/sql_join_cache.cc2
5 files changed, 27 insertions, 0 deletions
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";