From cb9f4b13b0938d317ad4b432aea30de3891b7283 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Mon, 22 Nov 2021 18:35:49 +0800 Subject: [PATCH] expression: Fix wrong result of hour function in vectorized expression (#28857) (#28870) --- expression/builtin_time_vec.go | 3 +-- expression/integration_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/expression/builtin_time_vec.go b/expression/builtin_time_vec.go index f509d5a9fcfcd..db7e613bde0d3 100644 --- a/expression/builtin_time_vec.go +++ b/expression/builtin_time_vec.go @@ -1836,12 +1836,11 @@ func (b *builtinHourSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) er result.ResizeInt64(n, false) result.MergeNulls(buf) i64s := result.Int64s() - ds := buf.GoDurations() for i := 0; i < n; i++ { if result.IsNull(i) { continue } - i64s[i] = int64(ds[i].Hours()) + i64s[i] = int64(buf.GetDuration(i, int(types.UnspecifiedFsp)).Hour()) } return nil } diff --git a/expression/integration_test.go b/expression/integration_test.go index be4f1d33b79fc..b1d877a727312 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -8377,6 +8377,19 @@ func (s *testIntegrationSuite) TestConstPropNullFunctions(c *C) { tk.MustQuery("select * from t2 where t2.i2=((select count(1) from t1 where t1.i1=t2.i2))").Check(testkit.Rows("1 0.1")) } +func (s *testIntegrationSuite) TestIssue28643(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 time(4));") + tk.MustExec("insert into t values(\"-838:59:59.000000\");") + tk.MustExec("insert into t values(\"838:59:59.000000\");") + tk.MustExec("set tidb_enable_vectorized_expression = on;") + tk.MustQuery("select hour(a) from t;").Check(testkit.Rows("838", "838")) + tk.MustExec("set tidb_enable_vectorized_expression = off;") + tk.MustQuery("select hour(a) from t;").Check(testkit.Rows("838", "838")) +} + func (s *testIntegrationSuite) TestIssue29244(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test")