xiaokang commented on code in PR #10169:
URL: https://github.com/apache/doris/pull/10169#discussion_r904424703
##########
be/src/vec/functions/like.cpp:
##########
@@ -129,6 +130,42 @@ Status FunctionLikeBase::vector_vector(const
ColumnString::Chars& values,
const ColumnString::Offsets&
pattern_offsets,
ColumnUInt8::Container& result, const
LikeFn& function,
LikeSearchState* search_state) {
+ // for constant_substring_fn, use long run length search for performance
+ if (constant_substring_fn ==
+ *(function.target<doris::Status (*)(LikeSearchState * state, const
StringValue&,
+ const StringValue&, unsigned
char*)>())) {
+ // treat continous multi string data as a long string data
+ const UInt8* begin = values.data();
+ const UInt8* end = begin + values.size();
+ const UInt8* pos = begin;
+
+ /// Current index in the array of strings.
+ size_t i = 0;
+ size_t needle_size =
search_state->substring_pattern.get_pattern_length();
+
+ /// We will search for the next occurrence in all strings at once.
+ while (pos < end) {
+ // search return matched substring start offset
+ pos = (UInt8*)search_state->substring_pattern.search((char*)pos,
end - pos);
+ if (pos >= end) break;
+
+ /// Determine which index it refers to.
+ /// begin + value_offsets[i] is the start offset of string at i+1
+ while (begin + value_offsets[i] <= pos) ++i;
+
+ /// We check that the entry does not pass through the boundaries
of strings.
Review Comment:
It's necessary to check the boundary.
Here is an example:
pattern: "cdef"
row1: "abcd"
row2: "efgh"
values.data: "abcdefgh"
value_offsets: [4, 8]
values.data "abcdefgh" will match pattern "cdef" at pos 2. The end of
matched substring is pos+needle_size == 6. It's beyond the end offset of row1,
which is begin+value_offsets[0]. So due to the check 'if (pos + needle_size <
begin + value_offsets[i])', we will not set result[i]=1 improperly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]