airborne12 opened a new pull request, #71022:
URL: https://github.com/apache/doris/pull/71022
### Background
`score()` ranks rows by BM25 and needs every scored predicate answered by
the inverted index. Since #69053, an AND/OR/NOT whose branches produced scores
fails when any branch has no index result, so scores cannot leak from a branch
evaluated row by row. A VARIANT column stores a path only in segments whose
rows contain it, so `v.content` can be missing from a whole segment. SEARCH
(#69347) proves such absence from the segment's VARIANT metadata and treats the
path as matching nothing; MATCH did not.
### What problem does this PR solve?
Issue Number: None
Related PR: #69053 (added the incomplete-evaluation error), #69347 (SEARCH's
absent-path proof, reused here)
PR Type: Bugfix
Problem Summary:
`score()` over MATCH predicates combined with AND/OR/NOT on VARIANT paths
fails when some segment does not store one of the paths, although `search()`
over the same paths works. This PR moves #69347's absence proof into one shared
check and lets MATCH use it: on a path the segment provably does not store,
MATCH is NULL on every row, which the index now answers exactly. Paths that are
stored without an index keep row evaluation. About half of the diff is tests.
```sql
-- v is a VARIANT with an english inverted index; each INSERT writes one
segment
INSERT INTO t VALUES (1, '{"title":"apple search guide","content":"search
database engine"}'), ...;
INSERT INTO t VALUES (3, '{"title":"apple archive"}'), (4,
'{"title":"database manual"}');
INSERT INTO t VALUES (5, '{"content":"apple search"}'), (6,
'{"content":"database analytics"}');
SELECT id, score() FROM t WHERE v['title'] MATCH_ANY 'apple' OR v['content']
MATCH_ANY 'search'
ORDER BY score() DESC LIMIT 100;
```
| | Result |
| --- | --- |
| Before | `[E-6001]Cannot score a compound predicate with incomplete index
evaluation` |
| After | ids 9, 1, 3, 5 with 1.6659, 1.3164, 0.833, 0.833: the same as
`search('v.title:apple OR v.content:search')` |
### Details
- **Change map:** about 380 changed lines: 113 added and 43 removed in
production code, of which 51 are #69347's proof moved from `vsearch.cpp` to
`vexpr_context.cpp`; the MATCH change is 48 lines in
`vmatch_predicate.{h,cpp}`; 222 lines are tests (BE UT 140, regression suite 63
and its .out 19).
- **Frequency:** Always, when `score()` ranks a scored AND/OR/NOT of MATCH
predicates on VARIANT paths and at least one segment does not store one of the
paths, as in the example above.
- **Root cause:** in a segment without the path there is no index iterator
for it, so `VExpr::_evaluate_inverted_index` returns OK without a result and
the MATCH falls back to row evaluation.
`VCompoundPred::evaluate_inverted_index` then sees an incomplete branch next to
a scored one and returns the error added by #69053. SEARCH does not fail
because `verify_missing_variant_path` (#69347) proves the path absent and
answers it as matching nothing.
- **Why existing tests missed it:** BE: `vcompound_pred_score_test.cpp`
(#69053) checks the error with mocked incomplete branches, and
`test_search_distinguishes_unindexed_historical_variant_path` (#69347) covers
SEARCH only; no unit test evaluated MATCH on a VARIANT path missing from a
segment. Regression: `search/test_search_score_boolean_branches` (#69053)
scores MATCH OR on ordinary columns written in one segment, and
`inverted_index_p0/test_bm25_score_variant` scores a single MATCH on one-insert
VARIANT tables; none had segments that miss one branch's path.
- **Fix:** `IndexExecContext::is_variant_path_absent` now holds #69347's
proof unchanged, and SEARCH keeps its contract and messages on top of it.
`VMatchPredicate` calls it when its own index evaluation left no result for an
extracted VARIANT path without an index iterator, and stores an exact result:
no matching rows, every row NULL. That is what MATCH on NULL gives, so NOT and
AND/OR keep their three-valued results. The fix sits in the MATCH predicate
because only the predicate knows its NULL result; the compound scoring check
stays as it is.
- **Other paths and branches:** SEARCH: not affected, it already had the
proof and now shares it. Comparison, IN, and IS NULL predicates on an absent
VARIANT path keep their row-level fallback (their results on NULL differ per
function), so combined with a scored MATCH under `score()` they still fail with
the same error; not fixed here. MATCH on the VARIANT root (values index): not
affected, the root is never absent. branch-4.1 and branch-4.2 have the bug:
both carry #69053 (#69160, #69265) and #69347 (#69603, #69361); a backport
needs to adapt the moved proof to their root-reader lookup by column uid.
- **Behavior change:** without `score()`, a MATCH on a VARIANT path that a
segment does not store is now answered by the inverted index instead of row
evaluation. The rows are the same (checked against row evaluation with
`enable_inverted_index_query=false`), but such segments now count in the
profile's inverted-index counters, and the scan may skip reading the all-NULL
path.
### Testing
All local, ASAN, single BE.
- BE UT `test_match_returns_null_rows_for_absent_variant_path` (new): MATCH
on an absent path of a real unindexed segment gets {no hits, 2 NULL rows}, also
under NOT. Fails on the base c7747fa64cb (no index result) and with only the
MATCH hook disabled; passes with the fix.
- BE UT `test_match_reads_rows_for_unindexed_variant_path` (new): a stored
but unindexed path keeps row evaluation.
`test_search_distinguishes_unindexed_historical_variant_path` (#69347) passes
before and after.
- BE UT `VariantColumnWriterReaderTest.*`, `VSearch*`, `*VMatchPredicate*`,
`VCompoundPredScoreTest.*`, `*FunctionSearch*`: 273 passed, 2 skipped
(NestedGroup not built). A wider run (2353 tests) also had 3 failures this
change does not touch: `ValuesIndexExistsOnlyInSniiSegments/{0,2}` (#69761's
test expects INVERTED_INDEX_BYPASS, which #70788 changed) and
`AsyncCacheWriteManagerTest` (file cache).
- Regression `search/test_search_score_boolean_branches` (new VARIANT case):
fails on the base at `variant_match_or` with E-6001, passes with the fix, fails
again with only the hook disabled. Its .out equals `search()` for the OR query
and the hand-derived rows 1, 2, 3, 6, 9 for the NOT query; row evaluation
(index disabled) gives the same rows.
- Regression: all 46 `search/` suites and 7 VARIANT/MATCH score suites
(`test_bm25_score_variant`, `test_variant_values_index_query`, ...) pass.
- clang-format, `check-format.sh`, `check-build-hygiene.sh`, clang-tidy on
changed lines: clean.
### Notes for Reviewers
- `is_variant_path_absent` is #69347's `verify_missing_variant_path` body
moved verbatim, except that it reports the answer instead of returning SEARCH's
error; start with `vsearch.cpp` to see the move, then
`VMatchPredicate::_evaluate_absent_variant_path`.
- The shared check asserts a segment, so both callers handle a missing one
first; many unit tests build an `IndexExecContext` without a segment.
- The regression case pins doc mode off and an unlimited subcolumn count,
like `test_search_score_cache`, because p0 randomizes VARIANT defaults.
### Release note
Fixed the error "Cannot score a compound predicate with incomplete index
evaluation" when `score()` ranks rows filtered by MATCH predicates on VARIANT
paths combined with AND, OR, or NOT, and some data does not contain one of the
paths.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified: not run in cloud mode or with
p0's fuzzy session variables (CI p0 and cloud_p0 run the suite)
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: code, tests, this description
- Human review: not stated
- Prompts: The author asked whether the reported score() error exists on
branch-4.2 and master, why search() does not fail on the same data, and which
PR added SEARCH's absent-path proof; then asked to reuse that check in the
MATCH path with TDD and open a fix PR, reusing code rather than duplicating it.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]