Commit 3d952cd8 authored by Michael Okoko's avatar Michael Okoko Committed by Sergei Petrunia

Improve tests and test results to cover larger cases

Signed-off-by: default avatarMichael Okoko <okokomichaels@outlook.com>
parent 63cbd074
......@@ -3,38 +3,47 @@
--echo # todo: should be merged with statistics_json.test
--echo #
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 (a varchar(255));
insert into t1 select concat('a-', a) from ten;
analyze table t1 persistent for all;
select * from mysql.column_stats where table_name='t1';
explain extended select * from t1 where a between 'a-3a' and 'zzzzzzzzz';
create table t2(a int);
insert into t2 select a*10 from ten;
analyze table t2 persistent for all;
explain extended select * from t2 where a between '44' and '55';
create table t1_bin (a varchar(255));
insert into t1_bin select concat('a-', a) from ten;
drop table t1;
drop table t2;
set histogram_size=10;
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 (a varchar(255));
insert into t1 select concat('a-', a) from ten;
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';
analyze table t1 persistent for all;
select * from mysql.column_stats where table_name='t1';
explain extended select * from t1 where a between 'a-3a' and 'zzzzzzzzz';
create table t2(a int);
insert into t2 select a*10 from ten;
set histogram_type=json;
analyze table t2 persistent for all;
explain extended select * from t2 where a between '44' and '55';
create table t2_bin(a int);
insert into t2_bin select a*10 from ten;
set histogram_type=@save_histogram_type;
analyze table t2_bin persistent for all;
explain extended select * from t2_bin where a between '44' and '55';
analyze select * from t2_bin where a between '44' and '55';
drop table t1;
drop table t2;
create table t2_json(a int);
insert into t2_json select a*10 from ten;
set histogram_type=json;
analyze table t2_json persistent for all;
select * from mysql.column_stats where table_name='t2_json';
explain extended select * from t2_json where a between '44' and '55';
analyze select * from t2_json where a between '44' and '55';
drop table t1_bin;
drop table t1_json;
drop table t2_bin;
drop table t2_json;
......@@ -5,309 +5,793 @@ drop table if exists t1;
set @save_histogram_type=@@histogram_type;
set @save_histogram_size=@@histogram_size;
CREATE TABLE t1 (
a int,
a int NOT NULL PRIMARY KEY,
b varchar(32),
c char(2),
d double
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)
);
INSERT INTO t1 SELECT seq, seq, seq, seq from seq_1_to_25;
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');
SET histogram_type='JSON';
set histogram_size=10;
ANALYZE TABLE t1 PERSISTENT FOR ALL;
set histogram_size=25;
ANALYZE TABLE t1 persistent for all;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
SELECT * FROM mysql.column_stats WHERE table_name='t1';
SELECT * FROM mysql.table_stats;
db_name table_name cardinality
test t1 40
SELECT * FROM mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
test t1 a 1 25 0.0000 4.0000 1.0000 10 JSON [
test t1 a 0 49 0.0000 4.0000 1.0000 25 JSON [
"1",
"3",
"5",
"4",
"7",
"8",
"10",
"12",
"14",
"16",
"19",
"21",
"23"
]
test t1 b 1 9 0.0000 1.6400 1.0000 10 JSON [
"11",
"13",
"14",
"15",
"18",
"2",
"21",
"23",
"3",
"5",
"7"
"19",
"22",
"24",
"25",
"30",
"31",
"33",
"34",
"37",
"38",
"40",
"41",
"43",
"44",
"47"
]
test t1 c 1 9 0.0000 2.0000 1.0000 10 JSON [
"11",
"13",
"15",
"18",
"2",
"21",
"23",
"3",
"5",
"7"
test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 5 JSON [
"vvvvvvvvvvvvv",
"wwwwwwwwwwwwwwwwwwwwwwwwwwww",
"xxxxxxxxxxxxxxxxxxxxxxxxxx",
"yyy",
"zzzzzzzzzzzzzzzzzz"
]
test t1 d 1 25 0.0000 8.0000 1.0000 10 JSON [
"3",
"5",
"7",
"10",
"12",
"14",
"16",
"19",
"21",
"23"
test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 5 JSON [
"aaaa",
"bbb",
"bbbbbb",
"ccccccccc",
"dddddddd"
]
test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 4 JSON [
"1989-03-12",
"1990-05-15",
"1998-08-28",
"1999-07-23"
]
test t1 e 0.01 0.112 0.2250 8.0000 6.2000 5 JSON [
"0.01",
"0.012",
"0.05",
"0.1",
"0.112"
]
explain extended select * from t1 where b between '20' and '70';
test t1 f 1 5 0.2000 1.0000 6.4000 5 JSON [
"",
"",
"",
"",
""
]
SELECT * FROM mysql.index_stats;
db_name table_name index_name prefix_arity avg_frequency
test t1 PRIMARY 1 1.0000
test t1 idx1 1 6.4000
test t1 idx1 2 1.6875
test t1 idx2 1 7.0000
test t1 idx2 2 2.3846
test t1 idx3 1 8.5000
test t1 idx4 1 6.2000
test t1 idx4 2 1.6875
test t1 idx4 3 1.1304
SELECT COUNT(*) FROM t1;
COUNT(*)
40
explain extended select * from t1 where a between '20' and '70';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 25 10.00 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 40 57.50 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`test`.`t1`.`d` AS `d` from `test`.`t1` where `test`.`t1`.`b` between '20' and '70'
UPDATE mysql.column_stats SET histogram='["1", {"a": "b"}, "2"]' WHERE table_name='t1';
FLUSH TABLES;
SELECT * FROM t1;
ERROR HY000: Failed to parse histogram, encountered JSON_TYPE '1'.
UPDATE mysql.column_stats SET histogram='{}' WHERE table_name='t1';
FLUSH TABLES;
SELECT * FROM t1;
ERROR HY000: Failed to parse histogram, encountered JSON_TYPE '1'.
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`test`.`t1`.`d` AS `d`,`test`.`t1`.`e` AS `e`,`test`.`t1`.`f` AS `f` from `test`.`t1` where `test`.`t1`.`a` between '20' and '70'
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
DELETE FROM mysql.column_stats;
DROP TABLE t1;
create schema world;
use world;
set histogram_type='JSON';
set histogram_size=25;
ANALYZE TABLE Country PERSISTENT FOR ALL;
set histogram_size=50;
ANALYZE TABLE Country, City, CountryLanguage persistent for all;
SELECT column_name, min_value, max_value, hist_size, hist_type, histogram FROM mysql.column_stats;
column_name min_value max_value hist_size hist_type histogram
Code ABW ZWE 25 JSON [
Code ABW ZWE 50 JSON [
"ALB",
"ARM",
"AUS",
"BEL",
"BLZ",
"CAF",
"COG",
"CZE",
"ERI",
"FRO",
"GMB",
"GUY",
"IRL",
"KAZ",
"LBN",
"LVA",
"MKD",
"MUS",
"NIC",
"PAN",
"PRT",
"SAU",
"SMR",
"SYC",
"TMP",
"BHR",
"BMU",
"BRN",
"CAN",
"CIV",
"COK",
"CUB",
"DEU",
"DOM",
"ESH",
"FJI",
"FSM",
"GIB",
"GNQ",
"GUF",
"HMD",
"IDN",
"IRQ",
"JAM",
"KGZ",
"KWT",
"LBY",
"LTU",
"MCO",
"MEX",
"MMR",
"MSR",
"MYS",
"NFK",
"NOR",
"PAK",
"PHL",
"PRK",
"QAT",
"RWA",
"SGS",
"SLV",
"STP",
"SWZ",
"TGO",
"TKM",
"TUR",
"UKR",
"VIR"
"UZB",
"VIR",
"YEM"
]
Name Afghanistan Zimbabwe 25 JSON [
Name Afghanistan Zimbabwe 50 JSON [
"Andorra",
"Argentina",
"Azerbaijan",
"Barbados",
"Botswana",
"Cameroon",
"Cocos (Keeling) Islands",
"Czech Republic",
"El Salvador",
"France",
"Gibraltar",
"Guyana",
"Iran",
"Kenya",
"Libyan Arab Jamahiriya",
"Maldives",
"Micronesia, Federated States of",
"Nepal",
"Norfolk Island",
"Papua New Guinea",
"Romania",
"Samoa",
"Solomon Islands",
"Svalbard and Jan Mayen",
"Togo",
"Bermuda",
"Bouvet Island",
"Bulgaria",
"Canada",
"Chile",
"Colombia",
"Costa Rica",
"Côte d’Ivoire",
"Dominican Republic",
"Equatorial Guinea",
"Faroe Islands",
"French Guiana",
"Georgia",
"Greenland",
"Guinea",
"Heard Island and McDonald Islands",
"Iceland",
"Ireland",
"Japan",
"Kuwait",
"Lesotho",
"Lithuania",
"Malawi",
"Marshall Islands",
"Mayotte",
"Mongolia",
"Namibia",
"Netherlands Antilles",
"Nigeria",
"Norway",
"Panama",
"Philippines",
"Qatar",
"Saint Helena",
"Saint Vincent and the Grenadines",
"Senegal",
"Slovenia",
"South Georgia and the South Sandwich Islands",
"Suriname",
"Syria",
"Thailand",
"Tunisia",
"Uganda",
"Venezuela"
"United States",
"Venezuela",
"Western Sahara"
]
SurfaceArea 0.40 17075400.00 25 JSON [
SurfaceArea 0.40 17075400.00 50 JSON [
"14.00",
"36.00",
"78.00",
"151.00",
"261.00",
"388.00",
"618.00",
"1102.00",
"4000.00",
"10990.00",
"18274.00",
"27750.00",
"36188.00",
"51197.00",
"71740.00",
"93030.00",
"112622.00",
"163610.00",
"238391.00",
"283561.00",
"338145.00",
"449964.00",
"587041.00",
"796095.00",
"1104300.00",
"200.00",
"264.00",
"344.00",
"430.00",
"464.00",
"622.00",
"751.00",
"1399.00",
"2510.00",
"4033.00",
"8875.00",
"11000.00",
"14874.00",
"20256.00",
"25713.00",
"28051.00",
"30518.00",
"41526.00",
"48511.00",
"56785.00",
"69700.00",
"78866.00",
"90000.00",
"103000.00",
"111369.00",
"120538.00",
"147181.00",
"181035.00",
"214969.00",
"242900.00",
"274000.00",
"309500.00",
"331689.00",
"390757.00",
"447400.00",
"505992.00",
"581730.00",
"637657.00",
"774815.00",
"912050.00",
"1098581.00",
"1246700.00",
"1648195.00",
"2724900.00"
"2149690.00",
"2724900.00",
"9363520.00"
]
Population 0 1277558000 25 JSON [
Population 0 1277558000 50 JSON [
"0",
"1000",
"2500",
"8000",
"25000",
"65000",
"94000",
"181000",
"293000",
"453000",
"817000",
"1439200",
"2542000",
"3337000",
"3869000",
"4807000",
"5496000",
"7430000",
"8861400",
"10278100",
"11669000",
"16125000",
"22256000",
"28351000",
"40377000",
"17000",
"27000",
"38000",
"68000",
"78000",
"99000",
"149000",
"190000",
"241000",
"307000",
"428000",
"456000",
"638000",
"885000",
"1295000",
"1726000",
"2153000",
"2662000",
"3101000",
"3520000",
"3850000",
"4023000",
"4629000",
"5074000",
"5398700",
"6188000",
"6782000",
"7733000",
"8329000",
"9586000",
"10239000",
"10730000",
"11385000",
"14786000",
"15942000",
"18886000",
"22244000",
"23115000",
"25662000",
"31471000",
"39441700",
"50456000",
"61399000",
"111506000"
"68470000",
"111506000",
"170115000"
]
Capital 1 4074 25 JSON [
"62",
"149",
"201",
"553",
"645",
"902",
"922",
"1109",
"1530",
"1859",
"2296",
"2430",
"2452",
"2482",
"2689",
"2729",
"2831",
"2919",
"3047",
"3162",
"3209",
"3250",
"3336",
"3426",
"3538"
Capital 1 4074 50 JSON [
"35",
"63",
"129",
"150",
"187",
"204",
"538",
"554",
"586",
"652",
"764",
"904",
"917",
"926",
"937",
"1365",
"1464",
"1532",
"1800",
"1864",
"2256",
"2317",
"2409",
"2434",
"2441",
"2454",
"2463",
"2507",
"2514",
"2696",
"2728",
"2754",
"2821",
"2884",
"2914",
"2973",
"3018",
"3064",
"3161",
"3172",
"3208",
"3225",
"3248",
"3315",
"3334",
"3358",
"3425",
"3499",
"3537",
"3791"
]
ID 1 4079 10 JSON [
"371",
"742",
"1113",
"1484",
"1855",
"2225",
"2596",
"2967",
"3338",
"3709"
ID 1 4079 50 JSON [
"80",
"160",
"240",
"320",
"400",
"480",
"560",
"640",
"720",
"800",
"880",
"960",
"1040",
"1120",
"1200",
"1280",
"1360",
"1440",
"1520",
"1600",
"1680",
"1760",
"1840",
"1920",
"2000",
"2080",
"2160",
"2240",
"2320",
"2400",
"2480",
"2560",
"2640",
"2720",
"2800",
"2880",
"2960",
"3040",
"3120",
"3200",
"3280",
"3360",
"3440",
"3520",
"3600",
"3680",
"3760",
"3840",
"3920",
"4000"
]
Name A Coruña (La Coruña) Århus 10 JSON [
"Berdytšiv",
"Clermont-Ferrand",
"Gatineau",
"Itapecerica da Serra",
"Kuytun",
"Milano",
"Ota",
"Roanoke",
"Split",
"Ulsan"
Name A Coruña (La Coruña) Århus 50 JSON [
"Allentown",
"Araguari",
"Bahtim",
"Batangas",
"Bialystok",
"Brampton",
"Calama",
"Changchun",
"Ciomas",
"Cuautla",
"Detroit",
"Effon-Alaiye",
"Firozabad",
"Gebze",
"Guangyuan",
"Hangzhou",
"Hradec Králové",
"Inazawa",
"Jalib al-Shuyukh",
"Jubayl",
"Kassel",
"Kitakyushu",
"Kunshan",
"Le Mans",
"Longueuil",
"Malang",
"Mati",
"Mishan",
"Muroran",
"Natal",
"North York",
"Omsk",
"Palu",
"Phoenix",
"Poznan",
"Quezon",
"Rishra",
"Salem",
"Sancti-Spíritus",
"Sekondi-Takoradi",
"Silao",
"Stoke-on-Trent",
"Taegu",
"Teheran",
"Tomsk",
"Târgu Mures",
"Varginha",
"Weifang",
"Yangjiang",
"Zhaodong"
]
Country ABW ZWE 10 JSON [
Country ABW ZWE 50 JSON [
"ARM",
"BHS",
"BRA",
"BRB",
"BRN",
"CAN",
"CHN",
"CIV",
"CMR",
"COD",
"COG",
"COL",
"DEU",
"DZA",
"ESP",
"FRA",
"GBR",
"IDN",
"IND",
"IRL",
"IRN",
"IRQ",
"ISL",
"ISR",
"ITA",
"JPN",
"KAZ",
"KEN",
"KOR",
"LKA",
"MEX",
"MHL",
"MMR",
"NGA",
"NZL",
"PER",
"PHL",
"POL",
"QAT",
"RUS",
"USA"
"RWA",
"SAU",
"TCD",
"TUR",
"UKR",
"USA",
"UZB",
"VAT",
"VCT",
"VNM"
]
Population 42 10500000 10 JSON [
"96002",
"105819",
"118326",
"132318",
"152397",
"181900",
"221400",
"288173",
"398300",
"670208"
Population 42 10500000 50 JSON [
"50699",
"90601",
"92583",
"94600",
"96800",
"98781",
"100887",
"102681",
"105119",
"107329",
"109500",
"112375",
"115532",
"118718",
"121600",
"124207",
"126820",
"130000",
"133642",
"137776",
"142044",
"146439",
"151060",
"157300",
"163849",
"170428",
"176576",
"183100",
"189569",
"197254",
"206158",
"216735",
"227657",
"241649",
"254842",
"270251",
"286900",
"304477",
"326399",
"349246",
"372840",
"409100",
"443727",
"483155",
"540828",
"636765",
"764902",
"993400",
"1300977",
"2154376"
]
Country ABW ZWE 10 JSON [
"BGD",
"CMR",
"ESP",
"GUF",
"KAZ",
Country ABW ZWE 50 JSON [
"ALB",
"ASM",
"AZE",
"BFA",
"BHS",
"BRA",
"CAF",
"CHE",
"CIV",
"COD",
"CPV",
"CZE",
"DOM",
"EST",
"FRA",
"GBR",
"GIN",
"GRC",
"HKG",
"IDN",
"IND",
"ISL",
"JPN",
"KGZ",
"LAO",
"LIE",
"LVA",
"MDA",
"NAM",
"PNG",
"SVK",
"UGA"
"MLI",
"MNG",
"MRT",
"MYS",
"NER",
"NIU",
"NRU",
"PAN",
"PLW",
"PYF",
"RUS",
"SDN",
"SLE",
"SVN",
"TCD",
"THA",
"TUR",
"TZA",
"UKR",
"UZB",
"VNM",
"ZAF"
]
Language Abhyasi [South]Mande 10 JSON [
"Bariba",
"Creole English",
Language Abhyasi [South]Mande 50 JSON [
"Amhara",
"Arabic",
"Araucan",
"Bakhtyari",
"Belorussian",
"Bubi",
"Cebuano",
"Chinese",
"Comorian",
"Creole French",
"Danish",
"Embera",
"English",
"Georgiana",
"Eskimo Languages",
"Estonian",
"French",
"Fries",
"Futuna",
"German",
"Greek",
"Hakka",
"Hui",
"Italian",
"Lomwe",
"Moravian",
"Punjabi",
"Soga",
"Tigrinja"
"Joruba",
"Kazakh",
"Kongo",
"Kurdish",
"Luchazi",
"Makua",
"Malinke",
"Marshallese",
"Mixed Languages",
"Nauru",
"Nung",
"Pangasinan",
"Polish",
"Portuguese",
"Romanian",
"Russian",
"Sara",
"Shona",
"Songhai",
"Spanish",
"Sranantonga",
"Tamashek",
"Thai",
"Tswana",
"Tuvalu",
"Urdu",
"Wolea"
]
Percentage 0.0 99.9 10 JSON [
Percentage 0.0 99.9 50 JSON [
"0.0",
"0.1",
"0.2",
"0.3",
"0.4",
"0.5",
"0.6",
"0.7",
"0.8",
"0.9",
"1.0",
"1.1",
"1.3",
"1.4",
"2.4",
"3.9",
"6.5",
"9.6",
"17.7",
"45.5",
"87.5"
"1.6",
"1.8",
"2.1",
"2.3",
"2.5",
"2.9",
"3.2",
"3.5",
"3.8",
"4.4",
"4.9",
"5.5",
"5.9",
"6.6",
"7.4",
"7.8",
"8.6",
"9.2",
"10.3",
"11.5",
"12.9",
"14.6",
"17.1",
"20.3",
"23.8",
"31.8",
"39.4",
"47.5",
"55.1",
"66.5",
"77.2",
"86.0",
"89.9",
"94.3",
"97.3",
"99.0"
]
explain extended select * from Country where 'Code' between 'BBC' and 'GGG';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 100.00
Warnings:
Note 1003 select `world`.`Country`.`Code` AS `Code`,`world`.`Country`.`Name` AS `Name`,`world`.`Country`.`SurfaceArea` AS `SurfaceArea`,`world`.`Country`.`Population` AS `Population`,`world`.`Country`.`Capital` AS `Capital` from `world`.`Country` where 1
analyze select * from Country where 'Code' between 'BBC' and 'GGG';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 239.00 100.00 100.00
set histogram_type=@save_histogram_type;
set histogram_size=@save_histogram_size;
DROP SCHEMA world;
......@@ -12,34 +12,80 @@ set @save_histogram_type=@@histogram_type;
set @save_histogram_size=@@histogram_size;
CREATE TABLE t1 (
a int,
b varchar(32),
c char(2),
d double
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 SELECT seq, seq, seq, seq from seq_1_to_25;
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 to be < row count (25 in this case) to see how histogram behaves
set histogram_size=10;
set histogram_size=25;
ANALYZE TABLE t1 PERSISTENT FOR ALL;
SELECT * FROM mysql.column_stats WHERE table_name='t1';
explain extended select * from t1 where b between '20' and '70';
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;
# We then 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
SELECT * FROM t1;
explain extended select * from t1 where a between '20' and '70';
analyze select * from t1 where a between '20' and '70';
UPDATE mysql.column_stats SET histogram='{}' WHERE table_name='t1';
FLUSH TABLES;
--error ER_JSON_HISTOGRAM_PARSE_FAILED
SELECT * FROM t1;
# 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';
DELETE FROM mysql.column_stats;
DROP TABLE t1;
......@@ -56,12 +102,14 @@ use world;
--enable_query_log
set histogram_type='JSON';
set histogram_size=25;
set histogram_size=50;
--disable_result_log
ANALYZE TABLE Country PERSISTENT FOR ALL;
ANALYZE TABLE Country, City, CountryLanguage persistent for all;
--enable_result_log
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';
set histogram_type=@save_histogram_type;
set histogram_size=@save_histogram_size;
......
......@@ -1564,9 +1564,9 @@ int Histogram_json::find_bucket(Field *field, const uchar *endpoint)
mid_val = histogram_bounds[mid];
int res = field->key_cmp((uchar*) mid_val.data(), endpoint);
min_bucket_index = mid;
if (res < 0) {
low = mid + 1;
min_bucket_index = mid;
} else if (res > 0) {
high = mid - 1;
} else {
......@@ -1574,6 +1574,9 @@ int Histogram_json::find_bucket(Field *field, const uchar *endpoint)
break;
}
}
if (min_bucket_index == -1)
min_bucket_index = high;
return min_bucket_index;
}
......
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