1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-27699 ANALYZE FORMAT=JSON fields are incorrect for UNION ALL queries

UNION ALL queries are a subject of optimization introduced in MDEV-334
when creation of a temporary table is skipped.
While there is a check for this optimization in Explain_union::print_explain()
there was no such in Explain_union::print_explain_json(). This resulted in
printing irrelevant data like:
  "union_result": {
    "table_name": "<union2,3>",
    "access_type": "ALL",
    "r_loops": 0,
    "r_rows": null
in case when creation of the temporary table was actually optimized out.
This commits adds a check whether the temporary table was actually created
during the UNION ALL processing and eliminates printing of the irrelevant data.
This commit is contained in:
Oleg Smirnov
2022-04-13 19:56:34 +07:00
parent 83516a33a8
commit 7498978e6a
6 changed files with 20 additions and 78 deletions

View File

@ -581,27 +581,29 @@ void Explain_union::print_explain_json(Explain_query *query,
else
writer->add_member("union_result").start_object();
// using_temporary_table
make_union_table_name(table_name_buffer);
writer->add_member("table_name").add_str(table_name_buffer);
writer->add_member("access_type").add_str("ALL"); // not very useful
/* r_loops (not present in tabular output) */
if (is_analyze)
if (using_tmp)
{
writer->add_member("r_loops").add_ll(fake_select_lex_tracker.get_loops());
}
make_union_table_name(table_name_buffer);
writer->add_member("table_name").add_str(table_name_buffer);
writer->add_member("access_type").add_str("ALL"); // not very useful
/* `r_rows` */
if (is_analyze)
{
writer->add_member("r_rows");
if (fake_select_lex_tracker.has_scans())
writer->add_double(fake_select_lex_tracker.get_avg_rows());
else
writer->add_null();
}
/* r_loops (not present in tabular output) */
if (is_analyze)
{
writer->add_member("r_loops").add_ll(
fake_select_lex_tracker.get_loops());
}
/* `r_rows` */
if (is_analyze)
{
writer->add_member("r_rows");
if (fake_select_lex_tracker.has_scans())
writer->add_double(fake_select_lex_tracker.get_avg_rows());
else
writer->add_null();
}
}
writer->add_member("query_specifications").start_array();
for (int i= 0; i < (int) union_members.elements(); i++)