Commit 79cdb535 authored by Michael Okoko's avatar Michael Okoko Committed by Sergei Petrunia

add json statistics test and change histogram column type to blob

parent 2aca7b0c
--source include/have_stat_tables.inc
--echo #
--echo # Test that JSON is a valid histogram type and we can store JSON strings in mysql.column_stats
--echo #
--disable_warnings
drop table if exists t1;
--enable_warnings
set @save_histogram_type=@@histogram_type;
CREATE TABLE t1 (
a int NOT NULL PRIMARY KEY,
b varchar(32)
) ENGINE=MYISAM;
SET histogram_type='JSON';
SELECT @@histogram_type;
INSERT INTO t1 VALUES
(7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx'),
(17, 'vvvvvvvvvvvvv');
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES();
DESCRIBE mysql.column_stats;
SELECT * FROM mysql.column_stats;
set histogram_type=@save_histogram_type;
DROP TABLE t1;
\ No newline at end of file
......@@ -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 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 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';
......
......@@ -183,7 +183,7 @@ TABLE_FIELD_TYPE column_stat_fields[COLUMN_STAT_N_FIELDS] =
},
{
{ STRING_WITH_LEN("histogram") },
{ STRING_WITH_LEN("varbinary(255)") },
{ STRING_WITH_LEN("blob") },
{ NULL, 0 }
}
};
......@@ -1071,7 +1071,8 @@ class Column_stat: public Stat_table
break;
case COLUMN_STAT_HISTOGRAM:
if (stats->histogram.get_type() == JSON) {
stat_field->store((char *) "hello_world", 11, &my_charset_bin);
const char* val = "{'hello': 'world'}";
stat_field->store(val, strlen(val), &my_charset_bin);
} else {
stat_field->store((char *) stats->histogram.get_values(),
stats->histogram.get_size(), &my_charset_bin);
......
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