From c1ed7ca004944c8b60799f70d8b5e23225084edf Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 29 Jun 2015 21:47:46 +0300 Subject: [PATCH] dbms: fixed error with LIKE [#METR-17078]. --- dbms/include/DB/Functions/FunctionsStringSearch.h | 7 ++++++- .../queries/0_stateless/00187_like_regexp_prefix.reference | 1 + .../tests/queries/0_stateless/00187_like_regexp_prefix.sql | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/00187_like_regexp_prefix.reference create mode 100644 dbms/tests/queries/0_stateless/00187_like_regexp_prefix.sql diff --git a/dbms/include/DB/Functions/FunctionsStringSearch.h b/dbms/include/DB/Functions/FunctionsStringSearch.h index 351fb47f1ef..f1a5a3a45a1 100644 --- a/dbms/include/DB/Functions/FunctionsStringSearch.h +++ b/dbms/include/DB/Functions/FunctionsStringSearch.h @@ -447,10 +447,15 @@ struct MatchImpl const char * str_data = reinterpret_cast(&data[i != 0 ? offsets[i - 1] : 0]); size_t str_size = (i != 0 ? offsets[i] - offsets[i - 1] : offsets[0]) - 1; + /** Даже в случае required_substring_is_prefix используем UNANCHORED проверку регекспа, + * чтобы он мог сматчиться, когда required_substring встречается в строке несколько раз, + * и на первом вхождении регексп не матчит. + */ + if (required_substring_is_prefix) res[i] = revert ^ regexp->getRE2()->Match( re2_st::StringPiece(str_data, str_size), - reinterpret_cast(pos) - str_data, str_size, re2_st::RE2::ANCHOR_START, nullptr, 0); + reinterpret_cast(pos) - str_data, str_size, re2_st::RE2::UNANCHORED, nullptr, 0); else res[i] = revert ^ regexp->getRE2()->Match( re2_st::StringPiece(str_data, str_size), diff --git a/dbms/tests/queries/0_stateless/00187_like_regexp_prefix.reference b/dbms/tests/queries/0_stateless/00187_like_regexp_prefix.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00187_like_regexp_prefix.reference @@ -0,0 +1 @@ +1 diff --git a/dbms/tests/queries/0_stateless/00187_like_regexp_prefix.sql b/dbms/tests/queries/0_stateless/00187_like_regexp_prefix.sql new file mode 100644 index 00000000000..7fec21b68ad --- /dev/null +++ b/dbms/tests/queries/0_stateless/00187_like_regexp_prefix.sql @@ -0,0 +1 @@ +SELECT materialize('prepre_f') LIKE '%pre_f%';