Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
382250c0
Commit
382250c0
authored
Sep 11, 2021
by
Sergei Petrunia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address review input
parent
cf8927e9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
4 deletions
+78
-4
mysql-test/main/statistics_json.result
mysql-test/main/statistics_json.result
+48
-0
mysql-test/main/statistics_json.test
mysql-test/main/statistics_json.test
+23
-0
sql/opt_histogram_json.cc
sql/opt_histogram_json.cc
+4
-1
sql/opt_histogram_json.h
sql/opt_histogram_json.h
+3
-3
No files found.
mysql-test/main/statistics_json.result
View file @
382250c0
...
...
@@ -7397,3 +7397,51 @@ id select_type table type possible_keys key key_len ref rows r_rows filtered r_f
set histogram_type=@save_histogram_type;
set histogram_size=@save_histogram_size;
DROP SCHEMA world;
use test;
create table t10 (
a varchar(10)
);
#
# Histograms are not collected for empty tables:
#
analyze table t10 persistent for all;
Table Op Msg_type Msg_text
test.t10 analyze status Engine-independent statistics collected
test.t10 analyze status Table is already up to date
select histogram
from mysql.column_stats where table_name='t10' and db_name=database();
histogram
NULL
#
# Try with n_buckets > n_rows
#
insert into t10 values ('Berlin'),('Paris'),('Rome');
set histogram_size=10, histogram_type='json_hb';
analyze table t10 persistent for all;
Table Op Msg_type Msg_text
test.t10 analyze status Engine-independent statistics collected
test.t10 analyze status OK
select histogram
from mysql.column_stats where table_name='t10' and db_name=database();
histogram
{
"histogram_hb_v2": [
{
"start": "Berlin",
"size": 0.333333333,
"ndv": 1
},
{
"start": "Paris",
"size": 0.333333333,
"ndv": 1
},
{
"start": "Rome",
"end": "Rome",
"size": 0.333333333,
"ndv": 1
}
]
}
drop table t10;
mysql-test/main/statistics_json.test
View file @
382250c0
...
...
@@ -149,3 +149,26 @@ set histogram_type=@save_histogram_type;
set
histogram_size
=@
save_histogram_size
;
DROP
SCHEMA
world
;
use
test
;
create
table
t10
(
a
varchar
(
10
)
);
--
echo
#
--
echo
# Histograms are not collected for empty tables:
--
echo
#
analyze
table
t10
persistent
for
all
;
select
histogram
from
mysql
.
column_stats
where
table_name
=
't10'
and
db_name
=
database
();
--
echo
#
--
echo
# Try with n_buckets > n_rows
--
echo
#
insert
into
t10
values
(
'Berlin'
),(
'Paris'
),(
'Rome'
);
set
histogram_size
=
10
,
histogram_type
=
'json_hb'
;
analyze
table
t10
persistent
for
all
;
select
histogram
from
mysql
.
column_stats
where
table_name
=
't10'
and
db_name
=
database
();
drop
table
t10
;
sql/opt_histogram_json.cc
View file @
382250c0
...
...
@@ -59,6 +59,8 @@ class Histogram_json_builder : public Histogram_builder
:
Histogram_builder
(
col
,
col_len
,
rows
),
histogram
(
hist
)
{
bucket_capacity
=
records
/
histogram
->
get_width
();
if
(
bucket_capacity
==
0
)
bucket_capacity
=
1
;
hist_width
=
histogram
->
get_width
();
n_buckets_collected
=
0
;
bucket
.
ndv
=
0
;
...
...
@@ -227,7 +229,8 @@ class Histogram_json_builder : public Histogram_builder
writer
.
end_object
();
Binary_string
*
json_string
=
(
Binary_string
*
)
writer
.
output
.
get_string
();
histogram
->
set_json_text
(
n_buckets_collected
,
(
uchar
*
)
json_string
->
c_ptr
());
json_string
->
c_ptr
(),
(
size_t
)
json_string
->
length
());
}
};
...
...
sql/opt_histogram_json.h
View file @
382250c0
...
...
@@ -113,11 +113,11 @@ class Histogram_json_hb : public Histogram_base
double
range_selectivity
(
Field
*
field
,
key_range
*
min_endp
,
key_range
*
max_endp
)
override
;
void
set_json_text
(
ulonglong
sz
,
uchar
*
json_text_arg
)
void
set_json_text
(
ulonglong
sz
,
const
char
*
json_text_arg
,
size_t
json_text_len
)
{
size
=
(
size_t
)
sz
;
json_text
.
assign
((
const
char
*
)
json_text_arg
,
strlen
((
const
char
*
)
json_text_arg
));
json_text
.
assign
(
json_text_arg
,
json_text_len
);
}
private:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment