Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: fix substring_index crash tiflash in some case (#9137) #9140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dbms/src/Functions/FunctionsString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5268,6 +5268,7 @@ class FunctionSubStringIndex : public IFunction
const UInt8 * pos = begin;
const UInt8 * end = pos + data_size;
assert(delim_size != 0);
assert(count != 0);
if (count > 0)
{
// Fast exit when count * delim_size > data_size
Expand All @@ -5283,10 +5284,11 @@ class FunctionSubStringIndex : public IFunction
if (match == end || count == 0)
{
copyDataToResult(res_data, res_offset, begin, match);
break;
return;
}
pos = match + delim_size;
}
copyDataToResult(res_data, res_offset, begin, end);
}
else
{
Expand Down
9 changes: 9 additions & 0 deletions dbms/src/Functions/tests/gtest_substring_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ try
createColumn<Nullable<String>>({"www.pingcap.com", "www...www", "中文.测.试。。。", "www.www"}),
createColumn<Nullable<String>>({"", "", "", ""}),
createColumn<Nullable<Int64>>({2, 2, 2, 2})));

// Test issue 9116
ASSERT_COLUMN_EQ(
createColumn<Nullable<String>>({"aaabbba", "aaabbbaa", "aaabbbaaa", "aaabbbaaa", "aaabbbaaa"}),
executeFunction(
func_name,
createColumn<Nullable<String>>({"aaabbbaaa", "aaabbbaaa", "aaabbbaaa", "aaabbbaaa", "aaabbbaaa"}),
createColumn<Nullable<String>>({"a", "a", "a", "a", "a"}),
createColumn<Nullable<Int64>>({5, 6, 7, 8, 9})));
}
CATCH

Expand Down