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

planner: completely reject 'ORDER BY contains aggregate function and applies to the result of a non-aggregated query' #21848

Open
dyzsr opened this issue Dec 17, 2020 · 2 comments
Labels
feature/developing the related feature is in development sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@dyzsr
Copy link
Contributor

dyzsr commented Dec 17, 2020

Development Task

In TiDB,

create table t (a int, b int);

# when only_full_group_by is enabled
select a from t order by count(b);
(3029, 'Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query')
select * from t order by max(b);
(3029, 'Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query')

# when only_full_group_by is disabled
select a from t order by count(b);
+---+
| a |
+---+
0 rows in set

select * from t order by max(b);
+---+---+
| a | b |
+---+---+
0 rows in set

Such queries should be rejected regardless only_full_group_by is enabled or not, as handled in https://bugs.mysql.com/bug.php?id=72512.

Currently, TiDB can only reject such cases when only_full_group_by is enabled through PlanBuilder.checkOnlyFullGroupByWithOutGroupClause.

We may move the checking logic of ORDER BY out of this method.

@dyzsr dyzsr added the type/enhancement The issue or PR belongs to an enhancement. label Dec 17, 2020
@dyzsr dyzsr changed the title completely reject ORDER BY contains aggregate function and applies to the result of a non-aggregated query planner: completely reject 'ORDER BY contains aggregate function and applies to the result of a non-aggregated query' Dec 17, 2020
@dyzsr
Copy link
Contributor Author

dyzsr commented Dec 17, 2020

/label sig/planner

@ti-srebot ti-srebot added the sig/planner SIG: Planner label Dec 17, 2020
@Reminiscent
Copy link
Contributor

@xuyifangreeneyes PTAL

@winoros winoros added the feature/developing the related feature is in development label Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/developing the related feature is in development sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

4 participants