Skip to content

Commit 1d14176

Browse files
committed
MDEV-26519: Improved histograms: Make JSON parser efficient
Previous JSON parser was using an API which made the parsing inefficient: the same JSON contents was parsed again and again. Switch to using a lower-level parsing API which allows to do parsing in an efficient way.
1 parent be55ad0 commit 1d14176

File tree

7 files changed

+351
-181
lines changed

7 files changed

+351
-181
lines changed

mysql-test/main/statistics_json.result

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,54 +4263,79 @@ UPDATE mysql.column_stats
42634263
SET histogram='["not-what-you-expect"]' WHERE table_name='t1_json';
42644264
FLUSH TABLES;
42654265
explain select * from t1_json limit 1;
4266-
ERROR HY000: Failed to parse histogram: Root JSON element must be a JSON object at offset 0.
4266+
id select_type table type possible_keys key key_len ref rows Extra
4267+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
4268+
Warnings:
4269+
Warning 4186 Failed to parse histogram for table test.t1_json: Root JSON element must be a JSON object at offset 1.
42674270
UPDATE mysql.column_stats
42684271
SET histogram='{"histogram_hb_v2":"not-histogram"}' WHERE table_name='t1_json';
42694272
FLUSH TABLES;
42704273
explain select * from t1_json limit 1;
4271-
ERROR HY000: Failed to parse histogram: A JSON array expected at offset 0.
4274+
id select_type table type possible_keys key key_len ref rows Extra
4275+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
4276+
Warnings:
4277+
Warning 4186 Failed to parse histogram for table test.t1_json: histogram_hb_v2 must contain an array at offset 35.
42724278
UPDATE mysql.column_stats
42734279
SET histogram='{"histogram_hb_v2":["not-a-bucket"]}'
42744280
WHERE table_name='t1_json';
42754281
FLUSH TABLES;
42764282
explain select * from t1_json limit 1;
4277-
ERROR HY000: Failed to parse histogram: Object expected at offset 19.
4283+
id select_type table type possible_keys key key_len ref rows Extra
4284+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
4285+
Warnings:
4286+
Warning 4186 Failed to parse histogram for table test.t1_json: Expected an object in the buckets array at offset 35.
42784287
UPDATE mysql.column_stats
42794288
SET histogram='{"histogram_hb_v2":[{"no-expected-members":1}]}'
42804289
WHERE table_name='t1_json';
42814290
FLUSH TABLES;
42824291
explain select * from t1_json limit 1;
4283-
ERROR HY000: Failed to parse histogram: .start member must be present and be a scalar at offset 20.
4292+
id select_type table type possible_keys key key_len ref rows Extra
4293+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
4294+
Warnings:
4295+
Warning 4186 Failed to parse histogram for table test.t1_json: "start" element not present at offset 45.
42844296
UPDATE mysql.column_stats
42854297
SET histogram='{"histogram_hb_v2":[{"start":{}}]}'
42864298
WHERE table_name='t1_json';
42874299
FLUSH TABLES;
42884300
explain select * from t1_json limit 1;
4289-
ERROR HY000: Failed to parse histogram: .start member must be present and be a scalar at offset 20.
4301+
id select_type table type possible_keys key key_len ref rows Extra
4302+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
4303+
Warnings:
4304+
Warning 4186 Failed to parse histogram for table test.t1_json: "size" element not present at offset 31.
42904305
UPDATE mysql.column_stats
42914306
SET histogram='{"histogram_hb_v2":[{"start":"aaa", "size":"not-an-integer"}]}'
42924307
WHERE table_name='t1_json';
42934308
FLUSH TABLES;
42944309
explain select * from t1_json limit 1;
4295-
ERROR HY000: Failed to parse histogram: .size member must be present and be a scalar at offset 20.
4310+
id select_type table type possible_keys key key_len ref rows Extra
4311+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
4312+
Warnings:
4313+
Warning 4186 Failed to parse histogram for table test.t1_json: "ndv" element not present at offset 60.
42964314
UPDATE mysql.column_stats
42974315
SET histogram='{"histogram_hb_v2":[{"start":"aaa", "size":0.25}]}'
42984316
WHERE table_name='t1_json';
42994317
FLUSH TABLES;
43004318
explain select * from t1_json limit 1;
4301-
ERROR HY000: Failed to parse histogram: .ndv member must be present and be a scalar at offset 20.
4319+
id select_type table type possible_keys key key_len ref rows Extra
4320+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
4321+
Warnings:
4322+
Warning 4186 Failed to parse histogram for table test.t1_json: "ndv" element not present at offset 48.
43024323
UPDATE mysql.column_stats
43034324
SET histogram='{"histogram_hb_v2":[{"start":"aaa", "size":0.25, "ndv":1}]}'
43044325
WHERE table_name='t1_json';
43054326
FLUSH TABLES;
43064327
explain select * from t1_json limit 1;
4307-
ERROR HY000: Failed to parse histogram: .end must be present in the last bucket and only there at offset 0.
4328+
id select_type table type possible_keys key key_len ref rows Extra
4329+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
43084330
UPDATE mysql.column_stats
43094331
SET histogram='{"histogram_hb_v2":[]}'
43104332
WHERE table_name='t1_json';
43114333
FLUSH TABLES;
43124334
explain select * from t1_json limit 1;
4313-
ERROR HY000: Failed to parse histogram: .end must be present in the last bucket and only there at offset 0.
4335+
id select_type table type possible_keys key key_len ref rows Extra
4336+
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10
4337+
Warnings:
4338+
Warning 4186 Failed to parse histogram for table test.t1_json: Histogram must have at least one bucket at offset 21.
43144339
create table t2 (
43154340
city varchar(100)
43164341
);

