diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 32a35e021fd25..7f953ce1cda91 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -1684,7 +1684,6 @@ func (c *fromUnixTimeFunctionClass) getFunction(ctx sessionctx.Context, args []E } if len(args) > 1 { - bf.tp.Flen = args[1].GetType().Flen sig = &builtinFromUnixTime2ArgSig{bf} sig.setPbCode(tipb.ScalarFuncSig_FromUnixTime2Arg) return sig, nil diff --git a/expression/integration_test.go b/expression/integration_test.go index d24c10d0fcff0..c45990245334e 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6684,6 +6684,23 @@ func (s *testIntegrationSuite) TestIssue18515(c *C) { tk.MustExec("select /*+ TIDB_INLJ(t2) */ t1.a, t1.c, t2.a from t t1, t t2 where t1.c=t2.c;") } +func (s *testIntegrationSuite) TestIssue20223(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("CREATE TABLE t (" + + "id int(10) unsigned NOT NULL AUTO_INCREMENT," + + "type tinyint(4) NOT NULL," + + "create_time int(11) NOT NULL," + + "PRIMARY KEY (id)" + + ")") + tk.MustExec("insert into t values (4, 2, 1598584933)") + tk.MustQuery("select from_unixtime(create_time,'%Y-%m-%d') as t_day,count(*) as cnt from t where `type` = 1 " + + "group by t_day union all " + + "select from_unixtime(create_time,'%Y-%m-%d') as t_day,count(*) as cnt from t where `type` = 2 " + + "group by t_day").Check(testkit.Rows("2020-08-28 1")) +} + func (s *testIntegrationSuite) TestIssue18525(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/expression/typeinfer_test.go b/expression/typeinfer_test.go index 51d30d059edc0..b1c2be753779b 100644 --- a/expression/typeinfer_test.go +++ b/expression/typeinfer_test.go @@ -1864,7 +1864,7 @@ func (s *testInferTypeSuite) createTestCase4TimeFuncs() []typeInferTestCase { {"from_unixtime(20170101.999)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDatetimeWidthWithFsp, 3}, {"from_unixtime(20170101.1234567)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDatetimeWidthWithFsp, int(types.MaxFsp)}, {"from_unixtime('20170101.999')", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDatetimeWidthWithFsp, int(types.MaxFsp)}, - {"from_unixtime(20170101.123, '%H')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, 2, types.UnspecifiedLength}, + {"from_unixtime(20170101.123, '%H')", mysql.TypeVarString, charset.CharsetUTF8MB4, 0, -1, types.UnspecifiedLength}, {"extract(day from c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0}, {"extract(hour from c_char)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0},