[Commits] 348d3788a00: JSON_HB histogram: represent values of BIT() columns in hex always
revision-id: 348d3788a0043c437e9c2fc92cd621dc32b6845a (mariadb-10.6.1-352-g348d3788a00) parent(s): 21a810253c6d120e75c421267afa913b5c21be3b author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2022-01-14 20:04:19 +0300 message: JSON_HB histogram: represent values of BIT() columns in hex always --- mysql-test/main/statistics_json.result | 60 +++++++++++++++++++++++++++------- mysql-test/main/statistics_json.test | 14 ++++++++ sql/opt_histogram_json.cc | 22 ++++++++++--- 3 files changed, 80 insertions(+), 16 deletions(-) diff --git a/mysql-test/main/statistics_json.result b/mysql-test/main/statistics_json.result index 9eb8cf87c44..40b2e1bb73d 100644 --- a/mysql-test/main/statistics_json.result +++ b/mysql-test/main/statistics_json.result @@ -374,23 +374,23 @@ test t1 f 1 5 0.2000 6.4000 4 JSON_HB { "collected_by": "REPLACED", "histogram_hb": [ { - "start": "\u0001", + "start_hex": "01", "size": 0.28125, "ndv": 2 }, { - "start": "\u0002", + "start_hex": "02", "size": 0.28125, "ndv": 2 }, { - "start": "\u0004", + "start_hex": "04", "size": 0.3125, "ndv": 1 }, { - "start": "\u0005", - "end": "\u0005", + "start_hex": "05", + "end_hex": "05", "size": 0.125, "ndv": 1 } @@ -586,28 +586,28 @@ test t1 f 1 5 0.2000 6.4000 5 JSON_HB { "collected_by": "REPLACED", "histogram_hb": [ { - "start": "\u0001", + "start_hex": "01", "size": 0.125, "ndv": 1 }, { - "start": "\u0002", + "start_hex": "02", "size": 0.25, "ndv": 1 }, { - "start": "\u0003", + "start_hex": "03", "size": 0.1875, "ndv": 1 }, { - "start": "\u0004", + "start_hex": "04", "size": 0.3125, "ndv": 1 }, { - "start": "\u0005", - "end": "\u0005", + "start_hex": "05", + "end_hex": "05", "size": 0.125, "ndv": 1 } @@ -8284,3 +8284,41 @@ analyze select f from t1 where f in (77, 1, 144, 73, 14, 12); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 10.00 10.00 Using where drop table t1; +# +# Test that histograms over BIT fields use hex +# +create table t1 (a BIT(64)); +insert into t1 values +(x'01'),(x'10'),(x'BE562B1A99001918'); +set histogram_type= JSON_HB; +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 histogram +from mysql.column_stats where table_name='t1' and db_name=database(); +histogram +{ + "target_histogram_size": 254, + "collected_at": "2022-01-14 20:01:53 MSK", + "collected_by": "10.8.0-MariaDB-debug-log", + "histogram_hb": [ + { + "start_hex": "0000000000000001", + "size": 0.333333333, + "ndv": 1 + }, + { + "start_hex": "0000000000000010", + "size": 0.333333333, + "ndv": 1 + }, + { + "start_hex": "BE562B1A99001918", + "end_hex": "BE562B1A99001918", + "size": 0.333333333, + "ndv": 1 + } + ] +} +drop table t1; diff --git a/mysql-test/main/statistics_json.test b/mysql-test/main/statistics_json.test index 0a1b886f8fd..ea017c97989 100644 --- a/mysql-test/main/statistics_json.test +++ b/mysql-test/main/statistics_json.test @@ -445,3 +445,17 @@ analyze table t1 persistent for all; analyze select f from t1 where f in (77, 1, 144, 73, 14, 12); drop table t1; + +--echo # +--echo # Test that histograms over BIT fields use hex +--echo # +create table t1 (a BIT(64)); +insert into t1 values + (x'01'),(x'10'),(x'BE562B1A99001918'); +set histogram_type= JSON_HB; +analyze table t1 persistent for all; +select histogram +from mysql.column_stats where table_name='t1' and db_name=database(); + +drop table t1; + diff --git a/sql/opt_histogram_json.cc b/sql/opt_histogram_json.cc index 73284025511..55848c58e2d 100644 --- a/sql/opt_histogram_json.cc +++ b/sql/opt_histogram_json.cc @@ -122,6 +122,12 @@ class Histogram_json_builder : public Histogram_builder /* Number of the buckets already collected */ uint n_buckets_collected; + /* + TRUE means do not try to represent values as UTF-8 text in histogram + storage. Use start_hex/end_hex for all values. + */ + bool force_binary; + /* Data about the bucket we are filling now */ struct CurBucket { @@ -135,6 +141,7 @@ class Histogram_json_builder : public Histogram_builder /* Used to create the JSON representation of the histogram. */ Json_writer writer; + public: Histogram_json_builder(Histogram_json_hb *hist, Field *col, uint col_len, @@ -155,6 +162,7 @@ class Histogram_json_builder : public Histogram_builder n_buckets_collected= 0; bucket.ndv= 0; bucket.size= 0; + force_binary= (col->type() == MYSQL_TYPE_BIT); writer.start_object(); append_histogram_params(); @@ -244,12 +252,16 @@ class Histogram_json_builder : public Histogram_builder // Escape the value for JSON StringBuffer<MAX_FIELD_WIDTH> escaped_val; - int rc= json_escape_to_string(str, &escaped_val); - if (!rc) + int rc= JSON_ERROR_ILLEGAL_SYMBOL; + if (!force_binary) { - writer.add_member(is_start? "start": "end"); - writer.add_str(escaped_val.c_ptr_safe()); - return false; + rc= json_escape_to_string(str, &escaped_val); + if (!rc) + { + writer.add_member(is_start? "start": "end"); + writer.add_str(escaped_val.c_ptr_safe()); + return false; + } } if (rc == JSON_ERROR_ILLEGAL_SYMBOL) {
participants (1)
-
psergey