From 46dff7c19ef5992748a1ce78abfea8cb6760863e Mon Sep 17 00:00:00 2001 From: Howie Date: Thu, 18 Mar 2021 18:01:36 +0800 Subject: [PATCH] cherry pick #23332 to release-5.0 Signed-off-by: ti-srebot --- executor/aggregate_test.go | 13 ++++++++++++- expression/builtin_cast_vec.go | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/executor/aggregate_test.go b/executor/aggregate_test.go index 1d5318e0498f2..56fe7f2df6611 100644 --- a/executor/aggregate_test.go +++ b/executor/aggregate_test.go @@ -770,7 +770,7 @@ func (s *testSuiteAgg) TestOnlyFullGroupBy(c *C) { tk.MustQuery("select max(a+b) from t") tk.MustQuery("select avg(a)+1 from t") tk.MustQuery("select count(c), 5 from t") - // test functinal depend on primary key + // test functional depend on primary key tk.MustQuery("select * from t group by a") // test functional depend on unique not null columns tk.MustQuery("select * from t group by b,d") @@ -1441,3 +1441,14 @@ func (s *testSuiteAgg) TestIssue23277(c *C) { tk.MustQuery("select avg(a) from t group by a").Sort().Check(testkit.Rows("-120.0000", "127.0000")) tk.MustExec("drop table t;") } + +// https://github.com/pingcap/tidb/issues/23314 +func (s *testSuiteAgg) TestIssue23314(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1") + tk.MustExec("create table t1(col1 time(2) NOT NULL)") + tk.MustExec("insert into t1 values(\"16:40:20.01\")") + res := tk.MustQuery("select col1 from t1 group by col1") + res.Check(testkit.Rows("16:40:20.01")) +} diff --git a/expression/builtin_cast_vec.go b/expression/builtin_cast_vec.go index 4ec1d138f8f41..e350d6154ce78 100644 --- a/expression/builtin_cast_vec.go +++ b/expression/builtin_cast_vec.go @@ -1304,12 +1304,13 @@ func (b *builtinCastDurationAsStringSig) vecEvalString(input *chunk.Chunk, resul var isNull bool sc := b.ctx.GetSessionVars().StmtCtx result.ReserveString(n) + fsp := b.args[0].GetType().Decimal for i := 0; i < n; i++ { if buf.IsNull(i) { result.AppendNull() continue } - res, err = types.ProduceStrWithSpecifiedTp(buf.GetDuration(i, 0).String(), b.tp, sc, false) + res, err = types.ProduceStrWithSpecifiedTp(buf.GetDuration(i, fsp).String(), b.tp, sc, false) if err != nil { return err }