[MDEV-30605] Wrong result while using index for group-by Created: 2023-02-07 Updated: 2023-04-25 Resolved: 2023-04-18 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0 |
| Fix Version/s: | 11.1.1, 10.11.3, 11.0.2, 10.5.20, 10.6.13, 10.8.8, 10.9.6, 10.10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | 11.0-sel | ||
| Issue Links: |
|
||||||||
| Description |
|
A row for (4,NULL) is missing. 10.4 doesn't use index for group-by, and the result there is correct. |
| Comments |
| Comment by Rex Johnston [ 2023-02-20 ] | ||||||||||||||||||||||||||||||||||||||
|
The issue is in how aggregate rows are read in and filtered.
It appears to skip past the rest of the group (a==NULL) without further examination. | ||||||||||||||||||||||||||||||||||||||
| Comment by Rex Johnston [ 2023-02-21 ] | ||||||||||||||||||||||||||||||||||||||
|
produces
It would appear that the select condition (pk <> 1) is being incorrectly passed into into make_join_select() and eliminating the whole group during the join. | ||||||||||||||||||||||||||||||||||||||
| Comment by Rex Johnston [ 2023-02-22 ] | ||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||
| Comment by Rex Johnston [ 2023-03-14 ] | ||||||||||||||||||||||||||||||||||||||
|
Hi Sergei, this seems to do the trick and is a minimal change. Thanks, Rex | ||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-03-27 ] | ||||||||||||||||||||||||||||||||||||||
|
Writing down take-aways from an earlier optimizer call: This bug is caused by this patch:
That patch makes the optimizer to not construct an interval for condition
then, QUICK_GROUP_MIN_MAX_SELECT code ignores this condition and returns a row with pk=1 which is filtered out when checking the WHERE condition. | ||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-03-27 ] | ||||||||||||||||||||||||||||||||||||||
|
The idea of QUICK_GROUP_MIN_MAX_SELECT is that it is able to use ranges to jump to the row that has the value of MIN() or MAX() that we're interested in. For the query in this MDEV:
it uses the INDEX(a, pk) to:
The second step requires that conditions on pk are converted into ranges that allow us to jump to the matching value.
...
This logic was fine but broke down when the fix for | ||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2023-03-28 ] | ||||||||||||||||||||||||||||||||||||||
|
https://github.com/MariaDB/server/commit/42aea1990d32cc31d9b2c0eabe7e58bcf15475ca . oleg.smirnov could you review this? | ||||||||||||||||||||||||||||||||||||||
| Comment by Oleg Smirnov [ 2023-04-15 ] | ||||||||||||||||||||||||||||||||||||||
|
After minor fix (group_min_max.result) it is ok to push. |