[MDEV-23291] SUM column from a derived table returns invalid values Created: 2020-07-25 Updated: 2021-06-10 Resolved: 2021-02-16 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Subquery |
| Affects Version/s: | 10.0, 10.1, 10.1.45, 10.2.32, 10.3.23, 10.4.13, 10.5.4, 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: | Marcos Alejandro Gallardo | Assignee: | Varun Gupta (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Platforms:
|
||
| Issue Links: |
|
||||||||||||
| Description |
|
Use this schema as example:
If we run this query:
It returns:
Now If move this into a derived table to get the sumarized `avgSold` grouped by `code` like this
It returns:
This is NOT the expected result. If I add a numeric column (YES it MUST be a numeric column) like this:
It returns:
NOW this is the expected result Here you can find a working demo |
| Comments |
| Comment by Alice Sherepa [ 2020-07-27 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks a lot!
5.5 returns correct results.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-08-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
A simpler test case that fails on debug builds
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-08-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
So for the query:
we we walk over the arguments of the SUM function.
The item z is a reference so we walk to the item it is referring to
item z is referring to SELECT#4 Then we walk the upper references in the SELECT #4, that would be item y
item y is again a reference to SELECT#3
So here we end up with (select x) as y termed as SELECT#3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2020-08-06 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
If we take such simplified example:
we found that it is not allowed to reference select list from other select list element. So even in user example we shoud have "ordered" as unknown. So one bug is in not returning an error in case of select list name reference. Also try use table reference in user examle and if the bug will be present it shoud also be fixed (second part) but I think it will not, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2020-12-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
OK, it looks like we supported the name resolution in the subquery so have to keep it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2021-02-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
OK to push |