Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AilinKid opened this issue Jan 26, 2025 · 2 comments · May be fixed by #59212
Open

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

AilinKid opened this issue Jan 26, 2025 · 2 comments · May be fixed by #59212
Labels
severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@AilinKid
Copy link
Contributor

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

@AilinKid AilinKid added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner severity/moderate labels Jan 26, 2025
@AilinKid
Copy link
Contributor Author

Image in the place marked with the red line, we found that since the union all have multiple children, while they share the same project column schema which is desirable, projecting column#8 as a constant is only right in the behavior of what the 2nd child does, not the 1st child. So for union-all case, maybe the functional dependency merge is not always right, we should discard fds of both child.

@AilinKid
Copy link
Contributor Author

AilinKid commented Jan 26, 2025

Image

we didn't implement a specific fds deriving logic for union all operator which is default as merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
1 participant