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

grouping function arg check logic errors in pre-only-full-group-check phase #45661

Closed
AilinKid opened this issue Jul 28, 2023 · 0 comments · Fixed by #45663
Closed

grouping function arg check logic errors in pre-only-full-group-check phase #45661

AilinKid opened this issue Jul 28, 2023 · 0 comments · Fixed by #45663
Assignees
Labels
severity/minor sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@AilinKid
Copy link
Contributor

AilinKid commented Jul 28, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `t` (
  `year` int(11) DEFAULT NULL,
  `country` varchar(20) DEFAULT NULL,
  `product` varchar(32) DEFAULT NULL,
  `profit` int(11) DEFAULT NULL
) 
alter table t set tiflash replica 1;
SELECT year+2 as y, sum(profit) as profit, grouping(year+2) FROM sales GROUP BY year+2, year+profit WITH ROLLUP having y > 2002 and profit >0 order by year+2, profit;

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

+------+--------+------------------+
| y    | profit | grouping(year+2) |
+------+--------+------------------+
| 2003 |    800 |                0 |
| 2003 |   1010 |                0 |
| 2003 |   1200 |                0 |
| 2003 |   3010 |                0 |
+------+--------+------------------+
4 rows in set (0.02 sec)

3. What did you see instead (Required)

MySQL [test]> SELECT year+2 as y, SUM(profit) AS profit, grouping(year+2) FROM sales GROUP BY year+2, year+profit WITH ROLLUP having y > 2002 order by year+2, profit;
ERROR 3602 (HY000): Argument 3 of GROUPING function is not in GROUP BY

In plan building phase, grouping(year+2) is seen as not following the only-full-group-logic in pre-only-full-group-check logic.
Actually, we do have our own grouping function validation logic in expression rewriting function, just skip it there, and left it to expressionRewriter is enough.

4. What is your TiDB version? (Required)

master

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

Successfully merging a pull request may close this issue.

1 participant