From f65aa2070f0eac9587fc37246fa03eebdb4158ce Mon Sep 17 00:00:00 2001 From: guo-shaoge Date: Tue, 12 Nov 2024 17:45:57 +0800 Subject: [PATCH 1/4] fix substring wrong result bug Signed-off-by: guo-shaoge --- dbms/src/Functions/FunctionsString.cpp | 1 + tests/fullstack-test/expr/substring_utf8.test | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/dbms/src/Functions/FunctionsString.cpp b/dbms/src/Functions/FunctionsString.cpp index dd37d46b65d..c335a231d06 100644 --- a/dbms/src/Functions/FunctionsString.cpp +++ b/dbms/src/Functions/FunctionsString.cpp @@ -818,6 +818,7 @@ struct SubstringUTF8Impl res_data[res_offset] = 0; ++res_offset; res_offsets[column_index] = res_offset; + prev_offset = offsets[column_index]; return; } start = start_offsets.size() - original_start_abs + 1; diff --git a/tests/fullstack-test/expr/substring_utf8.test b/tests/fullstack-test/expr/substring_utf8.test index 13534c00230..b950d37d052 100644 --- a/tests/fullstack-test/expr/substring_utf8.test +++ b/tests/fullstack-test/expr/substring_utf8.test @@ -44,3 +44,27 @@ a 1 mysql> drop table if exists test.t + +mysql> drop table if exists test.t1 +mysql> create table test.t1 (c1 int, c2 int) +mysql> insert into test.t1 (c1, c2) values (-82 , -4), ( 1 , 4); +mysql> alter table test.t1 set tiflash replica 1; +func> wait_table test test.t1 + +mysql> set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select c2, substring('abc', c2) as b FROM test.t1 order by 1, 2 ++------+------+ +| c2 | b | ++------+------+ +| -4 | | +| 4 | | ++------+------+ + +mysql> set session tidb_isolation_read_engines='tiflash'; set tidb_allow_mpp=0; set tidb_allow_tiflash_cop = ON; select c2, substring('abc', c2) as b FROM test.t1 order by 1, 2 ++------+------+ +| c2 | b | ++------+------+ +| -4 | | +| 4 | | ++------+------+ + +mysql> drop table if exists test.t1 From b295fd073c0562474ca7baf8142e6cabad44329a Mon Sep 17 00:00:00 2001 From: guo-shaoge Date: Wed, 13 Nov 2024 15:20:47 +0800 Subject: [PATCH 2/4] fix case Signed-off-by: guo-shaoge --- tests/fullstack-test/expr/substring_utf8.test | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fullstack-test/expr/substring_utf8.test b/tests/fullstack-test/expr/substring_utf8.test index b950d37d052..fa9e2ff4dad 100644 --- a/tests/fullstack-test/expr/substring_utf8.test +++ b/tests/fullstack-test/expr/substring_utf8.test @@ -47,9 +47,9 @@ mysql> drop table if exists test.t mysql> drop table if exists test.t1 mysql> create table test.t1 (c1 int, c2 int) -mysql> insert into test.t1 (c1, c2) values (-82 , -4), ( 1 , 4); -mysql> alter table test.t1 set tiflash replica 1; -func> wait_table test test.t1 +mysql> insert into test.t1 (c1, c2) values (-82 , -4), ( 1 , 4) +mysql> alter table test.t1 set tiflash replica 1 +func> wait_table test t1 mysql> set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select c2, substring('abc', c2) as b FROM test.t1 order by 1, 2 +------+------+ From b9870a57769f40c94354a730a2021c5fbb60d516 Mon Sep 17 00:00:00 2001 From: guo-shaoge Date: Mon, 18 Nov 2024 14:06:49 +0800 Subject: [PATCH 3/4] fix case Signed-off-by: guo-shaoge --- tests/fullstack-test/expr/substring_utf8.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fullstack-test/expr/substring_utf8.test b/tests/fullstack-test/expr/substring_utf8.test index fa9e2ff4dad..3612570f235 100644 --- a/tests/fullstack-test/expr/substring_utf8.test +++ b/tests/fullstack-test/expr/substring_utf8.test @@ -59,7 +59,7 @@ mysql> set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select | 4 | | +------+------+ -mysql> set session tidb_isolation_read_engines='tiflash'; set tidb_allow_mpp=0; set tidb_allow_tiflash_cop = ON; select c2, substring('abc', c2) as b FROM test.t1 order by 1, 2 +mysql> set session tidb_isolation_read_engines='tiflash'; set tidb_allow_mpp=0; select c2, substring('abc', c2) as b FROM test.t1 order by 1, 2 +------+------+ | c2 | b | +------+------+ From 389e0fbe369888c63220a72ca7d9ba45445fe4bf Mon Sep 17 00:00:00 2001 From: guo-shaoge Date: Mon, 18 Nov 2024 14:09:35 +0800 Subject: [PATCH 4/4] fix Signed-off-by: guo-shaoge --- tests/fullstack-test/expr/substring_utf8.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fullstack-test/expr/substring_utf8.test b/tests/fullstack-test/expr/substring_utf8.test index 3612570f235..9e7940f377c 100644 --- a/tests/fullstack-test/expr/substring_utf8.test +++ b/tests/fullstack-test/expr/substring_utf8.test @@ -51,7 +51,7 @@ mysql> insert into test.t1 (c1, c2) values (-82 , -4), ( 1 , 4) mysql> alter table test.t1 set tiflash replica 1 func> wait_table test t1 -mysql> set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select c2, substring('abc', c2) as b FROM test.t1 order by 1, 2 +mysql> set tidb_allow_mpp=1; set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select c2, substring('abc', c2) as b FROM test.t1 order by 1, 2 +------+------+ | c2 | b | +------+------+