Commit c3cfb691 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-406: ANALYZE $stmt: Scans that never executed will have r_rows=NULL

parent 06a87d77
...@@ -74,4 +74,9 @@ analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1; ...@@ -74,4 +74,9 @@ analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00
2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 3 100.00 33.33 Using where 2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 3 100.00 33.33 Using where
# Try a subquery that is never executed
analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1 where t1.a > 5;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 3 100.00 0.00 Using where
2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 NULL 100.00 NULL Using where
drop table t0,t1; drop table t0,t1;
...@@ -58,5 +58,8 @@ insert into t1 values (1,1),(2,2),(3,3); ...@@ -58,5 +58,8 @@ insert into t1 values (1,1),(2,2),(3,3);
--echo # See .test file for the right values of r_rows and r_filtered. --echo # See .test file for the right values of r_rows and r_filtered.
analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1; analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1;
--echo # Try a subquery that is never executed
analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1 where t1.a > 5;
drop table t0,t1; drop table t0,t1;
...@@ -553,9 +553,16 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai ...@@ -553,9 +553,16 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
/* `r_rows` */ /* `r_rows` */
if (is_analyze) if (is_analyze)
{ {
ha_rows avg_rows= tracker.get_avg_rows(); if (!tracker.has_scans())
item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows, {
MY_INT64_NUM_DECIMAL_DIGITS)); item_list.push_back(item_null);
}
else
{
ha_rows avg_rows= tracker.get_avg_rows();
item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows,
MY_INT64_NUM_DECIMAL_DIGITS));
}
} }
/* `filtered` */ /* `filtered` */
...@@ -572,12 +579,19 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai ...@@ -572,12 +579,19 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
/* `r_filtered` */ /* `r_filtered` */
if (is_analyze) if (is_analyze)
{ {
double r_filtered; if (!tracker.has_scans())
if (tracker.r_rows > 0) {
r_filtered= 100.0 * (double)tracker.r_rows_after_table_cond / tracker.r_rows; item_list.push_back(item_null);
}
else else
r_filtered= 100.0; {
item_list.push_back(new Item_float(r_filtered, 2)); double r_filtered;
if (tracker.r_rows > 0)
r_filtered= 100.0 * (double)tracker.r_rows_after_table_cond / tracker.r_rows;
else
r_filtered= 100.0;
item_list.push_back(new Item_float(r_filtered, 2));
}
} }
/* `Extra` */ /* `Extra` */
......
...@@ -28,6 +28,7 @@ public: ...@@ -28,6 +28,7 @@ public:
ha_rows r_rows_after_table_cond; /* Rows after applying the table condition */ 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 r_rows_after_where; /* Rows after applying attached part of WHERE */
bool has_scans() { return (r_scans != 0); }
ha_rows get_avg_rows() ha_rows get_avg_rows()
{ {
return r_scans ? (ha_rows)rint((double) r_rows / r_scans): 0; return r_scans ? (ha_rows)rint((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