airborne12 opened a new pull request, #71215:
URL: https://github.com/apache/doris/pull/71215
### Background
An inverted index on an ARRAY<STRING> column indexes the analyzed elements
of a row as one
document, and a phrase query (MATCH_PHRASE, MATCH_PHRASE_PREFIX,
MATCH_PHRASE_EDGE) matches only
adjacent positions. CLucene formats (V1/V2/V3) write the elements back to
back, so a phrase can
cross elements; SNII leaves one empty position after every element
(`SniiIndexColumnWriter::add_array_values`), so it cannot. When a segment
has no index for the
column, BE evaluates MATCH by rows, and since #68661 that evaluation spaces
elements like CLucene.
### What problem does this PR solve?
Issue Number: None
Related PR: #68661 (added the row-evaluation positions across array
elements), #39062 (made FE reject a parser on ARRAY indexes), #70352
(branch-4.2 backport of #68661 where review found this)
PR Type: Bugfix
Problem Summary:
For an analyzed SNII index on an ARRAY column, row evaluation and the index
disagree on a phrase
that crosses two elements: for `['hello', 'world']`, `MATCH_PHRASE 'hello
world'` returns the row
when the segment is read by rows but not on the SNII index
(MATCH_PHRASE_PREFIX and
MATCH_PHRASE_EDGE too). The answer then depends on whether each segment has
its index. This PR
makes row evaluation space the elements of SNII segments as SNII does;
CLucene segments are
unchanged.
### Details
- **Change map:** 31 lines of production code in 4 files; 287 lines are the
new BE unit test.
- **Frequency:** Not observed; found by code review on #70352 and reproduced
in a BE unit test with real SNII and V2 index files. Since #39062 FE rejects a
parser, analyzer, or normalizer on ARRAY columns, and VARIANT array subcolumns
inherit their index without one, so indexes created by current versions cannot
trigger it. It triggers for an ARRAY index created with a parser before #39062
once its partitions are written in SNII through the partition storage format
rollout (`partition_inverted_index_storage_format = "SNII"`).
- **Root cause:** `match_phrase_data_tokens` in `match.cpp` moved the
position base by the last token position of each element, as CLucene does. SNII
moves it one position further per element, also for an element without tokens,
so row evaluation made SNII's non-adjacent terms adjacent.
- **Why existing tests missed it:** The array phrase cases in
`function_match_test.cpp` (from #68661) check row evaluation with a context
that does not know the storage format and expect CLucene spacing;
`snii_golden_corpus_test.cpp` checks only the SNII index. No unit test compared
the two. No regression suite can create an analyzed ARRAY index on current
versions.
- **Fix:** `VMatchPredicate::execute_column_impl` reads the storage format
of the segment it evaluates (from the expression's `IndexExecContext`) and
gives row evaluation an analyzer context whose new `array_element_position_gap`
is 1 for SNII and 0 otherwise; `match_phrase_data_tokens` adds it after every
analyzed element. The format is taken per segment rather than from FE because
FE keeps the storage format per partition. The SNII writer is unchanged, so
existing segments keep their meaning.
- **Behavior change:** row evaluation on SNII segments no longer matches a
phrase across two ARRAY elements; CLucene segments and every other MATCH
function are unchanged.
- **Other paths and branches:**
- MATCH_PHRASE_PREFIX and MATCH_PHRASE_EDGE share the positions: fixed and
tested. MATCH_ANY, MATCH_ALL and MATCH_REGEXP ignore positions. Keyword
elements get no gap, as SNII writes them at consecutive positions.
- MATCH_PHRASE with slop (`'hello world ~1'`): still to fix, separately.
Row evaluation of analyzed columns does not parse the slop on any format and
returns no row where the SNII and V2 indexes do. This predates this PR.
- Row evaluation outside the storage layer (scanner-level conjuncts of AGG
and merge-on-read tables, or MATCH above the scan) has no segment and keeps
CLucene spacing; none of these can have an analyzed SNII ARRAY index.
- Branches: master has the bug. branch-4.2 has SNII but not #68661; #70352
brings it, so pick this with it. branch-4.1 and branch-4.0 have no SNII.
### Testing
- New BE UT `ArrayPhraseIndexParityTest` (`vmatch_predicate_test.cpp`)
writes the same arrays (a phrase across elements, inside one element, and
across an empty or NULL element) into an SNII and a V2 index, then runs
`VMatchPredicate` by rows and on the index for MATCH_PHRASE,
MATCH_PHRASE_PREFIX and MATCH_PHRASE_EDGE. Before the fix the SNII case fails
for all three (rows `{1,1,1,1,1}`, index `{0,1,0,0,0}`) and the V2 case passes;
after it both pass.
- `run-be-ut.sh` with FunctionMatchTest, VMatchPredicateTest,
ArrayPhraseIndexParityTest, Snii*, DorisSnii* and InvertedIndexArrayTest: 1561
tests passed (ASAN, local).
- `./build.sh --be --fe` (ASAN), `clang-format.sh`,
`check-build-hygiene.sh`: pass. `run-clang-tidy.sh`: no findings on changed
lines, though the local clang-tidy could not fully analyze the files.
- No regression case: FE rejects an analyzed ARRAY index on master, so a
suite cannot reach this path.
### Release note
On SNII partitions of an ARRAY column whose inverted index has a parser
(only possible for indexes created before #39062), MATCH_PHRASE,
MATCH_PHRASE_PREFIX and MATCH_PHRASE_EDGE without the index no longer match a
phrase across two array elements, which agrees with the SNII index.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified: no end-to-end regression case,
because current FE cannot create the analyzed ARRAY index that triggers it;
covered by a BE unit test with real SNII and V2 index files.
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: code, tests, this description
- Human review: Pending author review
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]