[Commits] 0fe2cfd45e6: Address review input
revision-id: 0fe2cfd45e616e93d47aa9e224db468f32dd391a (mariadb-10.6.1-129-g0fe2cfd45e6) parent(s): 5cbab7b371bd4a10eb6f8fd3e7d90339cc5653e3 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2021-09-11 19:43:08 +0300 message: Address review input --- mysql-test/main/statistics_json.result | 48 ++++++++++++++++++++++++++++++++++ mysql-test/main/statistics_json.test | 23 ++++++++++++++++ sql/opt_histogram_json.cc | 5 +++- sql/opt_histogram_json.h | 6 ++--- 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/statistics_json.result b/mysql-test/main/statistics_json.result index 05b9020d62f..067c2d47204 100644 --- a/mysql-test/main/statistics_json.result +++ b/mysql-test/main/statistics_json.result @@ -7397,3 +7397,51 @@ id select_type table type possible_keys key key_len ref rows r_rows filtered r_f set histogram_type=@save_histogram_type; set histogram_size=@save_histogram_size; DROP SCHEMA world; +use test; +create table t10 ( +a varchar(10) +); +# +# Histograms are not collected for empty tables: +# +analyze table t10 persistent for all; +Table Op Msg_type Msg_text +test.t10 analyze status Engine-independent statistics collected +test.t10 analyze status Table is already up to date +select histogram +from mysql.column_stats where table_name='t10' and db_name=database(); +histogram +NULL +# +# Try with n_buckets > n_rows +# +insert into t10 values ('Berlin'),('Paris'),('Rome'); +set histogram_size=10, histogram_type='json_hb'; +analyze table t10 persistent for all; +Table Op Msg_type Msg_text +test.t10 analyze status Engine-independent statistics collected +test.t10 analyze status OK +select histogram +from mysql.column_stats where table_name='t10' and db_name=database(); +histogram +{ + "histogram_hb_v2": [ + { + "start": "Berlin", + "size": 0.333333333, + "ndv": 1 + }, + { + "start": "Paris", + "size": 0.333333333, + "ndv": 1 + }, + { + "start": "Rome", + "end": "Rome", + "size": 0.333333333, + "ndv": 1 + } + ] +} +drop table t10; diff --git a/mysql-test/main/statistics_json.test b/mysql-test/main/statistics_json.test index edb26219bcd..f279296b7d5 100644 --- a/mysql-test/main/statistics_json.test +++ b/mysql-test/main/statistics_json.test @@ -149,3 +149,26 @@ set histogram_type=@save_histogram_type; set histogram_size=@save_histogram_size; DROP SCHEMA world; +use test; + +create table t10 ( + a varchar(10) +); + +--echo # +--echo # Histograms are not collected for empty tables: +--echo # +analyze table t10 persistent for all; +select histogram +from mysql.column_stats where table_name='t10' and db_name=database(); + +--echo # +--echo # Try with n_buckets > n_rows +--echo # +insert into t10 values ('Berlin'),('Paris'),('Rome'); +set histogram_size=10, histogram_type='json_hb'; +analyze table t10 persistent for all; +select histogram +from mysql.column_stats where table_name='t10' and db_name=database(); + +drop table t10; diff --git a/sql/opt_histogram_json.cc b/sql/opt_histogram_json.cc index 3cfb8ae6b88..979fca22a40 100644 --- a/sql/opt_histogram_json.cc +++ b/sql/opt_histogram_json.cc @@ -59,6 +59,8 @@ class Histogram_json_builder : public Histogram_builder : Histogram_builder(col, col_len, rows), histogram(hist) { bucket_capacity= records / histogram->get_width(); + if (bucket_capacity == 0) + bucket_capacity= 1; hist_width= histogram->get_width(); n_buckets_collected= 0; bucket.ndv= 0; @@ -227,7 +229,8 @@ class Histogram_json_builder : public Histogram_builder writer.end_object(); Binary_string *json_string= (Binary_string *) writer.output.get_string(); histogram->set_json_text(n_buckets_collected, - (uchar *) json_string->c_ptr()); + json_string->c_ptr(), + (size_t)json_string->length()); } }; diff --git a/sql/opt_histogram_json.h b/sql/opt_histogram_json.h index 83f107c13ac..b673bcc6b95 100644 --- a/sql/opt_histogram_json.h +++ b/sql/opt_histogram_json.h @@ -113,11 +113,11 @@ class Histogram_json_hb : public Histogram_base double range_selectivity(Field *field, key_range *min_endp, key_range *max_endp) override; - void set_json_text(ulonglong sz, uchar *json_text_arg) + void set_json_text(ulonglong sz, const char *json_text_arg, + size_t json_text_len) { size= (size_t) sz; - json_text.assign((const char*)json_text_arg, - strlen((const char*)json_text_arg)); + json_text.assign(json_text_arg, json_text_len); } private:
participants (1)
-
psergey