summaryrefslogtreecommitdiff
path: root/sql/opt_histogram_json.cc
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2021-10-11 17:07:28 +0300
committerSergei Petrunia <psergey@askmonty.org>2022-01-19 18:10:11 +0300
commit93d59804355d5a4bce5a971009af754068c6308f (patch)
tree3b42bed631d630d133e1b377b08142fa400c636f /sql/opt_histogram_json.cc
parent3936dc335328be8a4fdee9d00318d1b4318a21ff (diff)
downloadmariadb-git-93d59804355d5a4bce5a971009af754068c6308f.tar.gz
MDEV-26709: JSON histogram may contain bucketS than histogram_size allows
When computing bucket_capacity= records/histogram->get_width(), round the value UP, not down.
Diffstat (limited to 'sql/opt_histogram_json.cc')
-rw-r--r--sql/opt_histogram_json.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/sql/opt_histogram_json.cc b/sql/opt_histogram_json.cc
index 8bea920ecbf..944c5ffb353 100644
--- a/sql/opt_histogram_json.cc
+++ b/sql/opt_histogram_json.cc
@@ -100,7 +100,7 @@ class Histogram_json_builder : public Histogram_builder
/*
Number of rows that we intend to have in the bucket. That is, this is
- n_rows_in_table / histo_width
+ n_rows_in_table / hist_width
Actual number of rows in the buckets we produce may vary because of
"popular values" and rounding.
@@ -129,7 +129,14 @@ public:
ha_rows rows)
: Histogram_builder(col, col_len, rows), histogram(hist)
{
- bucket_capacity= records / histogram->get_width();
+ /*
+ When computing number of rows in the bucket, round it UP. This way, we
+ will not end up with a histogram that has more buckets than intended.
+
+ We may end up producing a histogram with fewer buckets than intended, but
+ this is considered tolerable.
+ */
+ bucket_capacity= round(rows2double(records) / histogram->get_width() + 0.5);
if (bucket_capacity == 0)
bucket_capacity= 1;
hist_width= histogram->get_width();