From 6b376d13d88fd906d415761f142a91e0efc1ad61 Mon Sep 17 00:00:00 2001 From: Jerry Hu Date: Fri, 25 Aug 2023 16:41:39 +0800 Subject: [PATCH] [improvement](function) do not use hyperscan for non-const partterns in like function --- be/src/vec/functions/like.cpp | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/be/src/vec/functions/like.cpp b/be/src/vec/functions/like.cpp index 8d56c4f2d11882..1a83dc8a87804c 100644 --- a/be/src/vec/functions/like.cpp +++ b/be/src/vec/functions/like.cpp @@ -272,27 +272,14 @@ Status FunctionLikeBase::regexp_fn_scalar(LikeSearchState* state, const StringRe const StringRef& pattern, unsigned char* result) { std::string re_pattern(pattern.data, pattern.size); - hs_database_t* database = nullptr; - hs_scratch_t* scratch = nullptr; - if (hs_prepare(nullptr, re_pattern.c_str(), &database, &scratch).ok()) { // use hyperscan - auto ret = hs_scan(database, val.data, val.size, 0, scratch, - doris::vectorized::LikeSearchState::hs_match_handler, (void*)result); - if (ret != HS_SUCCESS && ret != HS_SCAN_TERMINATED) { - return Status::RuntimeError(fmt::format("hyperscan error: {}", ret)); - } - - hs_free_scratch(scratch); - hs_free_database(database); - } else { // fallback to re2 - RE2::Options opts; - opts.set_never_nl(false); - opts.set_dot_nl(true); - re2::RE2 re(re_pattern, opts); - if (re.ok()) { - *result = RE2::PartialMatch(re2::StringPiece(val.data, val.size), re); - } else { - return Status::RuntimeError("Invalid pattern: {}", pattern.debug_string()); - } + RE2::Options opts; + opts.set_never_nl(false); + opts.set_dot_nl(true); + re2::RE2 re(re_pattern, opts); + if (re.ok()) { + *result = RE2::PartialMatch(re2::StringPiece(val.data, val.size), re); + } else { + return Status::RuntimeError("Invalid pattern: {}", pattern.debug_string()); } return Status::OK();