[MDEV-5926] EITS: Histogram estimates for column=least_possible_value are wrong Created: 2014-03-21  Updated: 2014-03-28  Resolved: 2014-03-28

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.0.9
Fix Version/s: 10.0.10

Type: Bug Priority: Major
Reporter: Sergei Petrunia Assignee: Sergei Petrunia
Resolution: Fixed Votes: 0
Labels: eits

Issue Links:
Relates
relates to MDEV-5950 EITS: bad estimate for very skewed di... Closed

 Description   

This is based on observations over MDEV-4362 and MDEV-4364.

Populate the table with 100 rows with a=0, 100 rows with a=1, etc. (the data distribution is perfectly uniform)

 
create table ten(a int);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1(a int);
insert into t1 select A.a from ten A, ten B, ten C;
set histogram_size=20;
set histogram_type='single_prec_hb';
analyze table t1 persistent for all;
set use_stat_tables='preferably';
set optimizer_use_condition_selectivity=4;

mysql> explain extended select * from t1 where a=2;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 1000 |     8.67 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+

Not a precise estimate, but it is probably ok.

mysql> explain extended select * from t1 where a=1;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 1000 |     8.67 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+

OK.

mysql> explain extended select * from t1 where a=0;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 1000 |   100.00 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+

Boom. The number of rows with a=0 is 10% of the table. Not ok.

mysql> explain extended select * from t1 where a=-1;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL | 1000 |   100.00 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+

-1 is not present at all. Not ok.



 Comments   
Comment by Sergei Petrunia [ 2014-03-25 ]

Committed a patch.

Comment by Sergei Petrunia [ 2014-03-27 ]

Second variant of the patch pushed with review feedback addressed.

Generated at Thu Feb 08 07:08:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.