mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
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.
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user