Commit f76e310a authored by Sergei Petrunia's avatar Sergei Petrunia

Rename histogram_type=JSON to JSON_HB

parent a48e63c5
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
--echo # Test that we can store JSON arrays in histogram field mysql.column_stats when histogram_type=JSON --echo # Test that we can store JSON arrays in histogram field mysql.column_stats when histogram_type=JSON
--echo # --echo #
let $histogram_type_override='JSON'; let $histogram_type_override='JSON_HB';
--source statistics.test --source statistics.test
--source include/have_stat_tables.inc --source include/have_stat_tables.inc
...@@ -27,7 +27,7 @@ select hex(histogram) from mysql.column_stats where table_name='t1_bin'; ...@@ -27,7 +27,7 @@ select hex(histogram) from mysql.column_stats where table_name='t1_bin';
explain extended select * from t1_bin where a between 'a-3a' and 'zzzzzzzzz'; explain extended select * from t1_bin where a between 'a-3a' and 'zzzzzzzzz';
analyze select * from t1_bin where a between 'a-3a' and 'zzzzzzzzz'; analyze select * from t1_bin where a between 'a-3a' and 'zzzzzzzzz';
set histogram_type=json; set histogram_type=json_hb;
create table t1_json (a varchar(255)); create table t1_json (a varchar(255));
insert into t1_json select concat('a-', a) from ten; insert into t1_json select concat('a-', a) from ten;
analyze table t1_json persistent for all; analyze table t1_json persistent for all;
...@@ -51,7 +51,7 @@ create table users ( ...@@ -51,7 +51,7 @@ create table users (
set histogram_size=50; set histogram_size=50;
insert into users select 'Moscow' from seq_1_to_99; insert into users select 'Moscow' from seq_1_to_99;
insert into users select 'Helsinki' from seq_1_to_2; insert into users select 'Helsinki' from seq_1_to_2;
set histogram_type=json; set histogram_type=json_hb;
analyze table users persistent for all; analyze table users persistent for all;
explain extended select * from users where city = 'Moscow'; explain extended select * from users where city = 'Moscow';
analyze select * from users where city = 'Moscow'; analyze select * from users where city = 'Moscow';
...@@ -76,7 +76,7 @@ use world; ...@@ -76,7 +76,7 @@ use world;
--enable_result_log --enable_result_log
--enable_query_log --enable_query_log
set histogram_type='JSON'; set histogram_type='JSON_HB';
set histogram_size=50; set histogram_size=50;
--disable_result_log --disable_result_log
ANALYZE TABLE Country, City, CountryLanguage persistent for all; ANALYZE TABLE Country, City, CountryLanguage persistent for all;
......
...@@ -234,7 +234,7 @@ column_stats CREATE TABLE `column_stats` ( ...@@ -234,7 +234,7 @@ column_stats CREATE TABLE `column_stats` (
`avg_length` decimal(12,4) DEFAULT NULL, `avg_length` decimal(12,4) DEFAULT NULL,
`avg_frequency` decimal(12,4) DEFAULT NULL, `avg_frequency` decimal(12,4) DEFAULT NULL,
`hist_size` tinyint(3) unsigned 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, `histogram` blob DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`) 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' ) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns'
......
...@@ -272,7 +272,7 @@ column_stats CREATE TABLE `column_stats` ( ...@@ -272,7 +272,7 @@ column_stats CREATE TABLE `column_stats` (
`avg_length` decimal(12,4) DEFAULT NULL, `avg_length` decimal(12,4) DEFAULT NULL,
`avg_frequency` decimal(12,4) DEFAULT NULL, `avg_frequency` decimal(12,4) DEFAULT NULL,
`hist_size` tinyint(3) unsigned 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, `histogram` blob DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`) 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' ) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns'
......
...@@ -276,7 +276,7 @@ column_stats CREATE TABLE `column_stats` ( ...@@ -276,7 +276,7 @@ column_stats CREATE TABLE `column_stats` (
`avg_length` decimal(12,4) DEFAULT NULL, `avg_length` decimal(12,4) DEFAULT NULL,
`avg_frequency` decimal(12,4) DEFAULT NULL, `avg_frequency` decimal(12,4) DEFAULT NULL,
`hist_size` tinyint(3) unsigned 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, `histogram` blob DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`) 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' ) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns'
......
...@@ -256,7 +256,7 @@ column_stats CREATE TABLE `column_stats` ( ...@@ -256,7 +256,7 @@ column_stats CREATE TABLE `column_stats` (
`avg_length` decimal(12,4) DEFAULT NULL, `avg_length` decimal(12,4) DEFAULT NULL,
`avg_frequency` decimal(12,4) DEFAULT NULL, `avg_frequency` decimal(12,4) DEFAULT NULL,
`hist_size` tinyint(3) unsigned 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, `histogram` blob DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`) 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' ) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns'
......
...@@ -13,9 +13,9 @@ def mysql column_stats avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL ...@@ -13,9 +13,9 @@ def mysql column_stats avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL
def mysql column_stats avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references NEVER NULL def mysql column_stats avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references NEVER NULL
def mysql column_stats column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_bin varchar(64) PRI select,insert,update,references NEVER NULL def mysql column_stats column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_bin varchar(64) PRI select,insert,update,references NEVER NULL
def mysql column_stats db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_bin varchar(64) PRI select,insert,update,references NEVER NULL def mysql column_stats db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_bin varchar(64) PRI select,insert,update,references NEVER NULL
def mysql column_stats histogram 11 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255) select,insert,update,references NEVER NULL def mysql column_stats histogram 11 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob select,insert,update,references NEVER NULL
def mysql column_stats hist_size 9 NULL YES tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references NEVER NULL def mysql column_stats hist_size 9 NULL YES tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references NEVER NULL
def mysql column_stats hist_type 10 NULL YES enum 14 42 NULL NULL NULL utf8mb3 utf8mb3_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') select,insert,update,references NEVER NULL def mysql column_stats hist_type 10 NULL YES enum 14 42 NULL NULL NULL utf8mb3 utf8mb3_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB') select,insert,update,references NEVER NULL
def mysql column_stats max_value 5 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255) select,insert,update,references NEVER NULL def mysql column_stats max_value 5 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255) select,insert,update,references NEVER NULL
def mysql column_stats min_value 4 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255) select,insert,update,references NEVER NULL def mysql column_stats min_value 4 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255) select,insert,update,references NEVER NULL
def mysql column_stats nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references NEVER NULL def mysql column_stats nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references NEVER NULL
...@@ -345,8 +345,8 @@ NULL mysql column_stats nulls_ratio decimal NULL NULL NULL NULL decimal(12,4) ...@@ -345,8 +345,8 @@ NULL mysql column_stats nulls_ratio decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats avg_length decimal NULL NULL NULL NULL decimal(12,4) NULL mysql column_stats avg_length decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats avg_frequency decimal NULL NULL NULL NULL decimal(12,4) NULL mysql column_stats avg_frequency decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats hist_size tinyint NULL NULL NULL NULL tinyint(3) unsigned NULL mysql column_stats hist_size tinyint NULL NULL NULL NULL tinyint(3) unsigned
3.0000 mysql column_stats hist_type enum 14 42 utf8mb3 utf8mb3_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') 3.0000 mysql column_stats hist_type enum 14 42 utf8mb3 utf8mb3_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB')
1.0000 mysql column_stats histogram varbinary 255 255 NULL NULL varbinary(255) 1.0000 mysql column_stats histogram blob 65535 65535 NULL NULL blob
3.0000 mysql db Host char 255 765 utf8mb3 utf8mb3_bin char(255) 3.0000 mysql db Host char 255 765 utf8mb3 utf8mb3_bin char(255)
3.0000 mysql db Db char 64 192 utf8mb3 utf8mb3_bin char(64) 3.0000 mysql db Db char 64 192 utf8mb3 utf8mb3_bin char(64)
3.0000 mysql db User char 128 384 utf8mb3 utf8mb3_bin char(128) 3.0000 mysql db User char 128 384 utf8mb3 utf8mb3_bin char(128)
......
...@@ -1309,7 +1309,7 @@ VARIABLE_COMMENT Specifies type of the histograms created by ANALYZE. Possible v ...@@ -1309,7 +1309,7 @@ VARIABLE_COMMENT Specifies type of the histograms created by ANALYZE. Possible v
NUMERIC_MIN_VALUE NULL NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST SINGLE_PREC_HB,DOUBLE_PREC_HB ENUM_VALUE_LIST SINGLE_PREC_HB,DOUBLE_PREC_HB,JSON_HB
READ_ONLY NO READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME HOSTNAME VARIABLE_NAME HOSTNAME
......
...@@ -314,7 +314,7 @@ DROP TABLE tmp_proxies_priv; ...@@ -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 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'; 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';
......
...@@ -503,7 +503,7 @@ String *Item_func_from_base64::val_str(String *str) ...@@ -503,7 +503,7 @@ String *Item_func_from_base64::val_str(String *str)
const char *histogram_types[] = 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= static TYPELIB histogram_types_typelib=
{ array_elements(histogram_types), { array_elements(histogram_types),
"histogram_types", "histogram_types",
...@@ -533,6 +533,13 @@ String *Item_func_decode_histogram::val_str(String *str) ...@@ -533,6 +533,13 @@ String *Item_func_decode_histogram::val_str(String *str)
null_value= 1; null_value= 1;
return 0; 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) if (type == DOUBLE_PREC_HB && res->length() % 2 != 0)
res->length(res->length() - 1); // one byte is unused res->length(res->length() - 1); // one byte is unused
...@@ -541,10 +548,6 @@ String *Item_func_decode_histogram::val_str(String *str) ...@@ -541,10 +548,6 @@ String *Item_func_decode_histogram::val_str(String *str)
str->length(0); str->length(0);
char numbuf[32]; char numbuf[32];
const uchar *p= (uchar*)res->c_ptr_safe(); const uchar *p= (uchar*)res->c_ptr_safe();
if (type == JSON)
{
return res;
}
for (i= 0; i < res->length(); i++) for (i= 0; i < res->length(); i++)
{ {
double val; double val;
......
...@@ -193,7 +193,7 @@ TABLE_FIELD_TYPE column_stat_fields[COLUMN_STAT_N_FIELDS] = ...@@ -193,7 +193,7 @@ TABLE_FIELD_TYPE column_stat_fields[COLUMN_STAT_N_FIELDS] =
}, },
{ {
{ STRING_WITH_LEN("hist_type") }, { 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") } { STRING_WITH_LEN("utf8mb3") }
}, },
{ {
...@@ -1234,7 +1234,7 @@ class Column_stat: public Stat_table ...@@ -1234,7 +1234,7 @@ class Column_stat: public Stat_table
case DOUBLE_PREC_HB: case DOUBLE_PREC_HB:
hist = new (mem_root) Histogram_binary(); hist = new (mem_root) Histogram_binary();
break; break;
case JSON: case JSON_HB:
hist = new (mem_root) Histogram_json(); hist = new (mem_root) Histogram_json();
break; break;
default: default:
...@@ -2046,7 +2046,7 @@ class Histogram_builder_json : public Histogram_builder ...@@ -2046,7 +2046,7 @@ class Histogram_builder_json : public Histogram_builder
Histogram_base *create_histogram(Histogram_type hist_type) Histogram_base *create_histogram(Histogram_type hist_type)
{ {
// assumes the caller already checked for invalid histograms // assumes the caller already checked for invalid histograms
if (hist_type == JSON) if (hist_type == JSON_HB)
return new Histogram_json; return new Histogram_json;
else else
return new Histogram_binary; return new Histogram_binary;
...@@ -2207,7 +2207,7 @@ class Count_distinct_field: public Sql_alloc ...@@ -2207,7 +2207,7 @@ class Count_distinct_field: public Sql_alloc
*/ */
void walk_tree_with_histogram(ha_rows rows) 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); Histogram_builder_json hist_builder(table_field, tree_key_length, rows);
tree->walk(table_field->table, json_histogram_build_walk, 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 ...@@ -2915,7 +2915,7 @@ Histogram_base * get_histogram_by_type(MEM_ROOT *mem_root, Histogram_type hist_t
case SINGLE_PREC_HB: case SINGLE_PREC_HB:
case DOUBLE_PREC_HB: case DOUBLE_PREC_HB:
return new Histogram_binary(); return new Histogram_binary();
case JSON: case JSON_HB:
return new Histogram_json(); return new Histogram_json();
default: default:
DBUG_ASSERT(0); DBUG_ASSERT(0);
......
...@@ -44,7 +44,7 @@ enum enum_histogram_type ...@@ -44,7 +44,7 @@ enum enum_histogram_type
{ {
SINGLE_PREC_HB, SINGLE_PREC_HB,
DOUBLE_PREC_HB, DOUBLE_PREC_HB,
JSON, JSON_HB,
INVALID_HISTOGRAM INVALID_HISTOGRAM
} Histogram_type; } Histogram_type;
...@@ -374,7 +374,7 @@ class Histogram_json : public Histogram_base ...@@ -374,7 +374,7 @@ class Histogram_json : public Histogram_base
Histogram_type get_type() override Histogram_type get_type() override
{ {
return JSON; return JSON_HB;
} }
void set_size (ulonglong sz) override {size = (uint8) sz; } void set_size (ulonglong sz) override {size = (uint8) sz; }
......
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