hello-stephen commented on code in PR #71215:
URL: https://github.com/apache/doris/pull/71215#discussion_r4808640850


##########
be/src/exprs/vmatch_predicate.cpp:
##########
@@ -291,8 +295,16 @@ 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 match as the index of their tablet would, inside the segment and 
in the scanner alike.
+    // Above the scanner the tablet is unknown, and the rows keep the CLucene 
element spacing.
+    auto* fn_context = context->fn_context(_fn_context_index);
+    const bool snii_rows =
+            context->inverted_index_storage_format() == 
InvertedIndexStorageFormatPB::SNII;
+    
fn_context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,

Review Comment:
   [P2] Don’t mutate a cached MATCH context during point-query execution
   
   `PointQueryExecutor::_output_data()` sends the cached `Reusable`’s output 
contexts directly to `VMysqlResultWriter`. If FE times out and re-executes the 
same prepared statement on the same BE, the earlier RPC can still run in 
`_light_work_pool` because the worker does not check cancellation. Both cache 
hits can therefore reach this assignment on the same `FunctionContext`. 
`THREAD_LOCAL` is an ordinary `shared_ptr` member of that object, not actual 
thread-local storage. Reassigning it here races with the other evaluation’s 
assignment or read even when both choose the same analyzer. Bind the analyzer 
before publishing a shared context, or keep execution state request-local. The 
new sequential V2/SNII cache test does not cover overlapping same-format 
requests.



##########
be/src/service/point_query_executor.cpp:
##########
@@ -343,11 +347,15 @@ Status PointQueryExecutor::init(const 
PTabletKeyLookupRequest* request,
     const auto& lc_time_names = request->lc_time_names();
     _binary_row_format = request->is_binary_row();
     _tablet = DORIS_TRY(ExecEnv::get_tablet(request->tablet_id()));
-    // SET time_zone or lc_time_names can reuse the same prepared UUID, but 
expressions
-    // capture these settings at open (e.g. monthname changes from zh_CN to 
en_US).
-    // Rebuild on changes; existing requests retain their original contexts.
+    auto tablet_schema = _tablet->tablet_schema();
+    // SET time_zone or lc_time_names can reuse the same prepared UUID, and 
partitions created
+    // under different inverted index storage formats (e.g. V2 vs SNII) can 
also share it.
+    // Expressions capture timezone/locale at open and read the tablet's index 
format from
+    // VExprContext, so rebuild on changes while existing requests retain 
their original contexts.
     if (cache_handle != nullptr &&
-        cache_handle->matches_timezone_and_locale(timezone, lc_time_names)) {
+        cache_handle->matches_timezone_and_locale(timezone, lc_time_names) &&
+        cache_handle->inverted_index_storage_format() ==

Review Comment:
   [P3] Preserve prepared cache hits for format-independent expressions
   
   A prepared `SELECT v FROM t WHERE k = ?` on a row-store MoW table now misses 
whenever successive keys alternate between V2 and SNII partitions served by the 
same BE, even though it does not evaluate MATCH. The cache holds one `Reusable` 
per UUID, so every switch deserializes and reopens the context and replaces the 
previous entry. With lightweight lookup enabled, every switch also adds a 
resend RPC. Restrict format-based cache selection to contexts whose results 
depend on it, or supply the format in request-local state without rebuilding 
the cached plan.



##########
be/src/exprs/function/match.cpp:
##########
@@ -446,12 +444,15 @@ bool match_phrase_data_tokens(const FunctionMatchBase& 
function, const std::stri
                               const ColumnUInt8::Container* 
array_element_null_map,
                               StreamingPhraseMatcher& matcher) {
     matcher.reset_row();
+    const bool analyzed =
+            analyzer_ctx && analyzer_ctx->requires_analysis() && 
analyzer_ctx->analyzer != nullptr;
+    // Positions follow the index this evaluation stands in for, including its 
gap between
+    // analyzed elements.
+    const int64_t element_gap = analyzed ? 
analyzer_ctx->array_element_position_gap : 0;

Review Comment:
   [P2] Keep unindexed ARRAY phrases independent of the tablet’s index format
   
   Take a cloud duplicate-key table `t(k DATE, a ARRAY<STRING>)` with no 
inverted indexes. Use the partition rollout from 
`test_partition_cloud_inverted_index_storage_format_rollout.groovy` to keep one 
V2 partition and add an SNII partition. Insert `a = ['hello', 'world']` in both 
and enable `enable_match_without_inverted_index`.
   
   ```sql
   SELECT k, NOT(a MATCH_PHRASE 'hello world') AS n
   FROM t
   ```
   
   `AnalyzerSelector` defaults to English when there is no index, so both rows 
use analyzed fallback in the scanner projection. The base returns `n = false` 
for both rows. The new gap leaves that result unchanged on V2 but makes it 
`true` on SNII, even though neither partition has an index. A computed 
`array(v, 'world')` that borrows the analyzer from a scalar index has the same 
problem. Apply the storage-specific gap only when the bound MATCH operand 
corresponds to an analyzed ARRAY index, and add a SQL regression for the 
unindexed case.



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