summaryrefslogtreecommitdiff
path: root/sql/sql_explain.cc
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2015-03-07 22:47:28 +0300
committerSergei Petrunia <psergey@askmonty.org>2015-03-07 22:47:28 +0300
commit1626e0d3d48f56bd91239c4fcbc24595ee3a34e3 (patch)
tree6d92530c4d9c2f47030be63f9cfc851636107ae5 /sql/sql_explain.cc
parent2288b84df46501b89a70d7dc3b46020e0af9a95e (diff)
downloadmariadb-git-1626e0d3d48f56bd91239c4fcbc24595ee3a34e3.tar.gz
MDEV-7648: Extra data in ANALYZE FORMAT=JSON $stmt
Show total execution time (r_total_time_ms) for various parts of the query: 1. time spent in SELECTs 2. time spent reading rows from storage engines #2 currently gets the data from P_S.
Diffstat (limited to 'sql/sql_explain.cc')
-rw-r--r--sql/sql_explain.cc47
1 files changed, 46 insertions, 1 deletions
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index aa16a744e83..873ed74a1a2 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -732,7 +732,12 @@ void Explain_select::print_explain_json(Explain_query *query,
*/
writer->add_member("query_block").start_object();
writer->add_member("select_id").add_ll(select_id);
-
+
+ if (is_analyze && time_tracker.get_loops())
+ {
+ writer->add_member("r_loops").add_ll(time_tracker.get_loops());
+ writer->add_member("r_total_time_ms").add_double(time_tracker.get_time_ms());
+ }
if (exec_const_cond)
{
writer->add_member("const_condition");
@@ -1289,6 +1294,9 @@ void Explain_table_access::print_explain_json(Explain_query *query,
}
else
writer->add_null();
+
+ op_tracker.end_tracking();
+ op_tracker.print_json(writer);
}
/* `filtered` */
@@ -1971,3 +1979,40 @@ void create_explain_query_if_not_exists(LEX *lex, MEM_ROOT *mem_root)
create_explain_query(lex, mem_root);
}
+//////////////////////////////////////////////////////////////////////////////
+//
+//////////////////////////////////////////////////////////////////////////////
+
+void Table_op_tracker::start_tracking(TABLE *table)
+{
+ //TODO: will this compile without P_S ?
+ start_count= end_count= 0;
+ if ((psi_table= table->file->m_psi))
+ {
+ PSI_CALL_get_table_current_stats(psi_table, &start_count, &start_sum);
+ }
+}
+
+
+void Table_op_tracker::end_tracking()
+{
+ if (psi_table)
+ {
+ PSI_CALL_get_table_current_stats(psi_table, &end_count, &end_sum);
+ }
+}
+
+void Table_op_tracker::print_json(Json_writer *writer)
+{
+ if (start_count != end_count)
+ {
+ /*
+ We have time in picoseconds, we want to print in milli-seconds
+ picosecond is sec* 10^ -12
+ millisecond is sec * 10^-3
+ */
+ double ms= double(end_sum - start_sum) / 1e9;
+ writer->add_member("r_total_time_ms").add_double(ms);
+ }
+}
+