[MDEV-12922] Expressions should be properly supported in GROUP BY in ONLY_FULL_GROUP_BY sql_mode Created: 2017-05-26  Updated: 2018-11-26

Status: Open
Project: MariaDB Server
Component/s: Optimizer, Parser
Fix Version/s: None

Type: Task Priority: Major
Reporter: Valerii Kravchuk Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: upstream


 Description   

As MySQL (and MariaDB) support expressions in GROUP BY clause (see https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html), it would be useful to support them in ONLY_FULL_GROUP_BY mode as well (taking the mode details into account).

Now (in 10.2) it seems even obviously logically correct queries are rejected, while in even more trivial cases expressions in GROUP BY work. Consider the following example:

MariaDB [test]> create table tt(id int primary key, a int, b int);
Query OK, 0 rows affected (0.28 sec)
 
MariaDB [test]> select @@sql_mode;
+-------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                |
+-------------------------------------------------------------------------------------------+
| STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [test]> select a,coalesce(b,1)*a from tt group by a,coalesce(b,1);
Empty set (0.00 sec)
 
MariaDB [test]> set sql_mode=only_full_group_by;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> select a,coalesce(b,1)*a from tt group by a,coalesce(b,1);
ERROR 1055 (42000): 'test.tt.b' isn't in GROUP BY
MariaDB [test]> select a, floor(b) from tt group by a, floor(b);
Empty set (0.01 sec)
 
MariaDB [test]> select a, floor(b)*2 from tt group by a, floor(b);
ERROR 1055 (42000): 'test.tt.b' isn't in GROUP BY
 
MariaDB [test]> select a, mod(b,2) from tt group by a, mod(b,2);
Empty set (0.00 sec)
 
MariaDB [test]> select a, 2*mod(b,2) from tt group by a, mod(b,2);
ERROR 1055 (42000): 'test.tt.b' isn't in GROUP BY
...

So, either we should reject all kinds of expressions in GROUP_BY when we use ONLY_FULL_GROUP_BY mode, or we should take functional dependencies on these expressions into account properly.

This is probably related to https://jira.mariadb.org/browse/MDEV-11588

See also upstream https://bugs.mysql.com/bug.php?id=86475


Generated at Thu Feb 08 08:01:32 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.