[MDEV-10146] Wrong result (or questionable result and behavior) with aggregate function in uncorrelated SELECT subquery Created: 2016-05-27 Updated: 2017-10-02 Resolved: 2017-07-05 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2 |
| Fix Version/s: | 10.1.26, 5.5.57, 10.0.32, 10.2.7 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Elena Stepanova | Assignee: | Oleksandr Byelkin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Sprint: | 10.2.7-1 | ||||||||
| Description |
|
Please consider the scenario below. I don't know whether my expectations are even correct, because MySQL, Oracle and PostgreSQL all behave differently in this case, and none does exactly what I expect.
|
| Comments |
| Comment by Oleksandr Byelkin [ 2017-06-22 ] | ||||||||||||||||||||
|
subquery ( SELECT MAX(f1) FROM t2 ) with no GROUP BY should return only one row always | ||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-06-22 ] | ||||||||||||||||||||
|
The problem do not depend on MAX specific, the same is with SUM for example. | ||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-06-22 ] | ||||||||||||||||||||
|
EXPLAIN EXTENDED explain why the result is correct: | ||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-06-22 ] | ||||||||||||||||||||
|
The problem is that even explicit GROUP BY ignored: (probably also checks JOIN::group_list but not JOIN::simple_grouping) | ||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-06-22 ] | ||||||||||||||||||||
|
Result of discussing with Igor: | ||||||||||||||||||||
| Comment by Igor Babaev [ 2017-06-22 ] | ||||||||||||||||||||
|
Some observations what postgresql returns for these queries:
So, here postgresql (and most probably the Standard) agrees with Sanja. Another observation:
The first query returns a wrong result set, while the second works fine.
So, probably this is another bug. | ||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-06-23 ] | ||||||||||||||||||||
|
error with not returning 2 records connected to not moving subselect in top subselect | ||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-06-26 ] | ||||||||||||||||||||
|
Bug with view resolved: outer field view resolving did not set max_arg_level.
| ||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-06-26 ] | ||||||||||||||||||||
|
revision-id: 7b5a04c14fb93fa6ebeaad4b40f028bf547bce14 (mariadb-10.2.6-64-g7b5a04c14fb)
When outer reference resolved in a VIEW it still should mark aggregate function resolving border. | ||||||||||||||||||||
| Comment by Igor Babaev [ 2017-07-04 ] | ||||||||||||||||||||
|
Sanja, Ok to push the patch into 5.5. | ||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-07-05 ] | ||||||||||||||||||||
|
2 them who will merge: there will be problem with subselect*.test. Solution is in commit above (for 10.2 not for 5.5). | ||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-07-06 ] | ||||||||||||||||||||
|
"The commit above" is http://lists.askmonty.org/pipermail/commits/2017-June/011271.html |