airborne12 commented on code in PR #71215:
URL: https://github.com/apache/doris/pull/71215#discussion_r4763731171


##########
be/src/exprs/vmatch_predicate.cpp:
##########
@@ -247,8 +251,19 @@ Status VMatchPredicate::execute_column_impl(VExprContext* 
context, const Block*
     // prepare a column to save result
     temp_block.insert({nullptr, _data_type, _expr_name});
 
-    RETURN_IF_ERROR(_function->execute(context->fn_context(_fn_context_index), 
temp_block,
-                                       arguments, num_columns_without_result, 
temp_block.rows()));
+    // Rows of a segment must match as that segment's index would. The format 
is known only in
+    // the storage layer; elsewhere the rows keep the CLucene element spacing.
+    auto* fn_context = context->fn_context(_fn_context_index);
+    const auto index_context = context->get_index_context();
+    const bool snii_segment =
+            index_context != nullptr && index_context->segment() != nullptr &&
+            
index_context->segment()->tablet_schema()->get_inverted_index_storage_format() 
==
+                    InvertedIndexStorageFormatPB::SNII;
+    
fn_context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
+                                   snii_segment ? _snii_analyzer_ctx : 
_analyzer_ctx);

Review Comment:
   Confirmed and fixed in 2639cd3f78c.
   
   On e3c8806ac24 the two evaluations differ as you describe. The virtual 
column's context is cloned in 
`SegmentIterator::_construct_compound_expr_context` with an `IndexExecContext` 
that holds the segment, so it got the SNII gap. `NOT(MATCH)` stays in 
`Scanner::_projections`, which have no index context, so it got none. 
Scanner-level conjuncts (merge-on-read and AGG tables, or conjuncts re-cloned 
when a runtime filter arrives late) had the same gap problem. A BE UT that runs 
MATCH_PHRASE in an `OlapScanner`'s conjunct and projection on an SNII tablet 
failed on e3c8806ac24: `['hello','world']` matched.
   
   The spacing now follows the index format of the tablet the rows come from. 
Whether a segment context exists no longer matters:
   - `VExprContext` carries the inverted index storage format of the tablet 
whose rows it evaluates.
   - `SegmentIterator` sets it to the segment's format on the pushed-down and 
virtual-column contexts it clones.
   - `OlapScanner` sets it to its tablet's format on its conjuncts, projections 
and intermediate projections. It sets it again when a late runtime filter 
re-clones the conjuncts.
   - `VMatchPredicate` reads only this value.
   
   A tablet keeps the format it was created with: 
`partition_inverted_index_storage_format` applies only to new partitions. So 
both values agree for every row. In your example, `m` and `n` now come out 
`(false, true)` on SNII and `(true, false)` on CLucene, whether the index is 
used or not.
   
   Not covered: an operator above the scan, such as a projection or filter 
after a join or aggregation, gets rows from several tablets, and those can be 
in different formats under the partition rollout. It has no single format to 
follow, so it keeps the CLucene spacing, as before this PR. A MATCH the 
optimizer leaves there can still disagree with one evaluated in the scan of an 
SNII tablet. The shapes `PushDownMatchProjectionAsVirtualColumn` produces 
(`Project -> OlapScan` and `Project -> Filter -> OlapScan`, wrapped or not) all 
evaluate in the scanner or the segment and are covered.
   
   Tests:
   - `ScannerLateArrivalRfTest.olap_scanner_match_follows_tablet_index_format` 
(the reproduction above; it passes now).
   - `ScannerLateArrivalRfTest.late_arrival_conjuncts_keep_tablet_index_format`.
   - `SegmentIteratorVirtualColumnTest.ExprContextsCarryTheSegmentIndexFormat`.
   - `ArrayPhraseIndexParityTest` now also evaluates the rows in a context like 
the scanner's (format only, no index) and compares them with the real SNII and 
V2 index files.
   
   No SQL regression: since #39062, FE rejects a parser on an ARRAY index 
(`INVERTED index with parser: english is not supported for array column`), so 
no suite can create the table in your example on current versions.
   



-- 
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]

Reply via email to