From 5a54d0d9b480ddcdcdf44f0e1375f6a41931f615 Mon Sep 17 00:00:00 2001 From: UBarney Date: Tue, 29 Mar 2022 15:12:28 +0800 Subject: [PATCH] expression: fix append to result twice when vecEval compress('') (#33523) close pingcap/tidb#33397 --- expression/builtin_encryption_vec.go | 1 + expression/integration_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/expression/builtin_encryption_vec.go b/expression/builtin_encryption_vec.go index 4433463429127..1c2124b8c3001 100644 --- a/expression/builtin_encryption_vec.go +++ b/expression/builtin_encryption_vec.go @@ -567,6 +567,7 @@ func (b *builtinCompressSig) vecEvalString(input *chunk.Chunk, result *chunk.Col // According to doc: Empty strings are stored as empty strings. if len(strBytes) == 0 { result.AppendString("") + continue } compressed, err := deflate(strBytes) diff --git a/expression/integration_test.go b/expression/integration_test.go index e99b6a3db703c..d7a7717e5b34f 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7078,3 +7078,16 @@ func TestIssue32488(t *testing.T) { tk.MustQuery("select binary upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"Ʞ ʞ"}}) tk.MustQuery("select distinct upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"Ʞ ʞ"}}) } + +func TestIssue33397(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t(a varchar(32)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;") + tk.MustExec("insert into t values(''), ('');") + tk.MustExec("set @@tidb_enable_vectorized_expression = true;") + result := tk.MustQuery("select compress(a) from t").Rows() + require.Equal(t, [][]interface{}{{""}, {""}}, result) +}