Commit 058a90e6 authored by Michael Okoko's avatar Michael Okoko Committed by Sergei Petrunia

Use existing statistics test to improve coverage for JSON statistics

Signed-off-by: default avatarMichael Okoko <okokomichaels@outlook.com>
parent 3692adeb
set @SINGLE_PREC_TYPE='single_prec_hb';
set @DOUBLE_PREC_TYPE='double_prec_hb';
drop table if exists t1,t2;
set @save_use_stat_tables=@@use_stat_tables;
set @save_histogram_size=@@global.histogram_size;
set @@global.histogram_size=0,@@local.histogram_size=0;
set @save_hist_type=@@histogram_type;
set histogram_type='single_prec_hb';
set histogram_type=@SINGLE_PREC_TYPE;
DELETE FROM mysql.table_stats;
DELETE FROM mysql.column_stats;
DELETE FROM mysql.index_stats;
......@@ -231,7 +233,7 @@ test t1 e 0.01 0.112 0.2250 6.2000 4 SINGLE_PREC_HB 000564E1
test t1 f 1 5 0.2000 6.4000 4 SINGLE_PREC_HB 3F7FBFBF
DELETE FROM mysql.column_stats;
set histogram_size=8;
set histogram_type='DOUBLE_PREC_HB';
set histogram_type=@DOUBLE_PREC_TYPE;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
......@@ -250,7 +252,7 @@ test t1 e 0.01 0.112 0.2250 6.2000 8 DOUBLE_PREC_HB 000005056464E1E1
test t1 f 1 5 0.2000 6.4000 8 DOUBLE_PREC_HB FF3FFF7FFFBFFFBF
DELETE FROM mysql.column_stats;
set histogram_size= 0;
set histogram_type='single_prec_hb';
set histogram_type=@SINGLE_PREC_TYPE;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
......@@ -1476,10 +1478,10 @@ WORLD_INNODB COUNTRYLANGUAGE Percentage 1 2.7640
use world;
set use_stat_tables='preferably';
set histogram_size=100;
set histogram_type='SINGLE_PREC_HB';
set histogram_type=@SINGLE_PREC_TYPE;
ANALYZE TABLE CountryLanguage;
set histogram_size=254;
set histogram_type='DOUBLE_PREC_HB';
set histogram_type=@DOUBLE_PREC_TYPE;
ANALYZE TABLE City;
FLUSH TABLES;
select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(hist_type,histogram) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='COUNTRYLANGUAGE' and UPPER(column_name) = 'PERCENTAGE';;
......@@ -1508,7 +1510,7 @@ hist_size 254
hist_type DOUBLE_PREC_HB
hex(histogram) 1F00A1002B023002350238023F02430249024E02520258025D02630268026E02720276027B02800285028C02920297029D02A102A802AC02B402BC02C402CC02D302DA02E302EA02F102F802010305030C03120319031F03290333033D0343034F03590363036D037803840390039A03A603B303C303D103E003F203020412042404330440045304600472047F049104A204B804C804DE04F2040A0526053F0558056F058E05B305D905F4051306380667068406AB06DA06020731075C079407C507F8072E085E08A508DF0824096909CC092E0A760AD50A400BA90B150CAD0C310D240E130F0E103B11B9126B14F0166B192F1CB71FFF240630483FC567
decode_histogram(hist_type,histogram) 0.00047,0.00198,0.00601,0.00008,0.00008,0.00005,0.00011,0.00006,0.00009,0.00008,0.00006,0.00009,0.00008,0.00009,0.00008,0.00009,0.00006,0.00006,0.00008,0.00008,0.00008,0.00011,0.00009,0.00008,0.00009,0.00006,0.00011,0.00006,0.00012,0.00012,0.00012,0.00012,0.00011,0.00011,0.00014,0.00011,0.00011,0.00011,0.00014,0.00006,0.00011,0.00009,0.00011,0.00009,0.00015,0.00015,0.00015,0.00009,0.00018,0.00015,0.00015,0.00015,0.00017,0.00018,0.00018,0.00015,0.00018,0.00020,0.00024,0.00021,0.00023,0.00027,0.00024,0.00024,0.00027,0.00023,0.00020,0.00029,0.00020,0.00027,0.00020,0.00027,0.00026,0.00034,0.00024,0.00034,0.00031,0.00037,0.00043,0.00038,0.00038,0.00035,0.00047,0.00056,0.00058,0.00041,0.00047,0.00056,0.00072,0.00044,0.00060,0.00072,0.00061,0.00072,0.00066,0.00085,0.00075,0.00078,0.00082,0.00073,0.00108,0.00089,0.00105,0.00105,0.00151,0.00150,0.00110,0.00145,0.00163,0.00160,0.00165,0.00232,0.00201,0.00371,0.00365,0.00383,0.00459,0.00583,0.00662,0.00984,0.00969,0.01080,0.01379,0.02063,0.04308,0.05960,0.15816,0.59464
set histogram_type='single_prec_hb';
set histogram_type=@SINGLE_PREC_TYPE;
set histogram_size=0;
use test;
DROP DATABASE world;
......@@ -1588,7 +1590,7 @@ drop table t1;
create table t1 ( a int);
insert into t1 values (1),(2),(3),(4),(5);
set histogram_size=10;
set histogram_type='double_prec_hb';
set histogram_type=@DOUBLE_PREC_TYPE;
show variables like 'histogram%';
Variable_name Value
histogram_size 10
......@@ -1605,7 +1607,7 @@ 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 1 5 0.0000 1.0000 10 DOUBLE_PREC_HB 0000FF3FFF7FFFBFFFFF
set histogram_size=0;
set histogram_type='single_prec_hb';
set histogram_type=@SINGLE_PREC_TYPE;
drop table t1;
#
# Bug mdev-4369: histogram for a column with many distinct values
......@@ -1760,12 +1762,12 @@ set use_stat_tables=@save_use_stat_tables;
#
# MDEV-10134 Add full support for DEFAULT
#
CREATE TABLE t1 (a BLOB, b TEXT DEFAULT DECODE_HISTOGRAM('SINGLE_PREC_HB',a));
CREATE TABLE t1 (a BLOB, b TEXT DEFAULT DECODE_HISTOGRAM(@SINGLE_PREC_TYPE,a));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` blob DEFAULT NULL,
`b` text DEFAULT decode_histogram('SINGLE_PREC_HB',`a`)
`b` text DEFAULT decode_histogram(@`SINGLE_PREC_TYPE`,`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 (a) VALUES (0x0000000000000000000000000101010101010101010202020303030304040404050505050606070707080809090A0A0B0C0D0D0E0E0F10111213131415161718191B1C1E202224292A2E33373B4850575F6A76818C9AA7B9C4CFDADFE5EBF0F4F8FAFCFF);
SELECT b FROM t1;
......
set @SINGLE_PREC_TYPE='single_prec_hb';
set @DOUBLE_PREC_TYPE='double_prec_hb';
set @DEFAULT_HIST_TYPE=@@histogram_type;
if ($histogram_type_override) {
eval set @SINGLE_PREC_TYPE=$histogram_type_override;
eval set @DOUBLE_PREC_TYPE=$histogram_type_override;
eval set @DEFAULT_HIST_TYPE=$histogram_type_override;
}
--source include/have_stat_tables.inc
--source include/have_innodb.inc
--disable_warnings
......@@ -7,8 +17,8 @@ drop table if exists t1,t2;
set @save_use_stat_tables=@@use_stat_tables;
set @save_histogram_size=@@global.histogram_size;
set @@global.histogram_size=0,@@local.histogram_size=0;
set @save_hist_type=@@histogram_type;
set histogram_type='single_prec_hb';
set @save_hist_type=@DEFAULT_HIST_TYPE;
set histogram_type=@SINGLE_PREC_TYPE;
DELETE FROM mysql.table_stats;
--sorted_result
......@@ -187,7 +197,7 @@ SELECT db_name, table_name, column_name,
DELETE FROM mysql.column_stats;
set histogram_size=8;
set histogram_type='DOUBLE_PREC_HB';
set histogram_type=@DOUBLE_PREC_TYPE;
ANALYZE TABLE t1;
--sorted_result
......@@ -200,7 +210,7 @@ SELECT db_name, table_name, column_name,
DELETE FROM mysql.column_stats;
set histogram_size= 0;
set histogram_type='single_prec_hb';
set histogram_type=@SINGLE_PREC_TYPE;
ANALYZE TABLE t1;
......@@ -650,10 +660,10 @@ use world;
set use_stat_tables='preferably';
--disable_result_log
set histogram_size=100;
set histogram_type='SINGLE_PREC_HB';
set histogram_type=@SINGLE_PREC_TYPE;
ANALYZE TABLE CountryLanguage;
set histogram_size=254;
set histogram_type='DOUBLE_PREC_HB';
set histogram_type=@DOUBLE_PREC_TYPE;
ANALYZE TABLE City;
FLUSH TABLES;
--enable_result_log
......@@ -661,7 +671,7 @@ FLUSH TABLES;
--query_vertical select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(hist_type,histogram) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='COUNTRYLANGUAGE' and UPPER(column_name) = 'PERCENTAGE';
--query_vertical select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(hist_type,histogram) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='CITY' and UPPER(column_name) = 'POPULATION';
set histogram_type='single_prec_hb';
set histogram_type=@SINGLE_PREC_TYPE;
set histogram_size=0;
use test;
......@@ -724,7 +734,7 @@ create table t1 ( a int);
insert into t1 values (1),(2),(3),(4),(5);
set histogram_size=10;
set histogram_type='double_prec_hb';
set histogram_type=@DOUBLE_PREC_TYPE;
show variables like 'histogram%';
......@@ -737,7 +747,7 @@ select db_name, table_name, column_name,
FROM mysql.column_stats;
set histogram_size=0;
set histogram_type='single_prec_hb';
set histogram_type=@SINGLE_PREC_TYPE;
drop table t1;
......@@ -908,11 +918,14 @@ set use_stat_tables=@save_use_stat_tables;
--echo # MDEV-10134 Add full support for DEFAULT
--echo #
CREATE TABLE t1 (a BLOB, b TEXT DEFAULT DECODE_HISTOGRAM('SINGLE_PREC_HB',a));
# disable for JSON histograms
if (!$histogram_type_override) {
CREATE TABLE t1 (a BLOB, b TEXT DEFAULT DECODE_HISTOGRAM(@SINGLE_PREC_TYPE,a));
SHOW CREATE TABLE t1;
INSERT INTO t1 (a) VALUES (0x0000000000000000000000000101010101010101010202020303030304040404050505050606070707080809090A0A0B0C0D0D0E0E0F10111213131415161718191B1C1E202224292A2E33373B4850575F6A76818C9AA7B9C4CFDADFE5EBF0F4F8FAFCFF);
SELECT b FROM t1;
DROP TABLE t1;
}
--echo #
--echo # End of 10.2 tests
......
This source diff could not be displayed because it is too large. You can view the blob instead.
--source include/have_stat_tables.inc
--source include/have_sequence.inc
--source include/analyze-format.inc
--echo #
--echo # Test that we can store JSON arrays in histogram field mysql.column_stats when histogram_type=JSON
--echo #
let $histogram_type_override='JSON';
--source statistics.test
--source include/have_stat_tables.inc
--source include/have_sequence.inc
--source include/analyze-format.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
......@@ -14,22 +18,31 @@ set @save_histogram_size=@@histogram_size;
create table ten(a int primary key);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
set histogram_size=100;
set histogram_type='double_prec_hb';
create table t1_bin (a varchar(255));
insert into t1_bin select concat('a-', a) from ten;
set histogram_size=100;
analyze table t1_bin persistent for all;
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';
analyze select * from t1_bin where a between 'a-3a' and 'zzzzzzzzz';
set histogram_type=json;
create table t1_json (a varchar(255));
insert into t1_json select concat('a-', a) from ten;
set histogram_type=json;
analyze table t1_json persistent for all;
select * from mysql.column_stats where table_name='t1_json';
explain extended select * from t1_json where a between 'a-3a' and 'zzzzzzzzz';
analyze select * from t1_json where a between 'a-3a' and 'zzzzzzzzz';
explain extended select * from t1_json where a < 'b-1a';
analyze select * from t1_json where a > 'zzzzzzzzz';
# test different valid JSON strings that are invalid histograms.
UPDATE mysql.column_stats SET histogram='["a-1", "a-2", {"a": "b"}, "a-3"]' WHERE table_name='t1_json';
FLUSH TABLES;
--error ER_JSON_HISTOGRAM_PARSE_FAILED
explain extended select * from t1_json where a between 'a-3a' and 'zzzzzzzzz';
--source include/have_sequence.inc
create table users (
......@@ -42,93 +55,15 @@ set histogram_type=json;
analyze table users persistent for all;
explain extended select * from users where city = 'Moscow';
analyze select * from users where city = 'Moscow';
explain extended select * from users where city = 'Helsinki';
analyze select * from users where city = 'helsinki';
explain extended select * from users where city < 'Lagos';
drop table t1_bin;
drop table t1_json;
drop table users;
CREATE TABLE t1 (
a int NOT NULL PRIMARY KEY,
b varchar(32),
c char(16),
d date,
e double,
f bit(3),
INDEX idx1 (b, e),
INDEX idx2 (c, d),
INDEX idx3 (d),
INDEX idx4 (e, b, d)
);
--disable_result_log
INSERT INTO t1 VALUES
(0, NULL, NULL, NULL, NULL, NULL),
(7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd', '1990-05-15', 0.1, b'100'),
(17, 'vvvvvvvvvvvvv', 'aaaa', '1989-03-12', 0.01, b'101'),
(1, 'vvvvvvvvvvvvv', NULL, '1989-03-12', 0.01, b'100'),
(12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.112, b'001'),
(23, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.1, b'100'),
(8, 'vvvvvvvvvvvvv', 'aaaa', '1999-07-23', 0.1, b'100'),
(22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa', '1989-03-12', 0.112, b'001'),
(31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa', '1999-07-23', 0.01, b'001'),
(10, NULL, 'aaaa', NULL, 0.01, b'010'),
(5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.1, b'100'),
(15, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.1, b'010'),
(30, NULL, 'bbbbbb', NULL, NULL, b'100'),
(38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, NULL, NULL),
(18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc', '1990-05-15', 0.01, b'010'),
(9, 'yyy', 'bbbbbb', '1998-08-28', 0.01, NULL),
(29, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.012, b'010'),
(3, 'yyy', 'dddddddd', '1990-05-15', 0.112, b'010'),
(39, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, 0.01, b'100'),
(14, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.1, b'100'),
(40, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', '1989-03-12', NULL, NULL),
(44, NULL, 'aaaa', '1989-03-12', NULL, b'010'),
(19, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.012, b'011'),
(21, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.112, b'100'),
(45, NULL, NULL, '1989-03-12', NULL, b'011'),
(2, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'ccccccccc', '1990-05-15', 0.1, b'001'),
(35, 'yyy', 'aaaa', '1990-05-15', 0.05, b'011'),
(4, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.01, b'101'),
(47, NULL, 'aaaa', '1990-05-15', 0.05, b'010'),
(42, NULL, 'ccccccccc', '1989-03-12', 0.01, b'010'),
(32, NULL, 'bbbbbb', '1990-05-15', 0.01, b'011'),
(49, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'aaaa', '1990-05-15', NULL, NULL),
(43, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'bbbbbb', '1990-05-15', NULL, b'100'),
(37, 'yyy', NULL, '1989-03-12', 0.05, b'011'),
(41, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.05, NULL),
(34, 'yyy', NULL, NULL, NULL, NULL),
(33, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.05, b'011'),
(24, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1990-05-15', 0.01, b'101'),
(11, 'yyy', 'ccccccccc', '1999-07-23', 0.1, NULL),
(25, 'zzzzzzzzzzzzzzzzzz', 'bbb', '1989-03-12', 0.01, b'101');
--enable_result_log
SET histogram_type='JSON';
set histogram_size=25;
ANALYZE TABLE t1 persistent for all;
SELECT * FROM mysql.table_stats;
SELECT * FROM mysql.column_stats;
SELECT * FROM mysql.index_stats;
SELECT COUNT(*) FROM t1;
explain extended select * from t1 where a between '20' and '70';
analyze select * from t1 where a between '20' and '70';
# test different valid JSON strings that are invalid histograms.
UPDATE mysql.column_stats SET histogram='["1", {"a": "b"}, "2"]' WHERE table_name='t1';
FLUSH TABLES;
--error ER_JSON_HISTOGRAM_PARSE_FAILED
explain extended select * from t1 where a between '20' and '70';
DELETE FROM mysql.column_stats;
DROP TABLE t1;
create schema world;
use world;
......@@ -150,6 +85,8 @@ ANALYZE TABLE Country, City, CountryLanguage persistent for all;
SELECT column_name, min_value, max_value, hist_size, hist_type, histogram FROM mysql.column_stats;
explain extended select * from Country where 'Code' between 'BBC' and 'GGG';
analyze select * from Country where 'Code' between 'BBC' and 'GGG';
explain extended select * from Country where 'Code' < 'BBC';
analyze select * from Country where 'Code' < 'BBC';
set histogram_type=@save_histogram_type;
set histogram_size=@save_histogram_size;
......
......@@ -541,6 +541,10 @@ 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;
......
......@@ -1992,6 +1992,7 @@ class Histogram_builder
class Histogram_builder_json : public Histogram_builder
{
std::vector<std::string> bucket_bounds;
bool got_first_value = false;
public:
Histogram_builder_json(Field *col, uint col_len, ha_rows rows)
......@@ -2021,7 +2022,7 @@ class Histogram_builder_json : public Histogram_builder
while (curr_bucket != hist_width &&
count > bucket_capacity * (curr_bucket + 1))
{
auto it = bucket_bounds.begin();
it = bucket_bounds.begin();
bucket_bounds.insert(it+curr_bucket, bucket_bounds[curr_bucket-1]);
curr_bucket++;
}
......
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