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
096995b1
Commit
096995b1
authored
Aug 22, 2021
by
Michael Okoko
Committed by
Sergei Petrunia
Jan 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix column range cardinality crash when histogram is null
Signed-off-by:
Michael Okoko
<
okokomichaels@outlook.com
>
parent
058a90e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
22 deletions
+43
-22
mysql-test/main/statistics.result
mysql-test/main/statistics.result
+2
-1
mysql-test/main/statistics_json.result
mysql-test/main/statistics_json.result
+2
-2
sql/sql_statistics.cc
sql/sql_statistics.cc
+39
-19
No files found.
mysql-test/main/statistics.result
View file @
096995b1
set @SINGLE_PREC_TYPE='single_prec_hb';
set @DOUBLE_PREC_TYPE='double_prec_hb';
set @DEFAULT_HIST_TYPE=@@histogram_type;
drop table if exists t1,t2;
set @save_use_stat_tables=@@use_stat_tables;
set @save_histogram_size=@@global.histogram_size;
set @@global.histogram_size=0,@@local.histogram_size=0;
set @save_hist_type=@
@histogram_type
;
set @save_hist_type=@
DEFAULT_HIST_TYPE
;
set histogram_type=@SINGLE_PREC_TYPE;
DELETE FROM mysql.table_stats;
DELETE FROM mysql.column_stats;
...
...
mysql-test/main/statistics_json.result
View file @
096995b1
...
...
@@ -2441,7 +2441,7 @@ Warnings:
Note 1003 select `test`.`t1_json`.`a` AS `a` from `test`.`t1_json` where `test`.`t1_json`.`a` < 'b-1a'
analyze select * from t1_json where a > 'zzzzzzzzz';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10 10.00
1
0.00 0.00 Using where
1 SIMPLE t1_json ALL NULL NULL NULL NULL 10 10.00 0.00 0.00 Using where
UPDATE mysql.column_stats SET histogram='["a-1", "a-2", {"a": "b"}, "a-3"]' WHERE table_name='t1_json';
FLUSH TABLES;
explain extended select * from t1_json where a between 'a-3a' and 'zzzzzzzzz';
...
...
@@ -2475,7 +2475,7 @@ id select_type table type possible_keys key key_len ref rows r_rows filtered r_f
1 SIMPLE users ALL NULL NULL NULL NULL 101 101.00 2.00 1.98 Using where
explain extended select * from users where city < 'Lagos';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE users ALL NULL NULL NULL NULL 101
50.00
Using where
1 SIMPLE users ALL NULL NULL NULL NULL 101
3.58
Using where
Warnings:
Note 1003 select `test`.`users`.`city` AS `city` from `test`.`users` where `test`.`users`.`city` < 'Lagos'
drop table t1_bin;
...
...
sql/sql_statistics.cc
View file @
096995b1
...
...
@@ -4364,10 +4364,37 @@ double get_column_range_cardinality(Field *field,
{
if
(
col_stats
->
min_max_values_are_provided
())
{
Histogram_base
*
hist
=
col_stats
->
histogram_
;
double
sel
=
hist
->
range_selectivity
(
field
,
min_endp
,
max_endp
);
Histogram_base
*
hist
=
col_stats
->
histogram_
;
double
sel
;
if
(
hist
&&
hist
->
is_usable
(
thd
))
{
sel
=
hist
->
range_selectivity
(
field
,
min_endp
,
max_endp
);
set_if_bigger
(
res
,
col_stats
->
get_avg_frequency
());
}
else
{
double
min_mp_pos
,
max_mp_pos
;
if
(
min_endp
&&
!
(
field
->
null_ptr
&&
min_endp
->
key
[
0
]))
{
store_key_image_to_rec
(
field
,
(
uchar
*
)
min_endp
->
key
,
field
->
key_length
());
min_mp_pos
=
field
->
pos_in_interval
(
col_stats
->
min_value
,
col_stats
->
max_value
);
}
else
min_mp_pos
=
0.0
;
if
(
max_endp
)
{
store_key_image_to_rec
(
field
,
(
uchar
*
)
max_endp
->
key
,
field
->
key_length
());
max_mp_pos
=
field
->
pos_in_interval
(
col_stats
->
min_value
,
col_stats
->
max_value
);
}
else
max_mp_pos
=
1.0
;
sel
=
(
max_mp_pos
-
min_mp_pos
);
}
res
=
col_non_nulls
*
sel
;
set_if_bigger
(
res
,
col_stats
->
get_avg_frequency
());
}
else
res
=
col_non_nulls
;
...
...
@@ -4525,23 +4552,16 @@ double Histogram_binary::range_selectivity(Field *field,
else
max_mp_pos
=
1.0
;
if
(
is_usable
(
field
->
table
->
in_use
))
{
double
bucket_sel
=
1.0
/
(
get_width
()
+
1
);
uint
min
=
find_bucket
(
min_mp_pos
,
TRUE
);
uint
max
=
find_bucket
(
max_mp_pos
,
FALSE
);
sel
=
bucket_sel
*
(
max
-
min
+
1
);
double
bucket_sel
=
1.0
/
(
get_width
()
+
1
);
uint
min
=
find_bucket
(
min_mp_pos
,
TRUE
);
uint
max
=
find_bucket
(
max_mp_pos
,
FALSE
);
sel
=
bucket_sel
*
(
max
-
min
+
1
);
/*fprintf(stderr, "bucket_sel =%g\n", bucket_sel);
fprintf(stderr, "min pos_in_interval =%g\n", min_mp_pos);
fprintf(stderr, "max pos_in_interval =%g\n", max_mp_pos);
fprintf(stderr, "min =%d\n", min);
fprintf(stderr, "max =%d\n", max);*/
}
else
{
sel
=
(
max_mp_pos
-
min_mp_pos
);
}
/*fprintf(stderr, "bucket_sel =%g\n", bucket_sel);
fprintf(stderr, "min pos_in_interval =%g\n", min_mp_pos);
fprintf(stderr, "max pos_in_interval =%g\n", max_mp_pos);
fprintf(stderr, "min =%d\n", min);
fprintf(stderr, "max =%d\n", max);*/
/*fprintf(stderr, "final sel =%g\n", sel);
fprintf(stderr, "Histogram_binary::range_selectivity ends\n");*/
return
sel
;
...
...
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