diff --git a/mysql-test/t/analyze_stmt.test b/mysql-test/t/analyze_stmt.test index 61ebc567057..135163ca128 100644 --- a/mysql-test/t/analyze_stmt.test +++ b/mysql-test/t/analyze_stmt.test @@ -28,4 +28,11 @@ analyze update t1 set b=100+b where a in (6,7,8); select * from t1; drop table t1; +--echo # Check that UNION works +create table t1(a int, b int); +insert into t1 select a,a from t0; +analyze (select * from t1 A where a<5) union (select * from t1 B where a in (5,6)); +analyze (select * from t1 A where a<5) union (select * from t1 B where a in (1,2)); +drop table t1; + drop table t0; diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 1402c76db01..dcec94927b4 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -291,7 +291,11 @@ int Explain_union::print_explain(Explain_query *query, /* `r_rows` */ if (is_analyze) - item_list.push_back(item_null); + { + ha_rows avg_rows= fake_select_lex_tracker.get_avg_rows(); + item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows, + MY_INT64_NUM_DECIMAL_DIGITS)); + } /* `filtered` */ if (explain_flags & DESCRIBE_EXTENDED || is_analyze) @@ -542,8 +546,8 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai /* `r_rows` */ if (is_analyze) { - ha_rows avg_rows= tracker.r_scans ? round((double) tracker.r_rows / tracker.r_scans): 0; - item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows, + ha_rows avg_rows= tracker.get_avg_rows(); + item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows, MY_INT64_NUM_DECIMAL_DIGITS)); } diff --git a/sql/sql_explain.h b/sql/sql_explain.h index 7970d778a21..203235f9f5c 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -27,6 +27,11 @@ public: ha_rows r_rows; /* How many rows we've got after that */ ha_rows r_rows_after_table_cond; /* Rows after applying the table condition */ ha_rows r_rows_after_where; /* Rows after applying attached part of WHERE */ + + ha_rows get_avg_rows() + { + return r_scans ? round((double) r_rows / r_scans): 0; + } };