[MDEV-6325] EITS: wrong selectivity for REF(t1.key=t0.col) AND COND(t0.col) Created: 2014-06-10  Updated: 2014-11-04  Resolved: 2014-11-04

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.0.11
Fix Version/s: 10.0.15

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

Issue Links:
Relates
relates to MDEV-5985 EITS: selectivity estimates look illo... Closed

 Description   

This issue is a branch-off from MDEV-5985.

The dataset is:

## Dataset from MDEV-5985:
create table ten(a int);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table one_k(a int);
insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C;
create table one_k2 as select * from one_k;
set histogram_size=100;
set use_stat_tables='preferably';
set optimizer_use_condition_selectivity=4;
analyze table one_k persistent for all;
analyze table one_k2 persistent for all;
 
# Extra data for this MDEV:
create table one_k3 (a int, b int, key(a));
insert into one_k3 select A.a + 10*B.a, 12345 from ten A, ten B, ten C;
analyze table one_k3 persistent for all;

The query is:

explain extended select * from one_k2 straight_join one_k3 where one_k2.a=one_k3.a and one_k2.a<10;
+------+-------------+--------+------+---------------+------+---------+--------------+------+----------+-------------+
| id   | select_type | table  | type | possible_keys | key  | key_len | ref          | rows | filtered | Extra       |
+------+-------------+--------+------+---------------+------+---------+--------------+------+----------+-------------+
|    1 | SIMPLE      | one_k2 | ALL  | NULL          | NULL | NULL    | NULL         | 1000 |     0.99 | Using where |
|    1 | SIMPLE      | one_k3 | ref  | a             | a    | 5       | j22.one_k2.a |   10 |     9.90 |             |
+------+-------------+--------+------+---------------+------+---------+--------------+------+----------+-------------+

Here, one_k2.filtered=0.99% is correct. However, we should have
one_k3.filtered=100%, because

  • ref access makes sure that one_k2.a=one_k3.a,
  • "one_k2.a<10" is checked for table one_k2
  • hence, checking that "one_k3.a<10" will not produce any selectivity (in fact, the optimizer will not even generate this condition)


 Comments   
Comment by Sergei Petrunia [ 2014-11-04 ]

Reviewed igor 's patch.

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