Commit 917b2239 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-406: ANALYZE $stmt

- Testcase for ANALYZE UNION
- Provide r_rows for union result.
parent 5621aa32
......@@ -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;
......@@ -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,7 +546,7 @@ 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;
ha_rows avg_rows= tracker.get_avg_rows();
item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows,
MY_INT64_NUM_DECIMAL_DIGITS));
}
......
......@@ -27,6 +27,11 @@ class Table_access_tracker
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;
}
};
......
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