[MDEV-25112] MIN/MAX aggregation over an indexed column may return wrong result Created: 2021-03-10 Updated: 2021-03-19 Resolved: 2021-03-19 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.5.9, 10.2, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.2.38, 10.3.29, 10.4.19, 10.5.10 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergey Lebedev | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Description |
|
For a DB Table having a id field which is the table’s auto-incremented primary key gives the result: At the same time SQL-query gives the correct result: here is a minimal example to create DB table and reproduce the issue CREATE TABLE _between_bug2 (id int(13) auto_increment primary key); SELECT max(id) FROM _between_bug2 WHERE id < 303 and (id BETWEEN 267 AND 287) and here is an SQL fiddle to reproduce it |
| Comments |
| Comment by Alice Sherepa [ 2021-03-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks! Reproducible on 5.5-10.5 as described
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2021-03-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem can be reproduced with any index. Here' s a test case demonstrating this.
We see that MIN/MAX optimization is applied here:
Interesting that the following query
works fine and with the same optimization applied
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2021-03-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
MySQL-8.0.21 has the same bug:
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Valerii Kravchuk [ 2021-03-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Same with 8.0.23:
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergey Lebedev [ 2021-03-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes, the bug also appears in MySQL and we've reported it. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2021-03-12 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
A similar problem can be observed here:
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Dmitry Shulga [ 2021-03-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Approved | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2021-03-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
A fix for this bug was pushed into 10.2 |