[MDEV-17785] Window functions not working in ONLY_FULL_GROUP_BY mode II Created: 2018-11-20 Updated: 2022-04-04 Resolved: 2022-02-07 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer - Window functions |
| Affects Version/s: | 10.3.11, 10.2, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.2.43, 10.3.34, 10.4.24, 10.5.15, 10.6.7, 10.7.3 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Jonas Staudenmeir | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 14 |
| Labels: | None | ||
| Environment: |
Ubuntu 18.04.1 |
||
| Issue Links: |
|
||||||||
| Description |
|
This is a follow-up to The patch fixed the AVG() function from the example query, but other window functions still don't work in ONLY_FULL_GROUP_BY mode. Using a different example from the documentation:
The SELECT query fails with an error:
|
| Comments |
| Comment by Varun Gupta (Inactive) [ 2020-07-09 ] | ||||||||||||||||||||||||
|
This is another bug where we treat the window function as an Item_sum. Window function is treated as an aggregate function and this leads to the problem here. | ||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-07-09 ] | ||||||||||||||||||||||||
|
Here is the code where we see the error being thrown
In the debugger I see
This means that the query has an aggregate function and atleast one field with non-aggregate function. The function select_lex->agg_func_used should return FALSE in this case | ||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-07-09 ] | ||||||||||||||||||||||||
|
With SUM function used as a window function, there is no problem here.
With RANK function we hit the error. | ||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-07-09 ] | ||||||||||||||||||||||||
|
Debugging in the function Item_sum::check_sum_func For the query:
and we return from this function. For the second query
Debugging till the end of the function
We set that this is marked as an aggregate function. This is wrong, we need to make sure that this is an Item_sum instance that is used as a window function. | ||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-07-09 ] | ||||||||||||||||||||||||
|
Patch | ||||||||||||||||||||||||
| Comment by Nuno [ 2020-12-27 ] | ||||||||||||||||||||||||
|
I've just come across this now. I was wondering why was MariaDB complaining about GROUP BY clauses/columns, when I was trying to use ROW_NUMBER(), without any GROUP BY stuff. My @@sql_mode has "ONLY_FULL_GROUP_BY", as should be, and I can confirm that ROW_NUMBER() works if I disable it. SET sql_mode = (SELECT REPLACE(REPLACE(@@sql_mode, ",ONLY_FULL_GROUP_BY", ""), "ONLY_FULL_GROUP_BY,", "")); Of course, this is not ideal... | ||||||||||||||||||||||||
| Comment by Nuno [ 2021-02-23 ] | ||||||||||||||||||||||||
|
igor Any idea when the fix can be reviewed and merged? | ||||||||||||||||||||||||
| Comment by Nuno [ 2021-10-28 ] | ||||||||||||||||||||||||
| Comment by Dan Livingston [ 2021-11-17 ] | ||||||||||||||||||||||||
|
This is something that is critical for us as well as it is causing problems - any updates? | ||||||||||||||||||||||||
| Comment by Paulus Limma [ 2022-01-20 ] | ||||||||||||||||||||||||
|
Is this going to be fixed anytime soon? IMO this is a really critical bug which is blocking me to use basic features of the SQL. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-02-07 ] | ||||||||||||||||||||||||
|
The second patch is ok. I've edited the commit comment to have more information. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-02-07 ] | ||||||||||||||||||||||||
|
bb-10.2-mdev17785 |