Skip to content

new-only-full-group-by mode can not tell special union all case #59211

@AilinKid

Description

@AilinKid

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> create table t(a int,b int,c int);
Query OK, 0 rows affected (0.11 sec)

mysql> insert into t values(1,2,3);
Query OK, 1 row affected (0.01 sec)

mysql> select a,max(b) as max_b from (select * from t union all select * from t) x ;
ERROR 1140 (42000): In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'x.a'; this is incompatible with sql_mode=only_full_group_by
mysql> select a,max(b) as max_b from (select * from t union all select 1,2,3 ) x ;
ERROR 1140 (42000): In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'x.a'; this is incompatible with sql_mode=only_full_group_by
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.3.0     |
+-----------+
1 row in set (0.01 sec)

tidb with new-only-full-group= on
tidb> select a,max(b) as max_b from (select * from t union all select * from t) x ;
ERROR 8123 (HY000): In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'x.a'; this is incompatible with sql_mode=only_full_group_by
tidb> select a,max(b) as max_b from (select * from t union all select 1,2,3 ) x ;
+------+-------+
| a    | max_b |
+------+-------+
|    1 |     2 |
+------+-------+
1 row in set (0.01 sec)

2. What did you expect to see? (Required)

both two queries should both error

3. What did you see instead (Required)

the 2nd can run success?

4. What is your TiDB version? (Required)

master

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.report/customerCustomers have encountered this bug.severity/moderatesig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions