1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

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

This commit is contained in:
Sergei Petrunia
2022-01-14 20:04:19 +03:00
parent dae20dde4e
commit 4842a56356
3 changed files with 81 additions and 16 deletions

View File

@ -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": "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;

View File

@ -445,3 +445,18 @@ 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;
--source include/json_hb_histogram.inc
select histogram
from mysql.column_stats where table_name='t1' and db_name=database();
drop table t1;

View File

@ -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 @@ public:
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 @@ private:
// 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)
{