mysql-test/main/statistics_json.test

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,62 +46,53 @@ drop table ten;
4646
UPDATE mysql.column_stats
4747
SET histogram='["not-what-you-expect"]' WHERE table_name='t1_json';
4848
FLUSH TABLES;
49-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
5049
explain select * from t1_json limit 1;
5150

5251
UPDATE mysql.column_stats
5352
SET histogram='{"histogram_hb_v2":"not-histogram"}' WHERE table_name='t1_json';
5453
FLUSH TABLES;
55-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
5654
explain select * from t1_json limit 1;
5755

5856
UPDATE mysql.column_stats
5957
SET histogram='{"histogram_hb_v2":["not-a-bucket"]}'
6058
WHERE table_name='t1_json';
6159
FLUSH TABLES;
62-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
6360
explain select * from t1_json limit 1;
6461

6562
UPDATE mysql.column_stats
6663
SET histogram='{"histogram_hb_v2":[{"no-expected-members":1}]}'
6764
WHERE table_name='t1_json';
6865
FLUSH TABLES;
69-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
7066
explain select * from t1_json limit 1;
7167

7268
UPDATE mysql.column_stats
7369
SET histogram='{"histogram_hb_v2":[{"start":{}}]}'
7470
WHERE table_name='t1_json';
7571
FLUSH TABLES;
76-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
7772
explain select * from t1_json limit 1;
7873

7974
UPDATE mysql.column_stats
8075
SET histogram='{"histogram_hb_v2":[{"start":"aaa", "size":"not-an-integer"}]}'
8176
WHERE table_name='t1_json';
8277
FLUSH TABLES;
83-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
8478
explain select * from t1_json limit 1;
8579

8680
UPDATE mysql.column_stats
8781
SET histogram='{"histogram_hb_v2":[{"start":"aaa", "size":0.25}]}'
8882
WHERE table_name='t1_json';
8983
FLUSH TABLES;
90-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
9184
explain select * from t1_json limit 1;
9285

9386
UPDATE mysql.column_stats
9487
SET histogram='{"histogram_hb_v2":[{"start":"aaa", "size":0.25, "ndv":1}]}'
9588
WHERE table_name='t1_json';
9689
FLUSH TABLES;
97-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
9890
explain select * from t1_json limit 1;
9991

10092
UPDATE mysql.column_stats
10193
SET histogram='{"histogram_hb_v2":[]}'
10294
WHERE table_name='t1_json';
10395
FLUSH TABLES;
104-
--error ER_JSON_HISTOGRAM_PARSE_FAILED
10596
explain select * from t1_json limit 1;
10697

10798
--source include/have_sequence.inc

0 commit comments

Comments
 (0)