Commit 382250c0 authored by Sergei Petrunia's avatar Sergei Petrunia

Address review input

parent cf8927e9
...@@ -7397,3 +7397,51 @@ id select_type table type possible_keys key key_len ref rows r_rows filtered r_f ...@@ -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_type=@save_histogram_type;
set histogram_size=@save_histogram_size; set histogram_size=@save_histogram_size;
DROP SCHEMA world; 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;
...@@ -149,3 +149,26 @@ set histogram_type=@save_histogram_type; ...@@ -149,3 +149,26 @@ set histogram_type=@save_histogram_type;
set histogram_size=@save_histogram_size; set histogram_size=@save_histogram_size;
DROP SCHEMA world; 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;
...@@ -59,6 +59,8 @@ class Histogram_json_builder : public Histogram_builder ...@@ -59,6 +59,8 @@ class Histogram_json_builder : public Histogram_builder
: Histogram_builder(col, col_len, rows), histogram(hist) : Histogram_builder(col, col_len, rows), histogram(hist)
{ {
bucket_capacity= records / histogram->get_width(); bucket_capacity= records / histogram->get_width();
if (bucket_capacity == 0)
bucket_capacity= 1;
hist_width= histogram->get_width(); hist_width= histogram->get_width();
n_buckets_collected= 0; n_buckets_collected= 0;
bucket.ndv= 0; bucket.ndv= 0;
...@@ -227,7 +229,8 @@ class Histogram_json_builder : public Histogram_builder ...@@ -227,7 +229,8 @@ class Histogram_json_builder : public Histogram_builder
writer.end_object(); writer.end_object();
Binary_string *json_string= (Binary_string *) writer.output.get_string(); Binary_string *json_string= (Binary_string *) writer.output.get_string();
histogram->set_json_text(n_buckets_collected, histogram->set_json_text(n_buckets_collected,
(uchar *) json_string->c_ptr()); json_string->c_ptr(),
(size_t)json_string->length());
} }
}; };
......
...@@ -113,11 +113,11 @@ class Histogram_json_hb : public Histogram_base ...@@ -113,11 +113,11 @@ class Histogram_json_hb : public Histogram_base
double range_selectivity(Field *field, key_range *min_endp, double range_selectivity(Field *field, key_range *min_endp,
key_range *max_endp) override; 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; size= (size_t) sz;
json_text.assign((const char*)json_text_arg, json_text.assign(json_text_arg, json_text_len);
strlen((const char*)json_text_arg));
} }
private: private:
......
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