Commit 2aca7b0c authored by Michael Okoko's avatar Michael Okoko Committed by Sergei Petrunia

Prepare JSON as valid histogram_type

Signed-off-by: default avatarMichael Okoko <okokomichaels@outlook.com>
parent e222e44d
......@@ -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'), histogram varbinary(255), 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'), histogram varbinary(255), 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';
......
......@@ -503,7 +503,7 @@ String *Item_func_from_base64::val_str(String *str)
const char *histogram_types[] =
{"SINGLE_PREC_HB", "DOUBLE_PREC_HB", 0};
{"SINGLE_PREC_HB", "DOUBLE_PREC_HB", "JSON", 0};
static TYPELIB histogram_types_typelib=
{ array_elements(histogram_types),
"histogram_types",
......
......@@ -178,7 +178,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')") },
{ STRING_WITH_LEN("enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON')") },
{ STRING_WITH_LEN("utf8mb3") }
},
{
......@@ -1070,8 +1070,12 @@ class Column_stat: public Stat_table
stat_field->store(stats->histogram.get_type() + 1);
break;
case COLUMN_STAT_HISTOGRAM:
stat_field->store((char *)stats->histogram.get_values(),
stats->histogram.get_size(), &my_charset_bin);
if (stats->histogram.get_type() == JSON) {
stat_field->store((char *) "hello_world", 11, &my_charset_bin);
} else {
stat_field->store((char *) stats->histogram.get_values(),
stats->histogram.get_size(), &my_charset_bin);
}
break;
}
}
......
......@@ -42,7 +42,8 @@ typedef
enum enum_histogram_type
{
SINGLE_PREC_HB,
DOUBLE_PREC_HB
DOUBLE_PREC_HB,
JSON
} Histogram_type;
enum enum_stat_tables
......@@ -154,6 +155,7 @@ class Histogram
case SINGLE_PREC_HB:
return ((uint) (1 << 8) - 1);
case DOUBLE_PREC_HB:
case JSON:
return ((uint) (1 << 16) - 1);
}
return 1;
......@@ -166,6 +168,7 @@ class Histogram
case SINGLE_PREC_HB:
return size;
case DOUBLE_PREC_HB:
case JSON:
return size / 2;
}
return 0;
......@@ -179,6 +182,7 @@ class Histogram
case SINGLE_PREC_HB:
return (uint) (((uint8 *) values)[i]);
case DOUBLE_PREC_HB:
case JSON:
return (uint) uint2korr(values + i * 2);
}
return 0;
......@@ -253,7 +257,8 @@ class Histogram
void set_value(uint i, double val)
{
switch (type) {
case SINGLE_PREC_HB:
case SINGLE_PREC_HB:
case JSON:
((uint8 *) values)[i]= (uint8) (val * prec_factor());
return;
case DOUBLE_PREC_HB:
......@@ -265,7 +270,8 @@ class Histogram
void set_prev_value(uint i)
{
switch (type) {
case SINGLE_PREC_HB:
case SINGLE_PREC_HB:
case JSON:
((uint8 *) values)[i]= ((uint8 *) values)[i-1];
return;
case DOUBLE_PREC_HB:
......
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