[MDEV-15433] Optimizer does not use group by optimization with distinct Created: 2018-02-27 Updated: 2020-08-25 Resolved: 2018-08-05 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer, Storage Engine - InnoDB |
| Affects Version/s: | 10.1.31 |
| Fix Version/s: | 10.1.35 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Varun Gupta (Inactive) |
| Resolution: | Fixed | Votes: | 3 |
| Labels: | optimizer | ||
| Issue Links: |
|
||||||||
| Description |
|
This is similar to the following upstream bug that was fixed in MySQL 5.6, but this problem seems to effect all InnoDB tables in MariaDB 10.1, not just partitioned ones: https://bugs.mysql.com/bug.php?id=60023 For example, run the following test:
Here's the output seen on MariaDB 10.1.31:
Compare this to the output seen on 5.6.38:
|
| Comments |
| Comment by Richard Stracke [ 2018-03-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
On MariaDB 10.2 it works with
On 10.1. a workarround is to combine group by and distinct.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alice Sherepa [ 2018-03-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Not reproducible on MariaDB 5.5, 10.2, 10.3 - Using index for group-by in all cases;
Innodb/10.1
Sporadic, not using group-by optimization
or sometimes like this:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-08-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Patch this patch reverts the commit for
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-08-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
After discussion with igor we have concluded that the fix for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-08-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-08-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In
The key_len= 0 which tells us that the length of the key on the GROUP BY column is 0. For such a case I think we should add a case of not allowing the GROUP BY optimization. This case comes under the category (4) as mentioned above. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-08-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
the code in get_best_group_min_max
So here we check if we have GROUP BY or not and if we don't have GROUP BY and distinct then we convert DISTINCT to GROUP BY. So for our case we don't enter the IF condition here and so we don't have any groups over which we will create the group by prefix and that is why we end up with key_len=0. So we should not allow such cases. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-08-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Second patch |