[Function][Enhance] lower/upper case transfer function vectorized (#6253)

Currently, the function lower()/upper() can only handle one char at a time.
A vectorized function has been implemented, it makes performance 2 times faster. Here is the performance test:

The length of char: 26, test 100 times
vectorized-function-cost: 99491 ns
normal-function-cost: 134766 ns

The length of char: 260, test 100 times
vectorized-function-cost: 179341 ns
normal-function-cost: 344995 ns
This commit is contained in:
xinghuayu007
2021-07-26 09:38:07 +08:00
committed by GitHub
parent 8d1c1ef1e6
commit 13ef2c9e1d
5 changed files with 157 additions and 10 deletions

View File

@ -16,6 +16,8 @@
// under the License.
#include "exprs/string_functions.h"
#include "util/vectorized-tool/lower.h"
#include "util/vectorized-tool/upper.h"
#include <re2/re2.h>
@ -346,15 +348,11 @@ StringVal StringFunctions::lower(FunctionContext* context, const StringVal& str)
if (str.is_null) {
return StringVal::null();
}
// TODO pengyubing
// StringVal result = StringVal::create_temp_string_val(context, str.len);
StringVal result(context, str.len);
if (UNLIKELY(result.is_null)) {
return result;
}
for (int i = 0; i < str.len; ++i) {
result.ptr[i] = ::tolower(str.ptr[i]);
}
Lower::to_lower(str.ptr, str.len, result.ptr);
return result;
}
@ -362,15 +360,11 @@ StringVal StringFunctions::upper(FunctionContext* context, const StringVal& str)
if (str.is_null) {
return StringVal::null();
}
// TODO pengyubing
// StringVal result = StringVal::create_temp_string_val(context, str.len);
StringVal result(context, str.len);
if (UNLIKELY(result.is_null)) {
return result;
}
for (int i = 0; i < str.len; ++i) {
result.ptr[i] = ::toupper(str.ptr[i]);
}
Upper::to_upper(str.ptr, str.len, result.ptr);
return result;
}