diff --git a/be/src/olap/rowset/segment_v2/inverted_index/query/regexp_query.cpp b/be/src/olap/rowset/segment_v2/inverted_index/query/regexp_query.cpp index 83c5401bac..ee959e1da7 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index/query/regexp_query.cpp +++ b/be/src/olap/rowset/segment_v2/inverted_index/query/regexp_query.cpp @@ -70,10 +70,12 @@ void RegexpQuery::add(const std::wstring& field_name, const std::string& pattern } if (is_match) { - terms.emplace_back(std::move(input)); - if (++count >= _max_expansions) { + if (_max_expansions > 0 && count >= _max_expansions) { break; } + + terms.emplace_back(std::move(input)); + count++; } _CLDECDELETE(term); @@ -88,6 +90,10 @@ void RegexpQuery::add(const std::wstring& field_name, const std::string& pattern hs_free_database(database); }) + if (terms.empty()) { + return; + } + query.add(field_name, terms); } diff --git a/regression-test/data/inverted_index_p0/test_index_match_regexp.out b/regression-test/data/inverted_index_p0/test_index_match_regexp.out index eab27de65e..f9a9caf6d7 100644 --- a/regression-test/data/inverted_index_p0/test_index_match_regexp.out +++ b/regression-test/data/inverted_index_p0/test_index_match_regexp.out @@ -14,3 +14,6 @@ -- !sql -- 38 +-- !sql -- +0 + diff --git a/regression-test/suites/inverted_index_p0/test_index_match_regexp.groovy b/regression-test/suites/inverted_index_p0/test_index_match_regexp.groovy index 7567102d59..3458f08674 100644 --- a/regression-test/suites/inverted_index_p0/test_index_match_regexp.groovy +++ b/regression-test/suites/inverted_index_p0/test_index_match_regexp.groovy @@ -85,6 +85,8 @@ suite("test_index_match_regexp", "p0"){ qt_sql """ select count() from test_index_match_regexp where request match_regexp 's\$'; """ qt_sql """ select count() from test_index_match_regexp where request match_regexp 'er\$'; """ qt_sql """ select count() from test_index_match_regexp where request match_regexp '.*tickets.*'; """ + qt_sql """ select count() from test_index_match_regexp where request match_regexp 'nonexistence'; """ + } finally { //try_sql("DROP TABLE IF EXISTS ${testTable}") }