Commit 4842a563 authored by Sergei Petrunia's avatar Sergei Petrunia

JSON_HB histogram: represent values of BIT() columns in hex always

parent dae20dde
...@@ -374,23 +374,23 @@ test t1 f 1 5 0.2000 6.4000 4 JSON_HB { ...@@ -374,23 +374,23 @@ test t1 f 1 5 0.2000 6.4000 4 JSON_HB {
"collected_by": "REPLACED", "collected_by": "REPLACED",
"histogram_hb": [ "histogram_hb": [
{ {
"start": "\u0001", "start_hex": "01",
"size": 0.28125, "size": 0.28125,
"ndv": 2 "ndv": 2
}, },
{ {
"start": "\u0002", "start_hex": "02",
"size": 0.28125, "size": 0.28125,
"ndv": 2 "ndv": 2
}, },
{ {
"start": "\u0004", "start_hex": "04",
"size": 0.3125, "size": 0.3125,
"ndv": 1 "ndv": 1
}, },
{ {
"start": "\u0005", "start_hex": "05",
"end": "\u0005", "end_hex": "05",
"size": 0.125, "size": 0.125,
"ndv": 1 "ndv": 1
} }
...@@ -586,28 +586,28 @@ test t1 f 1 5 0.2000 6.4000 5 JSON_HB { ...@@ -586,28 +586,28 @@ test t1 f 1 5 0.2000 6.4000 5 JSON_HB {
"collected_by": "REPLACED", "collected_by": "REPLACED",
"histogram_hb": [ "histogram_hb": [
{ {
"start": "\u0001", "start_hex": "01",
"size": 0.125, "size": 0.125,
"ndv": 1 "ndv": 1
}, },
{ {
"start": "\u0002", "start_hex": "02",
"size": 0.25, "size": 0.25,
"ndv": 1 "ndv": 1
}, },
{ {
"start": "\u0003", "start_hex": "03",
"size": 0.1875, "size": 0.1875,
"ndv": 1 "ndv": 1
}, },
{ {
"start": "\u0004", "start_hex": "04",
"size": 0.3125, "size": 0.3125,
"ndv": 1 "ndv": 1
}, },
{ {
"start": "\u0005", "start_hex": "05",
"end": "\u0005", "end_hex": "05",
"size": 0.125, "size": 0.125,
"ndv": 1 "ndv": 1
} }
...@@ -8284,3 +8284,41 @@ analyze select f from t1 where f in (77, 1, 144, 73, 14, 12); ...@@ -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 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 1 SIMPLE t1 ALL NULL NULL NULL NULL 20 20.00 10.00 10.00 Using where
drop table t1; 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": "REPLACED",
"collected_by": "REPLACED",
"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;
...@@ -445,3 +445,18 @@ analyze table t1 persistent for all; ...@@ -445,3 +445,18 @@ analyze table t1 persistent for all;
analyze select f from t1 where f in (77, 1, 144, 73, 14, 12); analyze select f from t1 where f in (77, 1, 144, 73, 14, 12);
drop table t1; 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;
--source include/json_hb_histogram.inc
select histogram
from mysql.column_stats where table_name='t1' and db_name=database();
drop table t1;
...@@ -122,6 +122,12 @@ class Histogram_json_builder : public Histogram_builder ...@@ -122,6 +122,12 @@ class Histogram_json_builder : public Histogram_builder
/* Number of the buckets already collected */ /* Number of the buckets already collected */
uint n_buckets_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 */ /* Data about the bucket we are filling now */
struct CurBucket struct CurBucket
{ {
...@@ -135,6 +141,7 @@ class Histogram_json_builder : public Histogram_builder ...@@ -135,6 +141,7 @@ class Histogram_json_builder : public Histogram_builder
/* Used to create the JSON representation of the histogram. */ /* Used to create the JSON representation of the histogram. */
Json_writer writer; Json_writer writer;
public: public:
Histogram_json_builder(Histogram_json_hb *hist, Field *col, uint col_len, Histogram_json_builder(Histogram_json_hb *hist, Field *col, uint col_len,
...@@ -155,6 +162,7 @@ class Histogram_json_builder : public Histogram_builder ...@@ -155,6 +162,7 @@ class Histogram_json_builder : public Histogram_builder
n_buckets_collected= 0; n_buckets_collected= 0;
bucket.ndv= 0; bucket.ndv= 0;
bucket.size= 0; bucket.size= 0;
force_binary= (col->type() == MYSQL_TYPE_BIT);
writer.start_object(); writer.start_object();
append_histogram_params(); append_histogram_params();
...@@ -244,13 +252,17 @@ class Histogram_json_builder : public Histogram_builder ...@@ -244,13 +252,17 @@ class Histogram_json_builder : public Histogram_builder
// Escape the value for JSON // Escape the value for JSON
StringBuffer<MAX_FIELD_WIDTH> escaped_val; StringBuffer<MAX_FIELD_WIDTH> escaped_val;
int rc= json_escape_to_string(str, &escaped_val); int rc= JSON_ERROR_ILLEGAL_SYMBOL;
if (!force_binary)
{
rc= json_escape_to_string(str, &escaped_val);
if (!rc) if (!rc)
{ {
writer.add_member(is_start? "start": "end"); writer.add_member(is_start? "start": "end");
writer.add_str(escaped_val.c_ptr_safe()); writer.add_str(escaped_val.c_ptr_safe());
return false; return false;
} }
}
if (rc == JSON_ERROR_ILLEGAL_SYMBOL) if (rc == JSON_ERROR_ILLEGAL_SYMBOL)
{ {
escaped_val.set_hex(val.ptr(), val.length()); escaped_val.set_hex(val.ptr(), val.length());
......
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