Skip to content

Commit

Permalink
branch-3.0: [Opt](function) Speed up function string and add regression
Browse files Browse the repository at this point in the history
#45062 (#45107)

Cherry-picked from #45062

Co-authored-by: zclllhhjj <[email protected]>
  • Loading branch information
github-actions[bot] and zclllyybb authored Dec 19, 2024
1 parent 7b2cfc2 commit e3073ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions be/src/vec/functions/function_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,16 +888,17 @@ struct StringSpace {
ColumnString::Offsets& res_offsets) {
res_offsets.resize(data.size());
size_t input_size = res_offsets.size();
std::vector<char, Allocator_<char>> buffer;
// sample to get approximate best reserve size
if (input_size > 4) {
res_data.reserve(((data[0] + data[input_size >> 1] + data[input_size >> 2] +
data[input_size - 1]) >>
2) *
input_size);
}
for (size_t i = 0; i < input_size; ++i) {
buffer.clear();
if (data[i] > 0) {
buffer.resize(data[i]);
for (size_t j = 0; j < data[i]; ++j) {
buffer[j] = ' ';
}
StringOP::push_value_string(std::string_view(buffer.data(), buffer.size()), i,
res_data, res_offsets);
if (data[i] > 0) [[likely]] {
res_data.resize_fill(res_data.size() + data[i], ' ');
res_offsets[i] = res_data.size();
} else {
StringOP::push_empty_string(i, res_data, res_offsets);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ suite("nereids_scalar_fn_S") {

sql "select space(10) from fn_test order by kint"
sql "select space(10) from fn_test_not_nullable order by kint"
sql """select k from (select length(space(number)) k from numbers("number" = "10"))t;""" // before #44919 will crash
qt_sql_split_part_Varchar_Varchar_Integer "select split_part(kvchrs1, ' ', 1) from fn_test order by kvchrs1"
qt_sql_split_part_Varchar_Varchar_Integer_notnull "select split_part(kvchrs1, ' ', 1) from fn_test_not_nullable order by kvchrs1"
qt_sql_split_part_String_String_Integer "select split_part(kstr, ' ', 1) from fn_test order by kstr"
Expand Down

0 comments on commit e3073ed

Please sign in to comment.