From ef7d60507d9d850f4ad71acb16cb351f492818aa Mon Sep 17 00:00:00 2001 From: lihaowei Date: Tue, 16 Mar 2021 13:20:12 +0800 Subject: [PATCH] Fix issue #23314 Signed-off-by: lihaowei --- 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 b9c4bf49bca91..489fda61fda3c 100644 --- a/executor/aggregate_test.go +++ b/executor/aggregate_test.go @@ -769,7 +769,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") @@ -1373,3 +1373,14 @@ func (s *testSerialSuite) TestRandomPanicAggConsume(c *C) { c.Assert(err.Error(), Equals, "failpoint panic: ERROR 1105 (HY000): Out Of Memory Quota![conn_id=1]") } } + +// 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 }