Skip to content

Commit 4e66879

Browse files
ti-chi-botguo-shaogeti-chi-bot[bot]
authored
fix substring wrong result bug (#9603) (#9618)
close #9604 Signed-off-by: guo-shaoge <shaoge1994@163.com> Co-authored-by: guo-shaoge <shaoge1994@163.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent 7de7609 commit 4e66879

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

dbms/src/Functions/FunctionsString.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ struct SubstringUTF8Impl
847847
res_data[res_offset] = 0;
848848
++res_offset;
849849
res_offsets[column_index] = res_offset;
850+
prev_offset = offsets[column_index];
850851
return;
851852
}
852853
start = start_offsets.size() - original_start_abs + 1;

tests/fullstack-test/expr/substring_utf8.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,27 @@ a
4444
1
4545

4646
mysql> drop table if exists test.t
47+
48+
mysql> drop table if exists test.t1
49+
mysql> create table test.t1 (c1 int, c2 int)
50+
mysql> insert into test.t1 (c1, c2) values (-82 , -4), ( 1 , 4)
51+
mysql> alter table test.t1 set tiflash replica 1
52+
func> wait_table test t1
53+
54+
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
55+
+------+------+
56+
| c2 | b |
57+
+------+------+
58+
| -4 | |
59+
| 4 | |
60+
+------+------+
61+
62+
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
63+
+------+------+
64+
| c2 | b |
65+
+------+------+
66+
| -4 | |
67+
| 4 | |
68+
+------+------+
69+
70+
mysql> drop table if exists test.t1

0 commit comments

Comments
 (0)