1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Implement point selectivity for JSON histograms

* Also merges tests relating to JSON statistics into one file

Signed-off-by: Michael Okoko <okokomichaels@outlook.com>
This commit is contained in:
Michael Okoko
2021-08-21 09:17:23 +01:00
committed by Sergei Petrunia
parent 547f805311
commit bff65a813e
8 changed files with 254 additions and 501 deletions

View File

@@ -4,6 +4,175 @@
drop table if exists t1;
set @save_histogram_type=@@histogram_type;
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);
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;
Table Op Msg_type Msg_text
test.t1_bin analyze status Engine-independent statistics collected
test.t1_bin analyze status OK
select hex(histogram) from mysql.column_stats where table_name='t1_bin';
hex(histogram)
00000000000000000000711C711C711C711C711CE338E338E338E338E33855555555555555555555C671C671C671C671C671388E388E388E388E388EAAAAAAAAAAAAAAAAAAAA1BC71BC71BC71BC71BC78DE38DE38DE38DE38DE3FFFFFFFFFFFFFFFFFFFF
explain extended select * from t1_bin where a between 'a-3a' and 'zzzzzzzzz';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1_bin ALL NULL NULL NULL NULL 10 58.82 Using where
Warnings:
Note 1003 select `test`.`t1_bin`.`a` AS `a` from `test`.`t1_bin` where `test`.`t1_bin`.`a` between 'a-3a' and 'zzzzzzzzz'
analyze select * from t1_bin where a between 'a-3a' and 'zzzzzzzzz';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1_bin ALL NULL NULL NULL NULL 10 10.00 58.82 60.00 Using where
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;
Table Op Msg_type Msg_text
test.t1_json analyze status Engine-independent statistics collected
test.t1_json analyze status OK
select * from mysql.column_stats where table_name='t1_json';
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
test t1_json a a-0 a-9 0.0000 3.0000 1.0000 100 JSON [
"a-0",
"a-0",
"a-0",
"a-0",
"a-0",
"a-0",
"a-0",
"a-0",
"a-0",
"a-0",
"a-1",
"a-1",
"a-1",
"a-1",
"a-1",
"a-1",
"a-1",
"a-1",
"a-1",
"a-1",
"a-2",
"a-2",
"a-2",
"a-2",
"a-2",
"a-2",
"a-2",
"a-2",
"a-2",
"a-2",
"a-3",
"a-3",
"a-3",
"a-3",
"a-3",
"a-3",
"a-3",
"a-3",
"a-3",
"a-3",
"a-4",
"a-4",
"a-4",
"a-4",
"a-4",
"a-4",
"a-4",
"a-4",
"a-4",
"a-4",
"a-5",
"a-5",
"a-5",
"a-5",
"a-5",
"a-5",
"a-5",
"a-5",
"a-5",
"a-5",
"a-6",
"a-6",
"a-6",
"a-6",
"a-6",
"a-6",
"a-6",
"a-6",
"a-6",
"a-6",
"a-7",
"a-7",
"a-7",
"a-7",
"a-7",
"a-7",
"a-7",
"a-7",
"a-7",
"a-7",
"a-8",
"a-8",
"a-8",
"a-8",
"a-8",
"a-8",
"a-8",
"a-8",
"a-8",
"a-8",
"a-9",
"a-9",
"a-9",
"a-9",
"a-9",
"a-9",
"a-9",
"a-9",
"a-9",
"a-9"
]
explain extended select * from t1_json where a between 'a-3a' and 'zzzzzzzzz';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10 60.87 Using where
Warnings:
Note 1003 select `test`.`t1_json`.`a` AS `a` from `test`.`t1_json` where `test`.`t1_json`.`a` between 'a-3a' and 'zzzzzzzzz'
analyze select * from t1_json where a between 'a-3a' and 'zzzzzzzzz';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10 10.00 60.87 60.00 Using where
create table users (
city varchar(100)
);
set histogram_size=50;
insert into users select 'Moscow' from seq_1_to_99;
insert into users select 'Helsinki' from seq_1_to_2;
set histogram_type=json;
analyze table users persistent for all;
Table Op Msg_type Msg_text
test.users analyze status Engine-independent statistics collected
test.users analyze status OK
explain extended select * from users where city = 'Moscow';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE users ALL NULL NULL NULL NULL 101 98.04 Using where
Warnings:
Note 1003 select `test`.`users`.`city` AS `city` from `test`.`users` where `test`.`users`.`city` = 'Moscow'
analyze select * from users where city = 'Moscow';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE users ALL NULL NULL NULL NULL 101 101.00 98.04 98.02 Using where
explain extended select * from users where city = 'Helsinki';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE users ALL NULL NULL NULL NULL 101 50.00 Using where
Warnings:
Note 1003 select `test`.`users`.`city` AS `city` from `test`.`users` where `test`.`users`.`city` = 'Helsinki'
analyze select * from users where city = 'helsinki';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE users ALL NULL NULL NULL NULL 101 101.00 50.00 1.98 Using where
drop table t1_bin;
drop table t1_json;
drop table users;
CREATE TABLE t1 (
a int NOT NULL PRIMARY KEY,
b varchar(32),
@@ -252,6 +421,10 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` A
analyze select * from t1 where a between '20' and '70';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 40 40.00 57.50 57.50 Using where
UPDATE mysql.column_stats SET histogram='["1", {"a": "b"}, "2"]' WHERE table_name='t1';
FLUSH TABLES;
explain extended select * from t1 where a between '20' and '70';
ERROR HY000: Failed to parse histogram, encountered JSON_TYPE '1'.
DELETE FROM mysql.column_stats;
DROP TABLE t1;
create schema world;