From a31fdf7eca7440560934a7ae97c1c5bc82cca291 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Fri, 12 Jun 2020 10:39:47 +0800 Subject: [PATCH] cherry pick #17848 to release-4.0 Signed-off-by: sre-bot --- expression/builtin_compare_test.go | 12 ++++++++++++ expression/builtin_compare_vec.go | 12 +++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/expression/builtin_compare_test.go b/expression/builtin_compare_test.go index 60dd79f15f0d7..dc910d0a4092f 100644 --- a/expression/builtin_compare_test.go +++ b/expression/builtin_compare_test.go @@ -290,6 +290,18 @@ func (s *testEvaluatorSuite) TestGreatestLeastFuncs(c *C) { []interface{}{tm, 123}, curTimeInt, int64(123), false, false, }, + { + []interface{}{tm, "invalid_time_1", "invalid_time_2", tmWithFsp}, + curTimeWithFspString, "invalid_time_1", false, false, + }, + { + []interface{}{tm, "invalid_time_2", "invalid_time_1", tmWithFsp}, + curTimeWithFspString, "invalid_time_2", false, false, + }, + { + []interface{}{tm, "invalid_time", nil, tmWithFsp}, + nil, nil, true, false, + }, { []interface{}{duration, "123"}, "12:59:59", "123", false, false, diff --git a/expression/builtin_compare_vec.go b/expression/builtin_compare_vec.go index 214fe4b2838b3..c1c8cc18c0c48 100644 --- a/expression/builtin_compare_vec.go +++ b/expression/builtin_compare_vec.go @@ -742,7 +742,9 @@ func (b *builtinLeastTimeSig) vecEvalString(input *chunk.Chunk, result *chunk.Co if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } else if !findInvalidTime[i] { - invalidValue[i] = result.GetString(i) + // Make a deep copy here. + // Otherwise invalidValue will internally change with result. + invalidValue[i] = string(result.GetBytes(i)) findInvalidTime[i] = true } continue @@ -754,12 +756,12 @@ func (b *builtinLeastTimeSig) vecEvalString(input *chunk.Chunk, result *chunk.Co } result.ReserveString(n) for i := 0; i < n; i++ { - if findInvalidTime[i] { - result.AppendString(invalidValue[i]) - continue - } if dst.IsNull(i) { result.AppendNull() + continue + } + if findInvalidTime[i] { + result.AppendString(invalidValue[i]) } else { result.AppendString(dstTimes[i].String()) }