2015-04-12 03:48:42 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 MariaDB Corporation Ab
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 21:19:05 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
|
2015-04-12 03:48:42 +02:00
|
|
|
|
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
|
|
|
#pragma implementation // gcc: Class implementation
|
|
|
|
#endif
|
|
|
|
|
2017-06-18 05:42:16 +02:00
|
|
|
#include "mariadb.h"
|
2015-04-12 03:48:42 +02:00
|
|
|
#include "sql_priv.h"
|
|
|
|
#include "sql_select.h"
|
|
|
|
#include "my_json_writer.h"
|
|
|
|
|
2015-06-05 23:32:27 +02:00
|
|
|
void Filesort_tracker::print_json_members(Json_writer *writer)
|
2015-04-12 03:48:42 +02:00
|
|
|
{
|
|
|
|
const char *varied_str= "(varied across executions)";
|
2020-02-28 07:16:13 +01:00
|
|
|
String str;
|
2017-07-12 16:16:44 +02:00
|
|
|
|
|
|
|
if (!get_r_loops())
|
|
|
|
writer->add_member("r_loops").add_null();
|
|
|
|
else
|
|
|
|
writer->add_member("r_loops").add_ll(get_r_loops());
|
2015-04-12 03:48:42 +02:00
|
|
|
|
2015-08-07 16:41:35 +02:00
|
|
|
if (get_r_loops() && time_tracker.timed)
|
|
|
|
{
|
|
|
|
writer->add_member("r_total_time_ms").
|
|
|
|
add_double(time_tracker.get_time_ms());
|
|
|
|
}
|
2015-04-12 03:48:42 +02:00
|
|
|
if (r_limit != HA_POS_ERROR)
|
|
|
|
{
|
|
|
|
writer->add_member("r_limit");
|
2017-07-12 16:16:44 +02:00
|
|
|
if (!get_r_loops())
|
|
|
|
writer->add_null();
|
|
|
|
else if (r_limit == 0)
|
2015-04-12 03:48:42 +02:00
|
|
|
writer->add_str(varied_str);
|
|
|
|
else
|
2019-05-01 13:14:50 +02:00
|
|
|
writer->add_ll(r_limit);
|
2015-04-12 03:48:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
writer->add_member("r_used_priority_queue");
|
2017-07-12 16:16:44 +02:00
|
|
|
if (!get_r_loops())
|
|
|
|
writer->add_null();
|
|
|
|
else if (r_used_pq == get_r_loops())
|
2015-04-12 03:48:42 +02:00
|
|
|
writer->add_bool(true);
|
|
|
|
else if (r_used_pq == 0)
|
|
|
|
writer->add_bool(false);
|
|
|
|
else
|
|
|
|
writer->add_str(varied_str);
|
|
|
|
|
2017-07-12 16:16:44 +02:00
|
|
|
if (!get_r_loops())
|
|
|
|
writer->add_member("r_output_rows").add_null();
|
|
|
|
else
|
2019-05-01 13:14:50 +02:00
|
|
|
writer->add_member("r_output_rows").add_ll(
|
|
|
|
(longlong) rint((double)r_output_rows / get_r_loops()));
|
2015-04-12 03:48:42 +02:00
|
|
|
|
|
|
|
if (sort_passes)
|
2015-08-07 16:41:35 +02:00
|
|
|
{
|
2019-05-01 13:14:50 +02:00
|
|
|
writer->add_member("r_sort_passes").add_ll(
|
|
|
|
(longlong) rint((double)sort_passes / get_r_loops()));
|
2015-08-07 16:41:35 +02:00
|
|
|
}
|
2015-04-12 03:48:42 +02:00
|
|
|
|
|
|
|
if (sort_buffer_size != 0)
|
|
|
|
{
|
|
|
|
writer->add_member("r_buffer_size");
|
|
|
|
if (sort_buffer_size == ulonglong(-1))
|
|
|
|
writer->add_str(varied_str);
|
|
|
|
else
|
|
|
|
writer->add_size(sort_buffer_size);
|
|
|
|
}
|
2020-02-28 07:16:13 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2020-03-10 00:26:38 +01:00
|
|
|
if (r_sort_keys_packed)
|
|
|
|
str->append("packed_sort_key");
|
|
|
|
else
|
|
|
|
str->append("sort_key");
|
2020-02-28 07:16:13 +01:00
|
|
|
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");
|
2015-04-12 03:48:42 +02:00
|
|
|
}
|
|
|
|
|
2019-11-09 19:03:23 +01:00
|
|
|
void attach_gap_time_tracker(THD *thd, Gap_time_tracker *gap_tracker,
|
|
|
|
ulonglong timeval)
|
|
|
|
{
|
|
|
|
thd->gap_tracker_data.bill_to= gap_tracker;
|
|
|
|
thd->gap_tracker_data.start_time= timeval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void process_gap_time_tracker(THD *thd, ulonglong timeval)
|
|
|
|
{
|
|
|
|
if (thd->gap_tracker_data.bill_to)
|
|
|
|
{
|
|
|
|
thd->gap_tracker_data.bill_to->log_time(thd->gap_tracker_data.start_time,
|
|
|
|
timeval);
|
|
|
|
thd->gap_tracker_data.bill_to= NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|