Skip to content

Commit df0d8c7

Browse files
sre-botzz-jason
authored andcommitted
expression: deduce result type for multi-argument functions li… (#11621)
1 parent 94498e7 commit df0d8c7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

expression/builtin_control.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ func InferType4ControlFuncs(lhs, rhs *types.FieldType) *types.FieldType {
6767
} else if rhs.Tp == mysql.TypeNull {
6868
*resultFieldType = *lhs
6969
} else {
70-
var unsignedFlag uint
71-
evalType := types.AggregateEvalType([]*types.FieldType{lhs, rhs}, &unsignedFlag)
7270
resultFieldType = types.AggFieldType([]*types.FieldType{lhs, rhs})
71+
evalType := types.AggregateEvalType([]*types.FieldType{lhs, rhs}, &resultFieldType.Flag)
7372
if evalType == types.ETInt {
7473
resultFieldType.Decimal = 0
7574
} else {

expression/integration_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4653,6 +4653,18 @@ func (s *testIntegrationSuite) TestFuncCaseWithLeftJoin(c *C) {
46534653
tk.MustQuery("select t1.id from kankan1 t1 left join kankan2 t2 on t1.id = t2.id where (case when t1.name='b' then 'case2' when t1.name='a' then 'case1' else NULL end) = 'case1' order by t1.id").Check(testkit.Rows("1", "2"))
46544654
}
46554655

4656+
func (s *testIntegrationSuite) TestIssue11594(c *C) {
4657+
tk := testkit.NewTestKit(c, s.store)
4658+
tk.MustExec("use test")
4659+
tk.MustExec(`drop table if exists t1;`)
4660+
tk.MustExec("CREATE TABLE t1 (v bigint(20) UNSIGNED NOT NULL);")
4661+
tk.MustExec("INSERT INTO t1 VALUES (1), (2);")
4662+
tk.MustQuery("SELECT SUM(IF(v > 1, v, -v)) FROM t1;").Check(testkit.Rows("1"))
4663+
tk.MustQuery("SELECT sum(IFNULL(cast(null+rand() as unsigned), -v)) FROM t1;").Check(testkit.Rows("-3"))
4664+
tk.MustQuery("SELECT sum(COALESCE(cast(null+rand() as unsigned), -v)) FROM t1;").Check(testkit.Rows("-3"))
4665+
tk.MustQuery("SELECT sum(COALESCE(cast(null+rand() as unsigned), v)) FROM t1;").Check(testkit.Rows("3"))
4666+
}
4667+
46564668
func (s *testIntegrationSuite) TestIssue11309And11319(c *C) {
46574669
tk := testkit.NewTestKit(c, s.store)
46584670
tk.MustExec("use test")

0 commit comments

Comments
 (0)