[MDEV-27382] OFFSET is ignored when it is combined with the DISTINCT, IN() and JOIN operation Created: 2021-12-29 Updated: 2023-05-15 Resolved: 2022-01-19 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.5.2, 10.5.8, 10.5.13, 10.6.5, 10.5, 10.6, 10.7 |
| Fix Version/s: | 10.5.14, 10.6.6, 10.7.2 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Thilanka | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
RHEL 8 |
||
| Issue Links: |
|
||||||||
| Description |
|
We have recently moved from MariaDB 10.2 to 10.5.13 and we observed that the OFFSET is ignored when it is combined with the DISTINCT, IN() and JOIN operation. The following steps explains how to reproduce the issue. Create two tables as parent and child with a foreign key and have 1 record in each.
Run a select distinct record query left joining parent and child tables with the OFFSET as 0 and it will return the id of the only record we have in the parent table.
Run the same query with the OFFSET as 1 and it will again return the id of the only record we have in the parent table. And when you continue to change the OFFSET to any higher value, it continues to return the id or the first record which is unintended.
I have done some changes to the query to check some other combinations and when we change it as follow the issue seems to diapear which is bit confusing. Chanding the DISTINCT p.id to DISTINCT *
Adding another id for the WHERE IN() clause
This has become a blocker for our product so we tested it in MariaDB 10.4.22 version and identified that the issue is not there in 10.4.22 version |
| Comments |
| Comment by Alice Sherepa [ 2021-12-29 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you! Reproducible as described on 10.5-10.7:
| ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Thilanka [ 2022-01-09 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Can I get a rough idea, when will this get prioritized to fix? | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2022-01-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
At the moment, it's planned to be fixed in the next release. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Thilanka [ 2022-01-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for the update and really appreciate it. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-01-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Looking at 10.5...
But the query with LIMIT 0 OFFSET n doesn't :
| ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-01-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
The problem is caused by this piece in JOIN_TAB::remove_duplicates :
| ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-01-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Before 10.5, the code looked like so:
That is, it didn't touch the offset value. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-01-13 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
bb-10.5-mdev27382 | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-01-13 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Sanja, please review. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-01-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Second variant: bb-10.5-mdev27382-v2 | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2022-01-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
2fd6cfe120b9f09a31e06db27acae993b4c3e55c ok to push | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Thilanka [ 2023-05-15 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
We tested this in the following versions but still this issue exists. Any idea why is it? 11.0.1-rc | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alice Sherepa [ 2023-05-15 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
I am terribly sorry, only the case with LIMIT 0 got fixed. I reopened the bug here - | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Thilanka [ 2023-05-15 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks Alice |