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

expression: fix a bug that DML using caseWhen may cause schema change #20095

Merged
merged 4 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion expression/constant_fold.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func caseWhenHandler(expr *ScalarFunction) (Expression, bool) {
foldedExpr.GetType().Decimal = expr.GetType().Decimal
return foldedExpr, isDeferredConst
}
return BuildCastFunction(expr.GetCtx(), foldedExpr, foldedExpr.GetType()), isDeferredConst
return foldedExpr, isDeferredConst
}
} else {
hasNonConstCondition = true
Expand Down
14 changes: 14 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3507,6 +3507,7 @@ func (s *testIntegrationSuite) TestAggregationBuiltin(c *C) {
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a decimal(7, 6))")
tk.MustExec("insert into t values(1.123456), (1.123456)")
result := tk.MustQuery("select avg(a) from t")
Expand All @@ -3533,6 +3534,19 @@ func (s *testIntegrationSuite) TestAggregationBuiltin(c *C) {
result.Check(testkit.Rows("18446744073709551615"))
}

func (s *testIntegrationSuite) Test19387(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("USE test;")

tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(a decimal(16, 2));")
tk.MustExec("select sum(case when 1 then a end) from t group by a;")
res := tk.MustQuery("show create table t")
c.Assert(len(res.Rows()), Equals, 1)
str := res.Rows()[0][1].(string)
c.Assert(strings.Contains(str, "decimal(16,2)"), IsTrue)
}

func (s *testIntegrationSuite) TestAggregationBuiltinBitOr(c *C) {
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
Expand Down