Repository navigation
[fix](be) Keep BM25 statistics per index for MATCH on one column - #69901
Conversation
### What problem does this PR solve? Issue Number: None Related PR: apache#69790 Problem Summary: score() over MATCH clauses that read different inverted indexes of one column fails: INDEX idx_english(name) USING INVERTED PROPERTIES("parser" = "english", ...), INDEX idx_standard(name) USING INVERTED PROPERTIES("parser" = "standard", ...) SELECT id, score() FROM t WHERE name MATCH 'apple' USING ANALYZER english AND name MATCH 'apple' USING ANALYZER standard ORDER BY score() DESC LIMIT 10; -- Scoring predicates for one field select different inverted indexes BM25 statistics are keyed by field (column unique id plus suffix path), but each index of a column holds its own terms and lengths: over Apple and apple, an index that folds case has df(apple) = 2 and one that does not has df(apple) = 1. One entry cannot serve both, so the collector refuses the query. Fix: a MATCH keeps its statistics under the field and the index id. CollectInfo records the field as indexed for opening the index, since the map key no longer is one. The readers bind their source to the real field and pass the statistics name to run_leaf, so the scorers and similarities need no change: they already look statistics up by the name they are given. Each clause now scores with the statistics of its own index, and the combined score is the sum of what each clause scores alone. SEARCH keeps its own statistics names and its rejection of two indexes on one field; only MATCH changes. A MATCH and a SEARCH on one index keep separate entries with the same values. ### Release note score() over MATCH clauses that use different inverted indexes of one column, selected with USING ANALYZER, no longer fails. ### Check List (For Author) - Test: Regression test / Unit Test / Manual test - Regression test: new test_match_score_multi_index on V2/V3/SNII, with two indexes that differ in case folding, so df(apple) is 3 in one and 1 in the other: both clauses score as they do alone, and identically on the three formats. 26 suites in inverted_index_p0 and search pass, including the multi-analyzer ones - Unit Test: the collector test that pinned the rejection now pins both entries; tests that read MATCH statistics use the new key - Behavior changed: Yes. The query above returns scores instead of an error. - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
run buildall |
|
/review |
|
Codex automated review failed and did not complete. Error: Selected model is at capacity. Please try a different model. Please inspect the workflow logs and rerun the review after the underlying issue is resolved. |
TPC-H: Total hot run time: 28484 ms |
TPC-DS: Total hot run time: 150956 ms |
ClickBench: Total hot run time: 24.37 s |
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
|
/review |
There was a problem hiding this comment.
Reviewed all 13 changed files at head 91eace3. One verified P2 finding is attached inline: MATCH's synthetic statistics key can collide with a raw SEARCH VARIANT field and reject a previously valid mixed scoring query. No existing inline findings were present; existing_blocking_comment_ids is empty.
Flow inspected: MATCH expression -> selected index -> field/index statistics -> physical CLucene or SNII source -> BM25 -> score collection. SEARCH retains its raw field identity and shares the statistics collection map.
Critical checkpoint conclusions:
- Goal: per-index terms and lengths support the intended multi-index MATCH behavior on ordinary fields. The mixed VARIANT namespace collision still needs correction.
- Scope/clarity: the producer/consumer identity change and its tests are focused; the physical field is explicitly retained.
- Concurrency: no new threads or locks. Shared tablet statistics retain their existing collection mutex, and derived scoring caches remain scanner-local. No new lock-order issue found.
- Lifecycle/initialization: schema and shared ownership retain generated index metadata and opened readers through synchronous scoring. No new dangling reference or cross-translation-unit initialization dependency found.
- Configuration: no configuration items added or changed.
- Compatibility: no on-disk, wire-format or libc dependency change. The legacy unscored CLucene overload remains available; both CLucene formats and SNII are updated.
- Thrift/protobuf: no definition or field-ID changes; release-branch ID comparison is inapplicable.
- Parallel paths: inspected MATCH/SEARCH, V2/V3/SNII, direct and inherited/field-pattern VARIANT indexes, term sets, phrases, prefixes, regexp, phrase-edge, keyword/normalizer and candidate-restricted paths. No additional verified issue.
- Conditions/errors: no new corrective branch; the key helper explains its Apple/apple example. Existing Status and exception boundaries propagate failure. Hidden-row norm callbacks use the synthetic name only as a cache label and compute through the physical source.
- Test coverage: inspected changed collector/SNII unit tests and the regression covering each analyzer alone, AND/OR sums, same-index reuse and phrase-plus-term across all three formats. A mixed colliding VARIANT-key regression is missing. Existing hidden/NULL/cache and prefix paths were also inspected.
- Test results: all 18 new regression result blocks agree with the source BM25 formula and score composition by arithmetic inspection. Test execution and result-generation provenance were not independently verified.
- Observability: existing errors and statistics diagnostics retain field/index context; no additional metric requirement identified for this local change.
- Transactions/persistence: no transaction or persistence behavior changed. Hidden rows still use the scan's read-version delete bitmap, and document counts are accumulated once per segment.
- Data writes/crashes: no write or asynchronous publication path changed. Existing ownership and failure cleanup remain intact; no additional leak or atomicity defect found.
- FE/BE variables: none added. Existing FE parsing/binding/serialization was traced to establish that the reported VARIANT path is reachable.
- Performance/memory: additional strings and entries scale with selected indexes/terms. No new large buffer, ownership leak or material algorithmic regression identified; MATCH/SEARCH can repeat statistics work for the same index under separate labels.
- Other/core invariants: committed-row visibility, version bounds, delete-bitmap alignment and nullable execution are unchanged by the identity change. No additional verified defect or unresolved candidate remains.
No additional user focus was supplied. Review converged after 2 rounds: all three reviewers returned NO_NEW_VALUABLE_FINDINGS in round 2, all risk points have evidence-backed dispositions, and the final changed-file/anchor sweep is complete. This was static inspection only: no builds, tests, benchmarks or runtime reproduction were performed, and no repository source was modified.
Review converged after 2 round(s).
| // terms and lengths under the same field, so the field alone cannot key them: over Apple and | ||
| // apple, an index that folds case has df(apple) = 2 and one that does not has df(apple) = 1. | ||
| inline std::wstring match_statistics_field(const std::wstring& field, int64_t index_id) { | ||
| return field + L"@" + std::to_wstring(index_id); |
There was a problem hiding this comment.
[P2] Keep MATCH keys disjoint from raw SEARCH fields
A synthetic MATCH key can also be a valid SEARCH field for a VARIANT subcolumn. For a scoring-capable parent index with ID 2001 and parent column UID 1, MATCH on v['a'] collects under 1.v.a@2001, exactly the raw key used by search('alpha', '{"default_field":"v.a@2001"}'). Both collectors write to the same map, but their inherited index suffixes differ (v%2Ea versus v%2Ea@2001), so validate_same_physical_index() rejects whichever predicate is collected second. This makes a previously valid mixed MATCH/SEARCH query fail when it requests score(). Use a tagged or structured identity that cannot collide with raw SEARCH fields, and cover a VARIANT key ending in @<actual-index-id>.
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
… MATCH statistics key ### What problem does this PR solve? Issue Number: None Related PR: apache#69901 Problem Summary: apache#69901 keeps the BM25 statistics of a MATCH under the field and the index id (`match_statistics_field`), so CollectionStatisticsTest.DeleteSignRowsCountWhenTheScanReturnsThem, which collects them for a MATCH and still read them under the field alone, failed on master with "Not such column 1". The test now reads them under `kMatchField`, as the other MATCH tests of the file do. ### Release note None ### Check List (For Author) - Test: Unit Test - The test fails on master without this change ("Not such column 1") and passes with it; the BM25, statistics, scanner and scan-operator unit tests pass on ASAN (258 tests). - Behavior changed: No - Does this need documentation: No
…ARCH #69790 (#70008) Backport of #69790 to branch-4.2. ### What problem does this PR solve? Issue Number: None Related PR: #69790, #69051 Problem Summary: score() of a MATCH on an untokenized (keyword) inverted index is always 0, while SEARCH on the same field scores BM25: INDEX idx_redirect (redirect) USING INVERTED -- one row ('BP') SELECT score() FROM t WHERE redirect MATCH 'BP'; -- 0 SELECT score() FROM t WHERE SEARCH('redirect:BP'); -- 0.2876821 Elasticsearch scores match, term and match_phrase on a keyword field with BM25 in query context, so the score is the idf of the whole value. #69051 (already on 4.2) made the engine score keyword postings but kept MATCH out. This makes a keyword index eligible for MATCH scoring and collects its whole value as one term, the one the reader looks up. It also carries the follow-up fixes from #69790's review: - A keyword MATCH_PHRASE drops its ` ~N` slop before collecting. - A MATCH on a non-string leaf such as `CAST(n AS STRING)` collects nothing. - A VARIANT path that a segment indexed as BKD, or does not hold, adds no statistics. This covers the BKD searcher coming from the searcher cache, and SNII. - A SNII index kind is looked up without copying the directory. ### Branch adaptations - `can_score_match` keeps 4.2's analyzed rule (support_phrase only); branch-4.2 has no lowercase-normalizer clause. - `test_omit_norms` does not exist on 4.2, so its `.out` change is dropped. The branch was cut before #69922 (the 4.2 backport of #69815) and then merged with branch-4.2 to resolve its conflict in `index_reader_helper_test.cpp`: both tests are kept, as on master. - `test_match_keyword_score` inserts its VARIANT rows as JSON strings: `parse_to_variant` in `VALUES` fails on 4.2 with a max-subcolumns conversion error. The expected output is master's file, unchanged. - **#69901 (BM25 statistics per index) is not on 4.2.** A MATCH on a keyword index and a MATCH on an analyzed index of the same column in one `score()` query (`name MATCH 'apple' USING ANALYZER english AND name MATCH 'apple' USING ANALYZER none`) now fails with "Scoring predicates for one field select different inverted indexes". Master behaved the same before #69901. Before this change, that query ran with the keyword clause scoring 0. Each clause alone scores fine. Two analyzed indexes on one column already fail this way on 4.2. Backporting #69901 lifts this. ### Validation On this branch merged with branch-4.2 c2aaed9, ASAN build: - BE UT: 1611 tests in `IndexReaderHelperTest`, `CollectionStatistics*` and `*Snii*` pass. - Regression: `test_match_keyword_score` passes against master's `.out` on V2/V3/SNII. The following also pass: `test_match_phrase_prefix_score`, `test_bm25_score`, `test_score_filter_matrix`, `test_score_filter_usage`, `test_search_score_topn_predicates`, `test_multi_analyzer_query`, `test_match_using_analyzer`, `test_single_column_multi_index` (with debug points on), `test_search_score_keyword_filters`, `test_search_score_raw_index`, `test_search_score_pattern_constant`. - Local note: the local thirdparty predates the lance-c upgrade, so `lance_reader.cpp`'s `lance_scanner_set_scalar_index_auto_selection` call was stubbed for the local build only. It is not part of this PR. ### Release note score() of MATCH / MATCH_ALL / MATCH_PHRASE on a keyword (untokenized) inverted index now returns the BM25 score of the value, the same as SEARCH, instead of 0. ### Check List (For Author) - Test: Regression test / Unit Test (see Validation) - Behavior changed: Yes. Keyword MATCH contributes its BM25 score to score() instead of 0. - Does this need documentation: No 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…om SEARCH fields apache#71123 apache#69901 keeps the BM25 statistics of a MATCH under `field@index_id`, while SEARCH keeps them under the field itself. A field is the column's unique id followed by an optional `.path`, and a VARIANT key may contain `@`, so a SEARCH on the VARIANT key `key@2004` gets the same name as a MATCH on `key` through index 2004. When one score query has both, the second collector finds the first one's entry and fails with "Scoring predicates for one field select different inverted indexes: 2004 and 2004". A MATCH name now starts with `@`: `@<index_id>@<field>`. No field starts with `@`, so the two kinds of names cannot meet, and the index id still tells two indexes of one column apart. Conflicts: be/test/storage/index/inverted/reader/collection_statistics_test.cpp The two new tests go after BuildFieldNameWithoutSuffix, whose surrounding tests differ on branch-4.2. (cherry picked from commit daa11f0) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
branch-4.2 got apache#68695, apache#69901, apache#69976, apache#70373 and apache#70883 through apache#71121, so after this merge the PR changes only what apache#71123 changes. Conflict in be/src/storage/index/inverted/common/query_info.h: branch-4.2 has the apache#69901 form of match_statistics_field(); kept the apache#71123 form, which prefixes the name with '@' so it cannot collide with a SEARCH field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
branch-4.2 now carries the CLucene-free text analysis migration (apache#71121, backporting apache#70260 to apache#70273), which conflicts with the SNII and MATCH picks on this branch. Master has both sides together, so each conflict takes master's shape where branch-4.2 has the same APIs. Conflicts: - be/src/exprs/function/match.h: take master's analyse_data_token, which has the TextTokenStream/TokenBatch parameters from apache#71121 and the size_t row and array_element_null_map parameters from apache#68661. - be/src/exprs/function/match.cpp: keep branch-4.2's VARIANT values-index helpers, compile_check and FunctionContext scope names, and take master's apache#68661 code in its stream form: StreamingPhraseMatcher, for_each_data_element_tokens and match_phrase_data_tokens taking the block's BlockTokenizer, MatchAnyTerms/MatchAllTerms in FunctionMatchAny/All, and the per-element array tokenization. - be/src/storage/index/inverted/snii/snii_index_writer.h: keep _reserve_null_docids_for_append and _null_docids_reservation (apache#66880), and drop _report_null_docids_capacity and _null_docids_charged_bytes. The lucene-based _plain_lane_token_stream/_finish_plain_lane_row (apache#70007) are gone, since apache#71121 replaced them with _stream, _batch and _report_analysis_capacity. Auto-merged files: - snii_index_writer.cpp: _reserve_null_docids_for_append calls the shared reserve_docids_for_append helper, which branch-4.2 already has (apache#69794), as master does. - function_match_test.cpp: the two phrase-position tests call analyse_data_token through data_tokens_of, which gives it a stream and a batch; data_tokens_of takes master's signature. - collection_statistics_test.cpp: SniiDocsOnlyNormalizerStillCollectsScoringStatistics reads the statistics under kMatchField, because apache#69901 (via apache#71121) keys MATCH BM25 statistics by match_statistics_field(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…om SEARCH fields #71123 (#71118) > **Update (merge of branch-4.2 at `dda37e3f019`):** #71121 brought #68695, #69901, #69976, #70373 and #70883 to `branch-4.2`. After merging `branch-4.2` into this branch, the PR changes only what #71123 changes: `query_info.h` (the `@<index_id>@<field>` statistics name) and two `CollectionStatisticsTest` cases. The one conflict, in `query_info.h`, was resolved to the #71123 form. The sections below describe the original six-commit backport. ### What problem does this PR solve? Issue Number: None Related PR: #68695, #69901, #69976, #70883, #70373, #71123 Problem Summary: Backport five merged inverted index changes to `branch-4.2`, one `git cherry-pick -x` commit per source PR, in master merge order. A sixth commit picks #71123, the master fix for the review finding on #69901 in this PR. #71123 is still open, and this pick follows any change made there. | Source | Change | Pick | |---|---|---| | #68695 | `SegmentIteratorApplyIndexExprTest`: the mock expression reports `MATCH_PRED`, so the reachable `is_virtual_slot_ref()` check reads an initialized node type. New and stronger assertions for a null index context, continued evaluation after a downgrade, and a missing index error when fallback is off. | Adapted (part of it is already on 4.2) | | #69901 | `score()` over MATCH clauses that read different inverted indexes of one column failed with "Scoring predicates for one field select different inverted indexes". BM25 statistics of a MATCH are now kept per field and index id, so each clause scores with the statistics of its own index. SEARCH is unchanged. | Ported, one test hunk N-A | | #69976 | Closing a rowset no longer depends on index compaction: the rowset level close seals every index file still open after the segments are closed. `IndexFileWriter::open()` rejects a closed writer, so an index written into a sealed file fails the compaction instead of being lost. | Adapted onto 4.2's #69936 | | #70883 | SNII sparse norms format: norms of the non-NULL rows only, read back to the same bytes. Writers still write dense norms (sparse is behind a debug point), so nothing changes on disk; a BE with this PR can read segments written by the follow-up that turns sparse norms on, so the reader should be in 4.2.0. | Ported (verbatim) | | #70373 | A wildcard that starts with `*` or `?` names its longest literal run, so CLucene and SNII skip terms that cannot match before converting them. `*cache*` over 100M rows: CPU 26.7 to 14.8 s on V3, 19.6 to 11.0 s on SNII (source PR numbers). | Ported (verbatim) | | #71123 | Follow-up to #69901. A MATCH kept its statistics under `field@index_id`, which a SEARCH on the VARIANT key `key@2004` could spell, so a score query with both failed with "Scoring predicates for one field select different inverted indexes: 2004 and 2004". A MATCH name now starts with `@` (`@<index_id>@<field>`), which no field name does. | Ported (verbatim) | ### Backport details - **#68695:** branch-4.2 already builds this test and gives the fixture its candidate rows (#68691, the 4.2 counterpart of #68695), and the mock already counts evaluations (#69292). The rest is ported; 4.2's `set_on_evaluate` hook is kept. - **#69901:** `SniiDocsOnlyNormalizerStillCollectsScoringStatistics` is not on branch-4.2; it arrives with #69199 in the open backport #70352. Its `L"1"` -> `kMatchField` update is therefore not applied here. **Whichever of this PR and #70352 merges second must switch that test's two assertions to `kMatchField`.** - **#69976:** branch-4.2 has the original fix as #69936, which closed the index files before the segments only when the rowset had index compaction, and finished them in `SegmentFlusher::close()`. This pick replaces both with the master close path: `_close_file_writers()` closes the segments and then calls `_close_inverted_index_file_writers()`, whose `begin_close()` skips writers sealed at flush. The resulting code of the three rowset files matches master after #69976. The call sites are the same on both branches (one `_segment_creator.close()` caller; the vertical writer closes its own index files; `BetaRowsetWriterV2` never calls `SegmentCreator::close()`). The file cache preload in `SegmentFlusher::close()` reads ranges of the segment file only, so moving the index close after it is safe. `test_index_compaction_non_vertical` is already on 4.2 from #69936 and identical to the source. - **#70373** is picked after #70883 as on master, so its include change applies unchanged. <details> <summary>Hunk audit (source diff per file; added and removed lines compared ignoring offsets)</summary> | Source | File | Source hunks | Result | |---|---|---|---| | #68695 | `be/test/CMakeLists.txt` | `@@ -100,7 +100,6 @@` | N-A: branch-4.2 never excluded this test from the UT build (#68691 says so) | | #68695 | `be/test/storage/segment/segment_iterator_apply_index_expr_test.cpp` | `@@ -45,9 +45,13 @@` | Ported `MATCH_PRED`; `evaluate_count()` already present from #69292 | | | | `@@ -62,11 +66,13 @@` | N-A: the evaluation counter is already present from #69292 | | | | `@@ -119,6 +125,7 @@` | N-A: `_row_bitmap.addRange` already present from #68691 | | | | `@@ -145,8 +152,11 @@`, `@@ -169,6 +179,19 @@`, `@@ -215,10 +238,12 @@` | Ported | | #69901 | 9 production files, `snii_index_reader_count_fallback_test.cpp`, both regression files | all | Ported (verbatim) | | #69901 | `be/test/storage/index/inverted/reader/collection_statistics_test.cpp` | `@@ -1507,8 +1511,8 @@ ... SniiDocsOnlyNormalizerStillCollectsScoringStati` | N-A: test absent on 4.2 (added by #69199, pending in #70352) | | | | every other hunk | Ported | | #69976 | `index_file_writer.cpp`, `index_file_writer.h`, `inverted_index_file_writer_test.cpp` | all | Ported (verbatim) | | #69976 | `be/src/storage/rowset/beta_rowset_writer.cpp` | `@@ -279,6 +279,10 @@` | Ported | | | | `@@ -973,10 +977,7 @@` | Adapted: removes 4.2's #69936 pre-close under `has_index_compaction()`; the function now equals master | | #69976 | `be/src/storage/rowset/beta_rowset_writer.h` | `@@ -87,7 +87,7 @@` | Ported | | | | `@@ -232,9 +232,9 @@` | Adapted: removes 4.2's comment "Only during compaction is this method called" (master's was "vertical compaction") | | #69976 | `be/src/storage/rowset/segment_creator.cpp` | `@@ -122,12 +122,6 @@` | Adapted: 4.2 only had `finish_close()` here; removed, as on master | | #69976 | `test_index_compaction_non_vertical.{groovy,out}` | new files | N-A: already on 4.2 from #69936, byte-identical to the source | | #70883 | all 22 files | all | Ported (verbatim) | | #70373 | all 5 files | all | Ported (verbatim) | | #71123 | `query_info.h`, `collection_statistics_test.cpp` | all | Ported (verbatim); the test hunk had a context conflict only, since the tests around `BuildFieldNameWithoutSuffix` differ on 4.2 | </details> ### Release note Fix score() over MATCH clauses that use different inverted indexes of one column, including when a SEARCH clause reads a VARIANT key that looks like a MATCH statistics name. Wildcard queries that start with `*` or `?` run faster on inverted indexes. A BE can read SNII segments with sparse norms. ### Check List (For Author) - Test - [x] Regression test - [x] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. - Behavior changed: - [ ] No. - [x] Yes. score() over MATCH clauses on different indexes of one column now succeeds; opening an index on a closed `IndexFileWriter` returns an error (no caller does after #69976). - Does this need documentation? - [x] No. - [ ] Yes. ### Validation - #71123 pick (head `add9c162f7a`): both new `CollectionStatisticsTest` cases failed before the fix and pass with it. Every suite of the 32 test files that include the headers of the statistics name, the readers and the collectors ran: 669 tests in 50 suites, all passed, no sanitizer report. The format preflight and the English check passed for this head. The runs below used ASAN builds of the first five commits (`d7b2ff7ea5a`) on top of `origin/branch-4.2` `017870e630b`. - Build: `./build.sh --be --fe -j 96` passed; the incremental `./build.sh --be -j 96` of this head passed. - Format: clang-format 16 on every changed C++ file, and the shared format preflight (clang-format and FE checkstyle against `origin/branch-4.2`): PASS. English check: PASS with 4 reviewed literal exceptions, the CJK wildcard inputs of #70373's test. - BE UT: `./run-be-ut.sh --run -j 96 --filter=<266 suites>:-S3FileWriterTest.*`, where the suites are every suite in the changed test files, in the test files that include a changed header, and in every SNII test file. 2596 tests ran: 2590 passed, 6 skipped themselves, 0 failed, no sanitizer report. All 33 test cases the five source PRs add or rename ran and passed. - `S3FileWriterTest` was in scope only because it includes `index_file_writer.h`. Locally it aborts with a SEGV in `FileCacheFactory::get_by_path` called from the `S3FileWriter` constructor, also when run alone; no picked code is on that stack. - Regression: an isolated FE and BE of this build, with `enable_debug_points = true` as in CI (the `debug_variant_*` session variables need it). 22 suites, 0 failed: - SNII: `test_storage_format_snii`, `test_storage_format_snii_norms`, `test_storage_format_snii_custom_analyzer`, `test_storage_format_snii_utf8_wildcard` - Scoring: `test_match_score_multi_index` (new, #69901), `test_bm25_score`, `test_bm25_score_variant`, `test_match_keyword_score`, `test_search_multi_analyzer_lucene`, `test_score_filter_usage` - Wildcard and SEARCH: `test_search_variant_wildcard`, `test_search_format_parity`, `test_search_dsl_syntax`, `test_search_score_pattern_constant`, `test_search_lucene_mode` - Index compaction: `test_index_compaction_non_vertical`, `_dup_keys`, `_unique_keys`, `_null`, `_empty_segments`, `_p0`, `_with_multi_index_segments` - Cloud mode was not run. ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: martin.foo838 <martin.foo838@gmail.com>
What problem does this PR solve?
Issue Number: None
Related PR: #69790
Problem Summary: score() over MATCH clauses that read different inverted
indexes of one column fails:
BM25 statistics are keyed by field (column unique id plus suffix path),
but each index of a column holds its own terms and lengths: over Apple
and apple, an index that folds case has df(apple) = 2 and one that does
not has df(apple) = 1. One entry cannot serve both, so the collector
refuses the query.
Fix: a MATCH keeps its statistics under the field and the index id.
CollectInfo records the field as indexed for opening the index, since the
map key no longer is one. The readers bind their source to the real field
and pass the statistics name to run_leaf, so the scorers and similarities
need no change: they already look statistics up by the name they are
given. Each clause now scores with the statistics of its own index, and
the combined score is the sum of what each clause scores alone.
SEARCH keeps its own statistics names and its rejection of two indexes on
one field; only MATCH changes. A MATCH and a SEARCH on one index keep
separate entries with the same values.
Release note
score() over MATCH clauses that use different inverted indexes of one
column, selected with USING ANALYZER, no longer fails.
Check List (For Author)
with two indexes that differ in case folding, so df(apple) is 3 in
one and 1 in the other: both clauses score as they do alone, and
identically on the three formats. 26 suites in inverted_index_p0
and search pass, including the multi-analyzer ones
both entries; tests that read MATCH statistics use the new key
error.
🤖 Generated with Claude Code