Repository: pingcap/tidb (Go)

Issue:
should ensure all columns have the same length, expect 103, but got 104
## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

<!-- a step by step guide for reproducing the bug. -->
```
use test;
source [test.txt](https://github.com/pingcap/tidb/files/8340417/test.txt)
set tidb_enable_vectorized_expression=on;
select * from PK_SNPRE10113 where compress(col1) = compress(col1);

set tidb_enable_vectorized_expression=off;
select * from PK_SNPRE10113 where compress(col1) = compress(col1);
```
### 2. What did you expect to see? (Required)

```
MySQL [test]> set tidb_enable_vectorized_expression=on;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> select * from PK_SNPRE10113 where compress(col1) = compress(col1);

+--------------------------------+--------------------------------------------------------------+---------------------+----------------------+-------------+
...
+--------------------------------+--------------------------------------------------------------+---------------------+----------------------+-------------+
103 rows in set (0.22 sec)
MySQL [test]>
MySQL [test]> set tidb_enable_vectorized_expression=off;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> select * from PK_SNPRE10113 where compress(col1) = compress(col1);
+--------------------------------+--------------------------------------------------------------+---------------------+----------------------+-------------+
...
+--------------------------------+--------------------------------------------------------------+---------------------+----------------------+-------------+
103 rows in set (0.22 sec)
```
### 3. What did you see instead (Required)
```
MySQL [test]> set tidb_enable_vectorized_expression=on;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> select * from PK_SNPRE10113 where compress(col1) = compress(col1);
ERROR 1105 (HY000): should ensure all columns have the same length, expect 103, but got 104
MySQL [test]>
MySQL [test]> set tidb_enable_vectorized_expression=off;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> select * from PK_SNPRE10113 where compress(col1) = compress(col1);
+--------------------------------+--------------------------------------------------------------+---------------------+----------------------+-------------+
...
+--------------------------------+--------------------------------------------------------------+---------------------+----------------------+-------------+
103 rows in set (0.22 sec)
```
### 4. What is your TiDB version? (Required)

<!-- Paste the output of SELECT tidb_version() -->
```
Release Version: v6.1.0-alpha-38-g6d01855
Edition: Community
Git Commit Hash: 6d01855856aac61e0829f73ed8a47be6add45321
Git Branch: master
UTC Build Time: 2022-03-24 01:03:09
GoVersion: go1.17.6
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
```



Discussion:
/assign



Patch:
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)


Test patch:
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)
+}