BiteTheDDDDt commented on code in PR #10169: URL: https://github.com/apache/doris/pull/10169#discussion_r902713424
########## 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: Whether our `text` and `pattern` may contain `\0`? If it is impossible to contain `\0`, then this check will be unnecessary ########## be/src/vec/common/string_searcher.h: ########## @@ -0,0 +1,860 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// This file is copied from +// https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/StringSearcher.h +// and modified by Doris + +#pragma once + +#include <stdint.h> +#include <string.h> + +#include <algorithm> +#include <limits> +#include <vector> + +#include "vec/common/string_utils/string_utils.h" + +#ifdef __SSE2__ +#include <emmintrin.h> +#endif + +#ifdef __SSE4_1__ +#include <smmintrin.h> +#endif + +namespace doris { + +// namespace ErrorCodes +// { +// extern const int BAD_ARGUMENTS; +// } + +/** Variants for searching a substring in a string. + * In most cases, performance is less than Volnitsky (see Volnitsky.h). + */ + +class StringSearcherBase { +public: + bool force_fallback = false; +#ifdef __SSE2__ +protected: + static constexpr auto n = sizeof(__m128i); + const int page_size = sysconf(_SC_PAGESIZE); //::getPageSize(); + + bool page_safe(const void* const ptr) const { + return ((page_size - 1) & reinterpret_cast<std::uintptr_t>(ptr)) <= page_size - n; + } +#endif +}; + +/// Performs case-sensitive and case-insensitive search of UTF-8 strings +template <bool CaseSensitive, bool ASCII> +class StringSearcher; + +// comment out since it's not used in doris and UTF8 dependency is not easy to meet Review Comment: Does we should keep those unused code? ########## 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 == Review Comment: Maybe we should move it to a function like named `vector_constant` -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org