1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +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

@ -11,6 +11,46 @@ 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;
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';
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';
--source include/have_sequence.inc
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;
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';
drop table t1_bin;
drop table t1_json;
drop table users;
CREATE TABLE t1 (
a int NOT NULL PRIMARY KEY,
b varchar(32),
@ -81,11 +121,11 @@ 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';
# todo: 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';
# 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;