[MDEV-10017] Get unexpected `Empty Set` for correlated subquery with aggregate functions Created: 2016-05-03 Updated: 2016-08-31 Resolved: 2016-08-31 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2 |
| Fix Version/s: | 10.1.19, 10.2.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Dylan Su | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | upstream | ||
| Sprint: | 10.1.15, 10.1.17-1 |
| Description |
|
Description:
Problem: How to repeat:
Suggested fix: |
| Comments |
| Comment by Elena Stepanova [ 2016-05-09 ] | ||||
|
Thanks for the report and the test case. Setting the sql_mode to ONLY_FULL_GROUP_BY makes the query fail with the error:
or, the MySQL version of the error is
The result is the same with MariaDB 5.1 - 10.2 and MySQL 5.5-5.6. | ||||
| Comment by Oleksandr Byelkin [ 2016-06-22 ] | ||||
|
Interesting thing is that ORDER BY in the test suite should be actually eliminated (because it has no sens without LIMIT clause) but removing it by hand fix situation. | ||||
| Comment by Oleksandr Byelkin [ 2016-06-23 ] | ||||
|
the subquery returns correct value (2), but only once when it compared with 1, then it return nothing. | ||||
| Comment by Oleksandr Byelkin [ 2016-06-23 ] | ||||
|
Picture is like this: Main select decided that it is implicit grouping, so for usual field with no group it take any value (which is MySQL extension 1 in this case) then check once the chosen value and that is all. probably min function is resolved in the main select... | ||||
| Comment by Oleksandr Byelkin [ 2016-06-23 ] | ||||
|
yes, the aggregate function found to belong to SELECT #1 And it is very strange, because 'c' is not defined in SELECT #1 | ||||
| Comment by Oleksandr Byelkin [ 2016-06-23 ] | ||||
|
It is not fix but some user interface (to be continue) revision-id: c584f1655ef45dafd2b5d0eb55ca21421de9a266 (mariadb-10.1.14-25-gc584f16)
Make aggregate function dependency visible. — | ||||
| Comment by Oleksandr Byelkin [ 2016-06-28 ] | ||||
|
I thought that max_arg_level only limit the arguments of aggregate function, but it also points to the SELECT where to find, probably function by arguments should be limited in other way | ||||
| Comment by Oleksandr Byelkin [ 2016-06-28 ] | ||||
|
It looks like max_sum_func_level can't play this role, because we need some low level limit. We can pull aggregate in the place where its arguments are not defined. | ||||
| Comment by Oleksandr Byelkin [ 2016-06-28 ] | ||||
|
OK I found what is wrong: if it is field resolved in HAVING & co then max_arg_level mover to this level (it is OK) if it is usual field resolved in outer field then max_arg_level do not moved (WHY if above?)
because aggregate will be resolved in outer query instead of local. So for now we have 2 "magnets" for aggregate, outer in HAVING&Co and local, other outer just ignored and do not checked at all. | ||||
| Comment by Oleksandr Byelkin [ 2016-07-06 ] | ||||
|
5.7 is a bit different and there is no problems... | ||||
| Comment by Oleksandr Byelkin [ 2016-07-06 ] | ||||
|
I found other big chunk of code in 5.7 which takes care about used table mask, probably it fixes 5.7. | ||||
| Comment by Oleksandr Byelkin [ 2016-07-12 ] | ||||
|
it appeared thet 5.7 also have problem of trying to pull aggregate function in the place where arguments are not defined so I'll roll back to very first fix and decision | ||||
| Comment by Oleksandr Byelkin [ 2016-08-22 ] | ||||
|
revision-id: 4ea7865195b8af02d61c1efe0ce60428ce53766e (mariadb-10.1.16-16-g4ea7865)
take into account all arguments of aggregate function — | ||||
| Comment by Oleksandr Byelkin [ 2016-08-23 ] | ||||
|
revision-id: 39c1ac14a80fcaeaac0ca40cbad5aff337fab157 (mariadb-10.1.16-16-g39c1ac1)
take into account all arguments of aggregate function — |