summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2015-04-04 00:47:10 +0300
committerSergei Petrunia <psergey@askmonty.org>2015-04-04 00:47:10 +0300
commit47c344b00fa6878e5d1ce4235f8016a1ec995967 (patch)
tree2317196c8100ca658794b54c1fb5b1c8f0596a16
parenta220905083c382bec096dd1435b6620d348bbfeb (diff)
downloadmariadb-git-47c344b00fa6878e5d1ce4235f8016a1ec995967.tar.gz
MDEV-7904: ANALYZE FORMAT=JSON doesn't print r_rows for union output
Print r_rows. There is no table tracking for reading from tmp table, yet.
-rw-r--r--mysql-test/r/analyze_format_json.result58
-rw-r--r--mysql-test/t/analyze_format_json.test16
-rw-r--r--sql/sql_explain.cc17
3 files changed, 91 insertions, 0 deletions
diff --git a/mysql-test/r/analyze_format_json.result b/mysql-test/r/analyze_format_json.result
index 4d3f6752b7c..48ebceb1959 100644
--- a/mysql-test/r/analyze_format_json.result
+++ b/mysql-test/r/analyze_format_json.result
@@ -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;
diff --git a/mysql-test/t/analyze_format_json.test b/mysql-test/t/analyze_format_json.test
index 8d838d0eee2..7a3c11b13c5 100644
--- a/mysql-test/t/analyze_format_json.test
+++ b/mysql-test/t/analyze_format_json.test
@@ -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;
+
+
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index c1f1b0218b5..900017e2476 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -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++)