mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-31067: selectivity_from_histogram >1.0 for a DOUBLE_PREC_HB histogram
Variant #2. When Histogram::point_selectivity() sees that the point value of interest falls into one bucket, it tries to guess whether the bucket has many different (unpopular) values or a few popular values. (The number of rows is fixed, as it's a Height-balanced histogram). The basis for this guess is the "width" of the value range the bucket covers. Buckets covering wider value ranges are assumed to contain values with proportionally lower frequencies. This is just a [brave] guesswork. For a very narrow bucket, it may produce an estimate that's larger than total #rows in the bucket or even in the whole table. Remove the guesswork and replace it with basic logic: return either the per-table average selectivity of col=const, or selectivity of one bucket, whichever is lower.
This commit is contained in:
@ -36,12 +36,12 @@ test.t2 analyze status OK
|
||||
# The following two must have the same in 'Extra' column:
|
||||
explain extended select * from t2 where col1 IN (20, 180);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1100 1.35 Using where
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1100 1.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`col1` AS `col1` from `test`.`t2` where `test`.`t2`.`col1` in (20,180)
|
||||
explain extended select * from t2 where col1 IN (180, 20);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1100 1.35 Using where
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 1100 1.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`col1` AS `col1` from `test`.`t2` where `test`.`t2`.`col1` in (180,20)
|
||||
drop table t1, t2;
|
||||
@ -102,7 +102,7 @@ test.t1 analyze status Engine-independent statistics collected
|
||||
test.t1 analyze status OK
|
||||
explain extended select * from t1 where col1 in (1,2,3);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 10000 3.37 Using where
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 10000 2.97 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`col1` AS `col1` from `test`.`t1` where `test`.`t1`.`col1` in (1,2,3)
|
||||
# Must not cause fp division by zero, or produce nonsense numbers:
|
||||
|
Reference in New Issue
Block a user