diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2014-03-26 21:05:31 +0400 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2014-03-26 21:05:31 +0400 |
commit | dee11f9633be3091bd7d3c0b868e4ea1efe4ac7f (patch) | |
tree | a23b935db0499da2014882be1ec196defea77b92 /sql/sql_statistics.h | |
parent | ad842b5f058d5342c22cdc86542baa2ae9db5e70 (diff) | |
download | mariadb-git-dee11f9633be3091bd7d3c0b868e4ea1efe4ac7f.tar.gz |
MDEV-4362: {division by zero when lookup constant is outside the value table}
- Fix Histogram::point_selectivity() to work in the case where the
passed value_pos=0 (or 1) and the first (or the last) bucket in the
histogram has zero value-range (i.e one value).
Diffstat (limited to 'sql/sql_statistics.h')
-rw-r--r-- | sql/sql_statistics.h | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/sql/sql_statistics.h b/sql/sql_statistics.h index 936f23f1091..da6a9035b44 100644 --- a/sql/sql_statistics.h +++ b/sql/sql_statistics.h @@ -302,16 +302,27 @@ public: (max + 1 == get_width() ? 1.0 : (get_value(max) * inv_prec_factor)) - (min == 0 ? 0.0 : (get_value(min-1) * inv_prec_factor)); - /* - So: - - each bucket has the same #rows - - values are unformly distributed across the [min_value,max_value] domain. - - If a bucket has value range that's N times bigger then average, than - each value will have to have N times fewer rows than average. - */ - DBUG_ASSERT(current_bucket_width); - sel= avg_sel * avg_bucket_width / current_bucket_width; + if (current_bucket_width < 1e-16) + { + /* + A special case: we are at the first (or the last) bucket in the + histogram, the bucket's value range is a singlepoint [x,x], and + pos_value=0 (for the first bucket) or pos_value=1 (for the last). + */ + sel= avg_sel; + } + else + { + /* + So: + - each bucket has the same #rows + - values are unformly distributed across the [min_value,max_value] domain. + + If a bucket has value range that's N times bigger then average, than + each value will have to have N times fewer rows than average. + */ + sel= avg_sel * avg_bucket_width / current_bucket_width; + } /* (Q: if we just follow this proportion we may end up in a situation |