Commit 7498978e authored by Oleg Smirnov's avatar Oleg Smirnov

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.
parent 83516a33
......@@ -4050,10 +4050,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<union1,4>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......
......@@ -10742,8 +10742,6 @@ EXPLAIN
"materialized": {
"query_block": {
"union_result": {
"table_name": "<union2,3>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -14718,8 +14716,6 @@ EXPLAIN
"materialized": {
"query_block": {
"union_result": {
"table_name": "<union2,3>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -14940,8 +14936,6 @@ EXPLAIN
"materialized": {
"query_block": {
"union_result": {
"table_name": "<union2,3,4>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......
......@@ -247,8 +247,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......
......@@ -1304,8 +1304,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<unit1>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -1525,8 +1523,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -1589,8 +1585,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -1633,8 +1627,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<union1,2,3>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -1677,10 +1669,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<unit1>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......@@ -1908,10 +1896,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......@@ -1976,10 +1960,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......@@ -2022,10 +2002,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<union1,2,3>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......
......@@ -1302,8 +1302,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<unit1>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -1523,8 +1521,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -1587,8 +1583,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -1631,8 +1625,6 @@ EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<union1,2,3>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
......@@ -1675,10 +1667,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<unit1>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......@@ -1906,10 +1894,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......@@ -1974,10 +1958,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......@@ -2020,10 +2000,6 @@ ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<union1,2,3>",
"access_type": "ALL",
"r_loops": 0,
"r_rows": null,
"query_specifications": [
{
"query_block": {
......
......@@ -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++)
......
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