Skip to content

Commit

Permalink
planner: ONLY_FULL_GROUP_BY sql_mode was not working with VIEWs (#57473)
Browse files Browse the repository at this point in the history
close #53175
  • Loading branch information
mjonss authored Nov 19, 2024
1 parent 60bbccb commit d0150c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/planner/core/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go_test(
data = glob(["testdata/**"]),
flaky = True,
race = "on",
shard_count = 3,
shard_count = 4,
deps = [
"//pkg/parser",
"//pkg/planner",
Expand Down
15 changes: 15 additions & 0 deletions pkg/planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,18 @@ func TestIssue54535(t *testing.T) {
tk.MustQuery("select /*+ inl_join(tmp) */ * from t1 inner join (select col_1, group_concat(col_2) from t2 group by col_1) tmp on t1.col_1 = tmp.col_1;").Check(testkit.Rows())
tk.MustQuery("select /*+ inl_join(tmp) */ * from t1 inner join (select col_1, group_concat(distinct col_2 order by col_2) from t2 group by col_1) tmp on t1.col_1 = tmp.col_1;").Check(testkit.Rows())
}

func TestIssue53175(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table t(a int)`)
tk.MustExec(`set @@sql_mode = default`)
tk.MustQuery(`select @@sql_mode REGEXP 'ONLY_FULL_GROUP_BY'`).Check(testkit.Rows("1"))
tk.MustContainErrMsg(`select * from t group by null`, "[planner:1055]Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t.a' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by")
tk.MustExec(`create view v as select * from t group by null`)
tk.MustContainErrMsg(`select * from v`, "[planner:1055]Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t.a' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by")
tk.MustExec(`set @@sql_mode = ''`)
tk.MustQuery(`select * from t group by null`)
tk.MustQuery(`select * from v`)
}
12 changes: 10 additions & 2 deletions pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2940,11 +2940,19 @@ func (b *PlanBuilder) tblInfoFromCol(from ast.ResultSetNode, name *types.FieldNa
for _, field := range tableList {
if field.Name.L == name.TblName.L {
tnW := b.resolveCtx.GetTableName(field)
// when the Select is inside a view, it's not pre-processed, tnW is nil.
if tnW != nil {
return tnW.TableInfo
}
return nil
// when the Select is inside a view, it's not pre-processed, tnW is nil.
if b.isCreateView {
// Ignore during create
return nil
}
tblInfo, err := b.is.TableInfoByName(name.DBName, name.TblName)
if err != nil {
return nil
}
return tblInfo
}
}
return nil
Expand Down

0 comments on commit d0150c0

Please sign in to comment.