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

core: fix subQuery at projection in only_full_group #22416

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,17 @@ func (s *testIntegrationSuite) TestMultiUpdateOnPrimaryKey(c *C) {
tk.MustQuery("select * from t").Check(testkit.Rows("11 12"))
}

func (s *testIntegrationSuite) TestSubProjNotInGroupBy(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1 (a int, b int);")
tk.MustExec("set sql_mode='ONLY_FULL_GROUP_BY';")
tk.MustExec("insert into t1 values (4, 40), (1, 10), (2, 20), (2, 20), (3, 30);")
tk.MustGetErrMsg("select (select t1.a) aa, count(distinct b) from t1 group by b",
"[planner:1055]Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t1.a' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by")
}

func (s *testIntegrationSuite) TestOrderByHavingNotInSelect(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
6 changes: 6 additions & 0 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5502,6 +5502,12 @@ func getInnerFromParenthesesAndUnaryPlus(expr ast.ExprNode) ast.ExprNode {
if uexpr, ok := expr.(*ast.UnaryOperationExpr); ok && uexpr.Op == opcode.Plus {
return getInnerFromParenthesesAndUnaryPlus(uexpr.V)
}
if sqpr, ok := expr.(*ast.SubqueryExpr); ok && sqpr.Query != nil {
if selSt, ok := sqpr.Query.(*ast.SelectStmt); ok && selSt.From == nil &&
len(selSt.Fields.Fields) > 0 {
return getInnerFromParenthesesAndUnaryPlus(selSt.Fields.Fields[0].Expr)
}
}
zhaoxugang marked this conversation as resolved.
Show resolved Hide resolved
return expr
}

Expand Down