[MDEV-5985] EITS: selectivity estimates look illogical for join and non-key equalities Created: 2014-03-31 Updated: 2014-06-10 Resolved: 2014-06-10 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.9 |
| Fix Version/s: | 10.0.12 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | eits | ||
| Issue Links: |
|
||||||||
| Description |
|
Create a dataset:
Let's see what histograms give us
The numbers looks ok. Now, let's try a join:
Looks ok. Now, let's add a condition.
And filtered% becomes 100%. It used to be 9.90%, we have added another condition into WHERE and now the optimizer expects the condition to be less selective! This looks wrong. |
| Comments |
| Comment by Sergei Petrunia [ 2014-03-31 ] | |||||||||||||||||
|
Look at the code near this comment:
Maybe, this is the cause of this bug? | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-04-21 ] | |||||||||||||||||
|
Patch submitted for review | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-04-25 ] | |||||||||||||||||
|
Summary of discussion with igor earlier this week: The committed patch doesn't handle all cases. When the multi-equality is a part
The query plan will be:
Now, add a condition:
one_k2 has values 1...1000, selectivity is 10/1000 = 1%. However, we fail to take into account that ref access only gives us rows that | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-04-25 ] | |||||||||||||||||
|
About the initial example (the one not using ref access): Debugging table_cond_selectivity(B) Then, we go into the part of code that starts with We find that B.a is a member in multiple_equality(B.a, A.a). if (field->cond_selectivity > 0) and get | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-04-26 ] | |||||||||||||||||
|
So. 1. When using full table scan, we must not try to discount field->cond_selectivity 2. When using ref access, there are two possibilities: 2.1 A member of multiple-equality is a part of ref_key. In this case, the 2.2 No member of multiple equality is a part of ref_key. | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-04-28 ] | |||||||||||||||||
|
Debugging the example in the comment (with one_k3 table), I see another problem: The code tries to discount for selectivity of "one_k3.a < 3". It reaches the lines
However, field->cond_selectivity==1, because selectivity was obtained using range optimization. | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-10 ] | |||||||||||||||||
|
Current EITS optimization code has multiple problems. I will not try to fix them all at once. Pushed the fix for the problem demonstrated by the example in this issue. The issue demonstrated in the comment dated 2014-04-25 20:29 is branched off into |