Commit 8f8585b0 authored by Sergei Petrunia's avatar Sergei Petrunia

Fixup 2 for MDEV-18478 ANALYZE for statement part#2

We may get r_index_rows=0. Do not divide by 0 in this case,
as the result is undefined. Produce "r_total_filtered": 100 instead.
parent f7abf4a6
......@@ -686,7 +686,7 @@ ANALYZE
"r_other_time_ms": "REPLACED",
"r_engine_stats": REPLACED,
"filtered": 8.529999733,
"r_total_filtered": 0,
"r_total_filtered": 100,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"r_icp_filtered": 100,
"attached_condition": "t1.fl2 = 0",
......
......@@ -2071,6 +2071,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
writer->add_member("rows").add_ull(rows);
double r_index_rows; /* protected by have_icp_or_rowid_filter */
bool r_index_rows_is_zero; /* also protected by have_icp_or_rowid_filter */
bool have_icp_or_rowid_filter= false;
/* `r_index_rows` and `r_rows` */
if (is_analyze)
......@@ -2092,13 +2093,17 @@ void Explain_table_access::print_explain_json(Explain_query *query,
Pushed Index Condition is checked before checking the Rowid Filter,
so try getting it first.
*/
r_index_rows= file->handler_stats->icp_attempts / loops;
ulonglong val= file->handler_stats->icp_attempts;
r_index_rows_is_zero= (val == 0);
r_index_rows= val / loops;
have_icp_or_rowid_filter= true;
}
else if (rowid_filter)
{
/* If ICP wasn't used, get the number from Rowid Filter */
r_index_rows= rowid_filter->tracker->get_container_lookups() / loops;
uint val= rowid_filter->tracker->get_container_lookups();
r_index_rows_is_zero= (val == 0);
r_index_rows= val / loops;
have_icp_or_rowid_filter= true;
}
......@@ -2181,7 +2186,10 @@ void Explain_table_access::print_explain_json(Explain_query *query,
else
out_rows= tracker.get_avg_rows_after_where();
r_total_filtered= out_rows* 100.0 / r_index_rows;
if (r_index_rows_is_zero)
r_total_filtered= 100.0;
else
r_total_filtered= out_rows* 100.0 / r_index_rows;
}
else if (have_r_filtered)
r_total_filtered= r_filtered;
......
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