This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new e3073edd6f8 branch-3.0: [Opt](function) Speed up function string and
add regression #45062 (#45107)
e3073edd6f8 is described below
commit e3073edd6f868afe999480f02f69976ca1d17417
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Dec 20 00:42:31 2024 +0800
branch-3.0: [Opt](function) Speed up function string and add regression
#45062 (#45107)
Cherry-picked from #45062
Co-authored-by: zclllhhjj <[email protected]>
---
be/src/vec/functions/function_string.cpp | 19 ++++++++++---------
.../nereids_function_p0/scalar_function/S.groovy | 1 +
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/be/src/vec/functions/function_string.cpp
b/be/src/vec/functions/function_string.cpp
index 1876ed499f4..1f88c0f5bcf 100644
--- a/be/src/vec/functions/function_string.cpp
+++ b/be/src/vec/functions/function_string.cpp
@@ -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);
}
diff --git
a/regression-test/suites/nereids_function_p0/scalar_function/S.groovy
b/regression-test/suites/nereids_function_p0/scalar_function/S.groovy
index 98a8685a888..ea0d80d8adc 100644
--- a/regression-test/suites/nereids_function_p0/scalar_function/S.groovy
+++ b/regression-test/suites/nereids_function_p0/scalar_function/S.groovy
@@ -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"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]