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: add some comment for checkOnlyFullGroupBy #25769

Merged
merged 3 commits into from
Jul 16, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,28 @@ func checkColFuncDepend(
Name: colInfo.Name,
}
pIdx, err := expression.FindFieldName(p.OutputNames(), pkName)
// It is possible that `pIdx < 0` and here is a case.
// ```
// CREATE TABLE `BB` (
// `pk` int(11) NOT NULL AUTO_INCREMENT,
// `col_int_not_null` int NOT NULL,
// PRIMARY KEY (`pk`)
// );
//
// SELECT OUTR . col2 AS X
// FROM
// BB AS OUTR2
// INNER JOIN
// (SELECT col_int_not_null AS col1,
// pk AS col2
// FROM BB) AS OUTR ON OUTR2.col_int_not_null = OUTR.col1
// GROUP BY OUTR2.col_int_not_null;
// ```
// When we enter `checkColFuncDepend`, `pkName.Table` is `OUTR` which is an alias, while `pkName.Name` is `pk`
// which is a original name. Hence `expression.FindFieldName` will fail and `pIdx` will be less than 0.
// Currently, when we meet `pIdx < 0`, we directly regard `primaryFuncDepend` as false and jump out. This way is
// easy to implement but makes only-full-group-by checker not smart enough. Later we will refactor only-full-group-by
// checker and resolve the inconsistency between the alias table name and the original column name.
if err != nil || pIdx < 0 {
primaryFuncDepend = false
break
Expand Down