Skip to content

Commit

Permalink
fix substring wrong result bug (#9603) (#9622)
Browse files Browse the repository at this point in the history
close #9604

Signed-off-by: guo-shaoge <shaoge1994@163.com>

Co-authored-by: guo-shaoge <shaoge1994@163.com>
Co-authored-by: JaySon <tshent@qq.com>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 7f1dd8c commit a95bef8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions dbms/src/Functions/FunctionsString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,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;
Expand Down
24 changes: 24 additions & 0 deletions tests/fullstack-test/expr/substring_utf8.test
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,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 bigint)
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
+------+------+
| 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

0 comments on commit a95bef8

Please sign in to comment.