Commit 0c35e80d authored by Varun Gupta's avatar Varun Gupta

MDEV-21838: Add information about packed addon fields in ANALYZE FORMAT=JSON

It is useful to know whether sorting uses addon fields[packed|unpacked] or ROWID.
Provide this information in ANALYZE FORMAT=JSON output.
parent 8db62303
...@@ -517,6 +517,7 @@ ANALYZE ...@@ -517,6 +517,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 0, "r_output_rows": 0,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"table": { "table": {
"table_name": "t2", "table_name": "t2",
...@@ -548,6 +549,7 @@ ANALYZE ...@@ -548,6 +549,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 256, "r_output_rows": 256,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"table": { "table": {
"table_name": "t2", "table_name": "t2",
...@@ -590,6 +592,7 @@ ANALYZE ...@@ -590,6 +592,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 256, "r_output_rows": 256,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"table": { "table": {
"table_name": "t2", "table_name": "t2",
...@@ -701,6 +704,7 @@ ANALYZE ...@@ -701,6 +704,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 0, "r_output_rows": 0,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"filesort": { "filesort": {
"sort_key": "(subquery#2)", "sort_key": "(subquery#2)",
...@@ -709,6 +713,7 @@ ANALYZE ...@@ -709,6 +713,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 0, "r_output_rows": 0,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"table": { "table": {
"table_name": "t2", "table_name": "t2",
...@@ -824,6 +829,7 @@ ANALYZE ...@@ -824,6 +829,7 @@ ANALYZE
"r_limit": null, "r_limit": null,
"r_used_priority_queue": null, "r_used_priority_queue": null,
"r_output_rows": null, "r_output_rows": null,
"r_sort_mode": "sort_key,rowid",
"table": { "table": {
"table_name": "t2", "table_name": "t2",
"access_type": "ALL", "access_type": "ALL",
......
...@@ -44,6 +44,7 @@ ANALYZE ...@@ -44,6 +44,7 @@ ANALYZE
"r_limit": 5, "r_limit": 5,
"r_used_priority_queue": true, "r_used_priority_queue": true,
"r_output_rows": 6, "r_output_rows": 6,
"r_sort_mode": "sort_key,rowid",
"table": { "table": {
"update": 1, "update": 1,
"table_name": "t2", "table_name": "t2",
...@@ -145,6 +146,7 @@ ANALYZE ...@@ -145,6 +146,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 10000, "r_output_rows": 10000,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,rowid",
"table": { "table": {
"delete": 1, "delete": 1,
"table_name": "t2", "table_name": "t2",
...@@ -211,6 +213,7 @@ ANALYZE ...@@ -211,6 +213,7 @@ ANALYZE
"r_limit": 4, "r_limit": 4,
"r_used_priority_queue": true, "r_used_priority_queue": true,
"r_output_rows": 4, "r_output_rows": 4,
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"table": { "table": {
"table_name": "t0", "table_name": "t0",
...@@ -300,6 +303,7 @@ ANALYZE ...@@ -300,6 +303,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 10, "r_output_rows": 10,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,addon_fields",
"table": { "table": {
"table_name": "t0", "table_name": "t0",
"access_type": "ALL", "access_type": "ALL",
...@@ -359,6 +363,7 @@ ANALYZE ...@@ -359,6 +363,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 10, "r_output_rows": 10,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"table": { "table": {
"table_name": "t2", "table_name": "t2",
...@@ -472,6 +477,7 @@ ANALYZE ...@@ -472,6 +477,7 @@ ANALYZE
"r_limit": 1, "r_limit": 1,
"r_used_priority_queue": true, "r_used_priority_queue": true,
"r_output_rows": 2, "r_output_rows": 2,
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"filesort": { "filesort": {
"sort_key": "t5.a", "sort_key": "t5.a",
...@@ -480,6 +486,7 @@ ANALYZE ...@@ -480,6 +486,7 @@ ANALYZE
"r_used_priority_queue": false, "r_used_priority_queue": false,
"r_output_rows": 6, "r_output_rows": 6,
"r_buffer_size": "REPLACED", "r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,rowid",
"temporary_table": { "temporary_table": {
"table": { "table": {
"table_name": "t6", "table_name": "t6",
......
...@@ -82,6 +82,42 @@ select id, generate_random_string(a), generate_random_string(b) from t2; ...@@ -82,6 +82,42 @@ select id, generate_random_string(a), generate_random_string(b) from t2;
# All records fit in memory # All records fit in memory
# #
set sort_buffer_size=262144*10; set sort_buffer_size=262144*10;
analyze format=json select id DIV 100 as x,
MD5(group_concat(substring(names,1,3), substring(address,1,3)
order by id))
FROM t3
GROUP BY x;
ANALYZE
{
"query_block": {
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"read_sorted_file": {
"r_rows": 10000,
"filesort": {
"sort_key": "t3.`id` DIV 100",
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_used_priority_queue": false,
"r_output_rows": 10000,
"r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,packed_addon_fields",
"table": {
"table_name": "t3",
"access_type": "ALL",
"r_loops": 1,
"rows": 10000,
"r_rows": 10000,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 100
}
}
}
}
}
flush status; flush status;
select id DIV 100 as x, select id DIV 100 as x,
MD5(group_concat(substring(names,1,3), substring(address,1,3) MD5(group_concat(substring(names,1,3), substring(address,1,3)
...@@ -203,6 +239,43 @@ set sort_buffer_size=default; ...@@ -203,6 +239,43 @@ set sort_buffer_size=default;
# Test for merge_many_buff # Test for merge_many_buff
# #
set sort_buffer_size=32768; set sort_buffer_size=32768;
analyze format=json select id DIV 100 as x,
MD5(group_concat(substring(names,1,3), substring(address,1,3)
order by id))
FROM t3
GROUP BY x;
ANALYZE
{
"query_block": {
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"read_sorted_file": {
"r_rows": 10000,
"filesort": {
"sort_key": "t3.`id` DIV 100",
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_used_priority_queue": false,
"r_output_rows": 10000,
"r_sort_passes": 4,
"r_buffer_size": "REPLACED",
"r_sort_mode": "sort_key,packed_addon_fields",
"table": {
"table_name": "t3",
"access_type": "ALL",
"r_loops": 1,
"rows": 10000,
"r_rows": 10000,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 100
}
}
}
}
}
flush status; flush status;
select id DIV 100 as x, select id DIV 100 as x,
MD5(group_concat(substring(names,1,3), substring(address,1,3) MD5(group_concat(substring(names,1,3), substring(address,1,3)
......
...@@ -109,6 +109,8 @@ let $query= select id DIV 100 as x, ...@@ -109,6 +109,8 @@ let $query= select id DIV 100 as x,
--echo # --echo #
set sort_buffer_size=262144*10; set sort_buffer_size=262144*10;
--source include/analyze-format.inc
eval analyze format=json $query;
flush status; flush status;
eval $query; eval $query;
show status like '%sort%'; show status like '%sort%';
...@@ -119,6 +121,8 @@ set sort_buffer_size=default; ...@@ -119,6 +121,8 @@ set sort_buffer_size=default;
--echo # --echo #
set sort_buffer_size=32768; set sort_buffer_size=32768;
--source include/analyze-format.inc
eval analyze format=json $query;
flush status; flush status;
eval $query; eval $query;
show status like '%sort%'; show status like '%sort%';
......
...@@ -298,6 +298,12 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, ...@@ -298,6 +298,12 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
tracker->report_sort_buffer_size(sort->sort_buffer_size()); tracker->report_sort_buffer_size(sort->sort_buffer_size());
} }
if (param.using_addon_fields())
{
// report information whether addon fields are packed or not
tracker->report_addon_fields_format(param.using_packed_addons());
}
if (open_cached_file(&buffpek_pointers,mysql_tmpdir,TEMP_PREFIX, if (open_cached_file(&buffpek_pointers,mysql_tmpdir,TEMP_PREFIX,
DISK_BUFFER_SIZE, MYF(MY_WME))) DISK_BUFFER_SIZE, MYF(MY_WME)))
goto err; goto err;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
void Filesort_tracker::print_json_members(Json_writer *writer) void Filesort_tracker::print_json_members(Json_writer *writer)
{ {
const char *varied_str= "(varied across executions)"; const char *varied_str= "(varied across executions)";
String str;
if (!get_r_loops()) if (!get_r_loops())
writer->add_member("r_loops").add_null(); writer->add_member("r_loops").add_null();
...@@ -78,6 +79,25 @@ void Filesort_tracker::print_json_members(Json_writer *writer) ...@@ -78,6 +79,25 @@ void Filesort_tracker::print_json_members(Json_writer *writer)
else else
writer->add_size(sort_buffer_size); writer->add_size(sort_buffer_size);
} }
get_data_format(&str);
writer->add_member("r_sort_mode").add_str(str.c_ptr(), str.length());
}
void Filesort_tracker::get_data_format(String *str)
{
str->append("sort_key");
str->append(",");
if (r_using_addons)
{
if (r_packed_addon_fields)
str->append("packed_addon_fields");
else
str->append("addon_fields");
}
else
str->append("rowid");
} }
void attach_gap_time_tracker(THD *thd, Gap_time_tracker *gap_tracker, void attach_gap_time_tracker(THD *thd, Gap_time_tracker *gap_tracker,
......
...@@ -221,7 +221,9 @@ class Filesort_tracker : public Sql_alloc ...@@ -221,7 +221,9 @@ class Filesort_tracker : public Sql_alloc
time_tracker(do_timing), r_limit(0), r_used_pq(0), time_tracker(do_timing), r_limit(0), r_used_pq(0),
r_examined_rows(0), r_sorted_rows(0), r_output_rows(0), r_examined_rows(0), r_sorted_rows(0), r_output_rows(0),
sort_passes(0), sort_passes(0),
sort_buffer_size(0) sort_buffer_size(0),
r_using_addons(false),
r_packed_addon_fields(false)
{} {}
/* Functions that filesort uses to report various things about its execution */ /* Functions that filesort uses to report various things about its execution */
...@@ -263,6 +265,14 @@ class Filesort_tracker : public Sql_alloc ...@@ -263,6 +265,14 @@ class Filesort_tracker : public Sql_alloc
else else
sort_buffer_size= bufsize; sort_buffer_size= bufsize;
} }
inline void report_addon_fields_format(bool addons_packed)
{
r_using_addons= true;
r_packed_addon_fields= addons_packed;
}
void get_data_format(String *str);
/* Functions to get the statistics */ /* Functions to get the statistics */
void print_json_members(Json_writer *writer); void print_json_members(Json_writer *writer);
...@@ -322,6 +332,8 @@ class Filesort_tracker : public Sql_alloc ...@@ -322,6 +332,8 @@ class Filesort_tracker : public Sql_alloc
other - value other - value
*/ */
ulonglong sort_buffer_size; ulonglong sort_buffer_size;
bool r_using_addons;
bool r_packed_addon_fields;
}; };
......
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