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

[Opt](function) Speed up function string and add regression #45062

Merged
merged 1 commit into from
Dec 6, 2024
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
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
Loading