This is an automated email from the ASF dual-hosted git repository.
airborne12 pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 91e2204ae46 branch-4.1: [fix](search) Keep numeric SEARCH leaves on
the inverted index #70488 (#70547)
91e2204ae46 is described below
commit 91e2204ae4605a4537c7290b2d75107bc88fdb6c
Author: guptashivam04 <[email protected]>
AuthorDate: Mon Nov 23 06:49:00 2026 +0530
branch-4.1: [fix](search) Keep numeric SEARCH leaves on the inverted index
#70488 (#70547)
### What problem does this PR solve?
Issue Number: None
Related PR: #70488 (master fix), #64782 (same fix, closed without merge)
Problem Summary:
`search()` has no row-by-row path, but a SEARCH term on a numeric (BKD)
field goes through `read_from_index` without `skip_try`. When the value
matches more than `inverted_index_skip_threshold` percent of a segment
(50 by default), the iterator returns `INVERTED_INDEX_BYPASS`, the
segment iterator falls back to row evaluation, and the query fails:
```
SELECT count(*) FROM t WHERE search('v.account_id:8069')
ERROR: [INTERNAL_ERROR]SearchExpr should not be executed without inverted
index
```
It often passes on a cold run and fails once the exact hit count comes
from the inverted index query cache, so it looks random to users. An
account or tenant id on a table loaded per account is enough to hit it.
This sets `skip_try` for the direct index reader leaf in
`FunctionSearch::build_leaf_query`, so SEARCH always reads the index.
MATCH and plain predicates keep the bypass. Workaround on unpatched
versions: `SET inverted_index_skip_threshold = 100`.
---
be/src/exprs/function/function_search.cpp | 4 ++
be/test/exprs/function/function_search_test.cpp | 4 ++
.../data/search/test_search_bkd_skip_threshold.out | 26 +++++++
.../search/test_search_bkd_skip_threshold.groovy | 82 ++++++++++++++++++++++
4 files changed, 116 insertions(+)
diff --git a/be/src/exprs/function/function_search.cpp
b/be/src/exprs/function/function_search.cpp
index 96e5208df24..8d70c75d22b 100644
--- a/be/src/exprs/function/function_search.cpp
+++ b/be/src/exprs/function/function_search.cpp
@@ -760,6 +760,10 @@ Status FunctionSearch::build_leaf_query(const
TSearchClause& clause,
param.query_type = direct_query_type;
param.num_rows = num_rows;
param.roaring = std::make_shared<roaring::Roaring>();
+ // SEARCH has no row-by-row fallback, so a BKD leaf must not take the
+ // inverted_index_skip_threshold bypass: a bypassed leaf would be
evaluated without
+ // the index and fail.
+ param.skip_try = true;
RETURN_IF_ERROR(iterator->read_from_index(segment_v2::IndexParam
{¶m}));
return
finish_leaf_query(std::make_shared<query_v2::BitSetQuery>(std::move(param.roaring)));
diff --git a/be/test/exprs/function/function_search_test.cpp
b/be/test/exprs/function/function_search_test.cpp
index d28e4d274be..502409ebbd8 100644
--- a/be/test/exprs/function/function_search_test.cpp
+++ b/be/test/exprs/function/function_search_test.cpp
@@ -96,6 +96,7 @@ public:
if (i_param->query_value.get_type() == TYPE_INT) {
last_int_value = i_param->query_value.get<TYPE_INT>();
}
+ last_skip_try = i_param->skip_try;
if (i_param->roaring != nullptr) {
i_param->roaring->add(3);
}
@@ -115,6 +116,7 @@ public:
PrimitiveType last_query_value_type = PrimitiveType::TYPE_NULL;
bool last_bool_value = false;
Int32 last_int_value = 0;
+ bool last_skip_try = false;
};
class DummyInvertedIndexReader final : public segment_v2::InvertedIndexReader {
@@ -2143,6 +2145,8 @@ TEST_F(FunctionSearchTest,
TestBuildLeafQueryVariantNestedIntUsesDirectIndexRead
EXPECT_EQ(InvertedIndexQueryType::EQUAL_QUERY, iterator.last_query_type);
EXPECT_EQ(TYPE_INT, iterator.last_query_value_type);
EXPECT_EQ(3, iterator.last_int_value);
+ // SEARCH has no row fallback, so the BKD skip-threshold bypass must be
disabled.
+ EXPECT_TRUE(iterator.last_skip_try);
}
TEST_F(FunctionSearchTest, TestMultiPhraseQueryCase) {
diff --git a/regression-test/data/search/test_search_bkd_skip_threshold.out
b/regression-test/data/search/test_search_bkd_skip_threshold.out
new file mode 100644
index 00000000000..77a2bdab1d1
--- /dev/null
+++ b/regression-test/data/search/test_search_bkd_skip_threshold.out
@@ -0,0 +1,26 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !dense_variant --
+7
+
+-- !dense_column --
+7
+
+-- !dense_and_text --
+4
+
+-- !dense_or --
+9
+
+-- !sparse_variant --
+2
+
+-- !sparse_column --
+2
+
+-- !dense_topn --
+7
+6
+
+-- !dense_standard_mode --
+4
+
diff --git
a/regression-test/suites/search/test_search_bkd_skip_threshold.groovy
b/regression-test/suites/search/test_search_bkd_skip_threshold.groovy
new file mode 100644
index 00000000000..ca613f8d29c
--- /dev/null
+++ b/regression-test/suites/search/test_search_bkd_skip_threshold.groovy
@@ -0,0 +1,82 @@
+// 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.
+
+// A numeric (BKD) leaf that matches more than inverted_index_skip_threshold
percent of a
+// segment used to return INVERTED_INDEX_BYPASS. SEARCH has no row-by-row
path, so the
+// query failed with "SearchExpr should not be executed without inverted
index". SEARCH must
+// always use the index.
+suite("test_search_bkd_skip_threshold", "p0") {
+ sql """ set enable_common_expr_pushdown = true """
+ sql """ set enable_inverted_index_query_cache = true """
+ sql """ set enable_sql_cache = false """
+ sql """ set inverted_index_skip_threshold = 50 """
+ sql """ set default_variant_enable_typed_paths_to_sparse = false """
+ sql """ set default_variant_enable_doc_mode = false """
+ // Keep both v.n and v.p as indexed subcolumns; a fuzzy budget of 1 would
push one to sparse.
+ sql """ set default_variant_max_subcolumns_count = 2048 """
+
+ sql "DROP TABLE IF EXISTS test_search_bkd_skip_threshold_t"
+ sql """
+ CREATE TABLE test_search_bkd_skip_threshold_t (
+ `id` INT NOT NULL,
+ `k` INT NULL,
+ `v` variant NULL,
+ INDEX idx_k (k) USING INVERTED,
+ INDEX idx_v (v) USING INVERTED PROPERTIES(
+ "parser" = "unicode", "lower_case" = "true", "support_phrase"
= "true")
+ ) ENGINE=OLAP
+ UNIQUE KEY(`id`)
+ DISTRIBUTED BY HASH(`id`) BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "enable_unique_key_merge_on_write" = "true",
+ "disable_auto_compaction" = "true"
+ )
+ """
+
+ // 7 of 10 rows have n = 5 and k = 5, so a BKD lookup for 5 hits 70% of
the segment.
+ sql """INSERT INTO test_search_bkd_skip_threshold_t VALUES
+ (1, 5, '{"n": 5, "p": "software engineer"}'),
+ (2, 5, '{"n": 5, "p": "sales"}'),
+ (3, 5, '{"n": 5, "p": "software developer"}'),
+ (4, 5, '{"n": 5, "p": "sales"}'),
+ (5, 5, '{"n": 5, "p": "software engineer"}'),
+ (6, 5, '{"n": 5, "p": "sales"}'),
+ (7, 5, '{"n": 5, "p": "software tester"}'),
+ (8, 6, '{"n": 6, "p": "software engineer"}'),
+ (9, 6, '{"n": 6, "p": "sales"}'),
+ (10, 7, '{"n": 7, "p": "software engineer"}')
+ """
+
+ // The first lookup of a value can pass on the BKD estimate. Warm both
numeric leaves so the
+ // exact hit count is in the inverted index query cache; every check below
then runs its
+ // SEARCH expression for the first time and sees that count, which is over
the threshold.
+ sql "SELECT count(*) FROM test_search_bkd_skip_threshold_t WHERE
search('v.n:5')"
+ sql "SELECT count(*) FROM test_search_bkd_skip_threshold_t WHERE
search('k:5')"
+
+ qt_dense_variant """SELECT count(*) FROM test_search_bkd_skip_threshold_t
WHERE search('v.n:5')"""
+ qt_dense_column """SELECT count(*) FROM test_search_bkd_skip_threshold_t
WHERE search('k:5')"""
+ qt_dense_and_text """SELECT count(*) FROM test_search_bkd_skip_threshold_t
+ WHERE search('v.n:5 AND v.p:software')"""
+ qt_dense_or """SELECT count(*) FROM test_search_bkd_skip_threshold_t WHERE
search('v.n:5 OR v.n:6')"""
+ qt_sparse_variant """SELECT count(*) FROM test_search_bkd_skip_threshold_t
WHERE search('v.n:6')"""
+ qt_sparse_column """SELECT count(*) FROM test_search_bkd_skip_threshold_t
WHERE search('k:6')"""
+ qt_dense_topn """SELECT id FROM test_search_bkd_skip_threshold_t
+ WHERE search('v.n:5') ORDER BY id DESC LIMIT 2"""
+ qt_dense_standard_mode """SELECT count(*) FROM
test_search_bkd_skip_threshold_t
+ WHERE search('v.n:5 AND v.p:software',
'{"mode":"standard"}')"""
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]