Skip to content

Commit

Permalink
MDEV-7904: ANALYZE FORMAT=JSON doesn't print r_rows for union output
Browse files Browse the repository at this point in the history
Print r_rows. There is no table tracking for reading from tmp table, yet.
  • Loading branch information
spetrunia committed Apr 3, 2015
1 parent a220905 commit 47c344b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
58 changes: 58 additions & 0 deletions mysql-test/r/analyze_format_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,61 @@ ANALYZE
}
}
drop table t1,t2,t3,t4;
#
# MDEV-7904: ANALYZE FORMAT=JSON SELECT .. UNION SELECT doesn't print r_rows for union output
#
create table t0 (a int);
INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int);
INSERT INTO t1 select * from t0;
analyze format=json (select * from t1 A where a<5) union (select * from t1 B where a in (2,3));
ANALYZE
{
"query_block": {
"union_result": {
"table_name": "<union1,2>",
"access_type": "ALL",
"r_loops": 1,
"r_rows": 5,
"query_specifications": [
{
"query_block": {
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"table": {
"table_name": "A",
"access_type": "ALL",
"r_loops": 1,
"rows": 10,
"r_rows": 10,
"r_total_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 50,
"attached_condition": "(A.a < 5)"
}
}
},
{
"query_block": {
"select_id": 2,
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"table": {
"table_name": "B",
"access_type": "ALL",
"r_loops": 1,
"rows": 10,
"r_rows": 10,
"r_total_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 20,
"attached_condition": "(B.a in (2,3))"
}
}
}
]
}
}
}
drop table t0, t1;
16 changes: 16 additions & 0 deletions mysql-test/t/analyze_format_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,19 @@ select * from t1, t2 where (t2.key1 between t1.lb1 and t1.rb1) and
(t2.key3=t1.c1 OR t2.key4=t1.c2);

drop table t1,t2,t3,t4;

--echo #
--echo # MDEV-7904: ANALYZE FORMAT=JSON SELECT .. UNION SELECT doesn't print r_rows for union output
--echo #
create table t0 (a int);
INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

create table t1 (a int);
INSERT INTO t1 select * from t0;

--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/
analyze format=json (select * from t1 A where a<5) union (select * from t1 B where a in (2,3));

drop table t0, t1;


17 changes: 17 additions & 0 deletions sql/sql_explain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,23 @@ void Explain_union::print_explain_json(Explain_query *query,
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)
{
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++)
Expand Down

0 comments on commit 47c344b

Please sign in to comment.