[MDEV-9028] Incorrect query result when combining DISTINCT, LEFT JOIN and subquery with constant column Created: 2015-10-28 Updated: 2017-02-20 Resolved: 2017-02-20 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Subquery |
| Affects Version/s: | 5.5.43, 5.5, 10.0, 10.1 |
| Fix Version/s: | 5.5.55 |
| Type: | Bug | Priority: | Major |
| Reporter: | Nathan Lewis | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | regression, wrong_result | ||
| Environment: |
Ubuntu 12 |
||
| Sprint: | 5.5.55 |
| Description |
|
There appears to be a problem with the results returned from a query when DISTINCT, LEFT JOIN and a subquery which contains a constant value are combined. I've boiled down the problem into a simple example of how it fails:
If you create a table called "realtable" with columns int "id" and string "data", insert two records (1, "yes") and (2, "yes") and run the query then you'll get:
which is incorrect. The value "yes" should be returned in the recordexists column. Obviously the "virtual" records are being joined correctly to the "real" records, because the virtualid returns the correct value, but the constant "yes" is missing. If you remove DISTINCT, change LEFT JOIN to just JOIN, or change "yes" to realtable.data then you get the correct results:
I also confirmed that this is NOT caused by using the same table in both the main and sub queries. I've got a query structured like this which is working in Postgress and MySQL, and when delivered to a client who tried it in MariaDB it started failing. This could probably be considered a data loss bug. |
| Comments |
| Comment by Elena Stepanova [ 2015-10-29 ] | |||||||||||||||||||||
|
nathanl, thanks for the report.
The problem was introduced by the following revision in 5.5.43:
| |||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-02-17 ] | |||||||||||||||||||||
|
OK to push! Thank you a lot for the fix! | |||||||||||||||||||||
| Comment by Igor Babaev [ 2017-02-20 ] | |||||||||||||||||||||
|
The fix for this bug was pushed into the 5.5 tree. |