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;
...@@ -552,11 +552,18 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai ...@@ -552,11 +552,18 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
/* `r_rows` */ /* `r_rows` */
if (is_analyze) if (is_analyze)
{
if (!tracker.has_scans())
{
item_list.push_back(item_null);
}
else
{ {
ha_rows avg_rows= tracker.get_avg_rows(); ha_rows avg_rows= tracker.get_avg_rows();
item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows, item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows,
MY_INT64_NUM_DECIMAL_DIGITS)); MY_INT64_NUM_DECIMAL_DIGITS));
} }
}
/* `filtered` */ /* `filtered` */
if (explain_flags & DESCRIBE_EXTENDED || is_analyze) if (explain_flags & DESCRIBE_EXTENDED || is_analyze)
...@@ -571,6 +578,12 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai ...@@ -571,6 +578,12 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
/* `r_filtered` */ /* `r_filtered` */
if (is_analyze) if (is_analyze)
{
if (!tracker.has_scans())
{
item_list.push_back(item_null);
}
else
{ {
double r_filtered; double r_filtered;
if (tracker.r_rows > 0) if (tracker.r_rows > 0)
...@@ -579,6 +592,7 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai ...@@ -579,6 +592,7 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
r_filtered= 100.0; r_filtered= 100.0;
item_list.push_back(new Item_float(r_filtered, 2)); item_list.push_back(new Item_float(r_filtered, 2));
} }
}
/* `Extra` */ /* `Extra` */
StringBuffer<256> extra_buf; StringBuffer<256> extra_buf;
......
...@@ -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