revision-id: ef70a780ac663f56412183ef47cfac2d4ae84738 (mariadb-10.6.0-413-gef70a780ac6) parent(s): d809e220eb2a31f07016210186600fa9dfe56232 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2021-08-27 16:57:22 +0300 message: Rename histogram_type=JSON to JSON_HB --- mysql-test/main/statistics_json.result | 8 ++++---- mysql-test/main/statistics_json.test | 6 +++--- mysql-test/main/system_mysql_db.result | 3 +-- mysql-test/main/system_mysql_db_fix50030.result | 2 +- scripts/mysql_system_tables.sql | 2 +- sql/item_strfunc.cc | 13 ++++++++----- sql/sql_statistics.cc | 10 +++++----- sql/sql_statistics.h | 4 ++-- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/mysql-test/main/statistics_json.result b/mysql-test/main/statistics_json.result index 5bf5c98a206..9eaa195c534 100644 --- a/mysql-test/main/statistics_json.result +++ b/mysql-test/main/statistics_json.result @@ -4,9 +4,9 @@ set @SINGLE_PREC_TYPE='single_prec_hb'; set @DOUBLE_PREC_TYPE='double_prec_hb'; set @DEFAULT_HIST_TYPE=@@histogram_type; -set @SINGLE_PREC_TYPE='JSON'; -set @DOUBLE_PREC_TYPE='JSON'; -set @DEFAULT_HIST_TYPE='JSON'; +set @SINGLE_PREC_TYPE='JSON_HB'; +set @DOUBLE_PREC_TYPE='JSON_HB'; +set @DEFAULT_HIST_TYPE='JSON_HB'; drop table if exists t1,t2; set @save_use_stat_tables=@@use_stat_tables; set @save_histogram_size=@@global.histogram_size; @@ -232,7 +232,7 @@ nulls_ratio, avg_frequency, hist_size, hist_type, HEX(histogram) FROM mysql.column_stats; db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) -test t1 a 0 49 0.0000 1.0000 4 JSON 5B0A20202239222C0A2020223139222C0A2020223331222C0A2020223430220A5D +test t1 a 0 49 0.0000 1.0000 4 JSON_HB 5B0A20202239222C0A2020223139222C0A2020223331222C0A2020223430220A5D test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 4 JSON 5B0A20202276767676767676767676767676222C0A20202277777777777777777777777777777777777777777777777777777777222C0A202022797979222C0A2020227A7A7A7A7A7A7A7A7A7A7A7A7A7A7A7A7A7A220A5D test t1 c aaaa dddddddd 0.1250 7.0000 4 JSON 5B0A20202261616161222C0A202022626262626262222C0A202022636363636363636363222C0A2020226464646464646464220A5D test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 4 JSON 5B0A202022313938392D30332D3132222C0A202022313939302D30352D3135222C0A202022313939302D30352D3135222C0A202022313939392D30372D3233220A5D diff --git a/mysql-test/main/statistics_json.test b/mysql-test/main/statistics_json.test index 4bda3255b1c..1fc42155ece 100644 --- a/mysql-test/main/statistics_json.test +++ b/mysql-test/main/statistics_json.test @@ -2,7 +2,7 @@ --echo # Test that we can store JSON arrays in histogram field mysql.column_stats when histogram_type=JSON --echo # -let $histogram_type_override='JSON'; +let $histogram_type_override='JSON_HB'; --source statistics.test --source include/have_stat_tables.inc @@ -76,7 +76,7 @@ use world; --enable_result_log --enable_query_log -set histogram_type='JSON'; +set histogram_type='JSON_HB'; set histogram_size=50; --disable_result_log ANALYZE TABLE Country, City, CountryLanguage persistent for all; @@ -91,4 +91,4 @@ analyze select * from Country where 'Code' < 'BBC'; set histogram_type=@save_histogram_type; set histogram_size=@save_histogram_size; -DROP SCHEMA world; \ No newline at end of file +DROP SCHEMA world; diff --git a/mysql-test/main/system_mysql_db.result b/mysql-test/main/system_mysql_db.result index b756dfcf45e..cfcd738e7cc 100644 --- a/mysql-test/main/system_mysql_db.result +++ b/mysql-test/main/system_mysql_db.result @@ -234,8 +234,7 @@ column_stats CREATE TABLE `column_stats` ( `avg_length` decimal(12,4) DEFAULT NULL, `avg_frequency` decimal(12,4) DEFAULT NULL, `hist_size` tinyint(3) unsigned DEFAULT NULL, - `hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON') COLLATE utf8mb3_bin DEFAULT NULL, - `histogram` blob DEFAULT NULL, + `hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB') COLLATE utf8mb3_bin DEFAULT NULL, `histogram` blob DEFAULT NULL, PRIMARY KEY (`db_name`,`table_name`,`column_name`) ) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns' show create table index_stats; diff --git a/mysql-test/main/system_mysql_db_fix50030.result b/mysql-test/main/system_mysql_db_fix50030.result index 4e038849cf6..b60253c42ad 100644 --- a/mysql-test/main/system_mysql_db_fix50030.result +++ b/mysql-test/main/system_mysql_db_fix50030.result @@ -276,7 +276,7 @@ column_stats CREATE TABLE `column_stats` ( `avg_length` decimal(12,4) DEFAULT NULL, `avg_frequency` decimal(12,4) DEFAULT NULL, `hist_size` tinyint(3) unsigned DEFAULT NULL, - `hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON') COLLATE utf8mb3_bin DEFAULT NULL, + `hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB') COLLATE utf8mb3_bin DEFAULT NULL, `histogram` blob DEFAULT NULL, PRIMARY KEY (`db_name`,`table_name`,`column_name`) ) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns' diff --git a/scripts/mysql_system_tables.sql b/scripts/mysql_system_tables.sql index e31f3372b5f..e5b824894a0 100644 --- a/scripts/mysql_system_tables.sql +++ b/scripts/mysql_system_tables.sql @@ -314,7 +314,7 @@ DROP TABLE tmp_proxies_priv; CREATE TABLE IF NOT EXISTS table_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) engine=Aria transactional=0 CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables'; -CREATE TABLE IF NOT EXISTS column_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varbinary(255) DEFAULT NULL, max_value varbinary(255) DEFAULT NULL, nulls_ratio decimal(12,4) DEFAULT NULL, avg_length decimal(12,4) DEFAULT NULL, avg_frequency decimal(12,4) DEFAULT NULL, hist_size tinyint unsigned, hist_type enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON'), histogram blob, PRIMARY KEY (db_name,table_name,column_name) ) engine=Aria transactional=0 CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns'; +CREATE TABLE IF NOT EXISTS column_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varbinary(255) DEFAULT NULL, max_value varbinary(255) DEFAULT NULL, nulls_ratio decimal(12,4) DEFAULT NULL, avg_length decimal(12,4) DEFAULT NULL, avg_frequency decimal(12,4) DEFAULT NULL, hist_size tinyint unsigned, hist_type enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB'), histogram blob, PRIMARY KEY (db_name,table_name,column_name) ) engine=Aria transactional=0 CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns'; CREATE TABLE IF NOT EXISTS index_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency decimal(12,4) DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) engine=Aria transactional=0 CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes'; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 1f31de8fd52..9f406a7a1cf 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -496,7 +496,7 @@ String *Item_func_from_base64::val_str(String *str) const char *histogram_types[] = - {"SINGLE_PREC_HB", "DOUBLE_PREC_HB", "JSON", 0}; + {"SINGLE_PREC_HB", "DOUBLE_PREC_HB", "JSON_HB", 0}; static TYPELIB histogram_types_typelib= { array_elements(histogram_types), "histogram_types", @@ -526,6 +526,13 @@ String *Item_func_decode_histogram::val_str(String *str) null_value= 1; return 0; } + + if (type == JSON_HB) + { + // It's a JSON histogram. Return it as-is. + return res; + } + if (type == DOUBLE_PREC_HB && res->length() % 2 != 0) res->length(res->length() - 1); // one byte is unused @@ -534,10 +541,6 @@ String *Item_func_decode_histogram::val_str(String *str) str->length(0); char numbuf[32]; const uchar *p= (uchar*)res->c_ptr_safe(); - if (type == JSON) - { - return res; - } for (i= 0; i < res->length(); i++) { double val; diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 43cf4d7dbdd..fb89bf513c1 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -193,7 +193,7 @@ TABLE_FIELD_TYPE column_stat_fields[COLUMN_STAT_N_FIELDS] = }, { { STRING_WITH_LEN("hist_type") }, - { STRING_WITH_LEN("enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON')") }, + { STRING_WITH_LEN("enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB')") }, { STRING_WITH_LEN("utf8mb3") } }, { @@ -1234,7 +1234,7 @@ class Column_stat: public Stat_table case DOUBLE_PREC_HB: hist = new (mem_root) Histogram_binary(); break; - case JSON: + case JSON_HB: hist = new (mem_root) Histogram_json(); break; default: @@ -2046,7 +2046,7 @@ class Histogram_builder_json : public Histogram_builder Histogram_base *create_histogram(Histogram_type hist_type) { // assumes the caller already checked for invalid histograms - if (hist_type == JSON) + if (hist_type == JSON_HB) return new Histogram_json; else return new Histogram_binary; @@ -2207,7 +2207,7 @@ class Count_distinct_field: public Sql_alloc */ void walk_tree_with_histogram(ha_rows rows) { - if (table_field->collected_stats->histogram_->get_type() == JSON) + if (table_field->collected_stats->histogram_->get_type() == JSON_HB) { Histogram_builder_json hist_builder(table_field, tree_key_length, rows); tree->walk(table_field->table, json_histogram_build_walk, @@ -2915,7 +2915,7 @@ Histogram_base * get_histogram_by_type(MEM_ROOT *mem_root, Histogram_type hist_t case SINGLE_PREC_HB: case DOUBLE_PREC_HB: return new Histogram_binary(); - case JSON: + case JSON_HB: return new Histogram_json(); default: DBUG_ASSERT(0); diff --git a/sql/sql_statistics.h b/sql/sql_statistics.h index 33e0430450a..f9fdd0a63bc 100644 --- a/sql/sql_statistics.h +++ b/sql/sql_statistics.h @@ -44,7 +44,7 @@ enum enum_histogram_type { SINGLE_PREC_HB, DOUBLE_PREC_HB, - JSON, + JSON_HB, INVALID_HISTOGRAM } Histogram_type; @@ -374,7 +374,7 @@ class Histogram_json : public Histogram_base Histogram_type get_type() override { - return JSON; + return JSON_HB; } void set_size (ulonglong sz) override {size = (uint8) sz; }