[MDEV-6634] Wrong estimates for ref(const) and key IS NULL predicate Created: 2014-08-23 Updated: 2014-09-03 Resolved: 2014-08-24 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.5.39, 10.0.13 |
| Fix Version/s: | 10.1.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | optimizer | ||
| Issue Links: |
|
||||||||
| Description |
|
Create the dataset:
Let's explore the dataset
Here, it underestimates the amount of NULLs (by about two times). This is not a problem, yet.
This is close to reality.
Now, here the scan on "removed IS NULL" produces 10 rows, even if we saw above that the optimizer knows it will produce about 1K rows. This might be not a problem for this particular query, but it may cause the optimizer not to pick a good query plan. |
| Comments |
| Comment by Sergei Petrunia [ 2014-08-23 ] | |||||||||||||||||
|
On MariaDB 10.0:
That is, the problem I can observe on MariaDB 5.5 cannot be seen on MariaDB 10.0. | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-08-23 ] | |||||||||||||||||
|
More details about what happens on 5.5: Range optimizer is actually unable to make use of condition "t1p.removed is null". This is because of this (incorrect) old code in opt_range.cc, get_mm_leaf():
Then, best_access_path() find that which causes this formula to be used:
where rec has the value from the start of the function:
and we get records = s->records / (s->records / MATCHING_ROWS_IN_OTHER_TABLE)= MATCHING_ROWS_IN_OTHER_TABLE= 10. which is a really bad estimate (and note that it is always equal to 10. This is even worse than using an imprecise estimate from rec_per_key). | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-08-23 ] | |||||||||||||||||
|
The problem is not seen on MariaDB 10.0, because 10.0 has extended_keys enabled by default. When extended keys is ON, execution in best_access_path() takes a different branch. If I disable extended_keys in 10.0.13, I get the same bad estimate:
Debugging 10.0, I see that the problematic code in opt_range.cc, get_mm_leaf() is still there. | |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-08-23 ] | |||||||||||||||||
|
In 5.5, it's other way around. if I turn extended_keys to ON, the problem goes away:
| |||||||||||||||||
| Comment by Sergei Petrunia [ 2014-08-24 ] | |||||||||||||||||
|
Pushed a patch to 10.1 tree. I think, we could discuss back-porting it to some earlier releases. |