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


##########
be/src/exprs/vmatch_predicate.cpp:
##########
@@ -204,6 +210,44 @@ Status 
VMatchPredicate::evaluate_inverted_index(VExprContext* context, uint32_t
     return status;
 }
 
+// A MATCH on a VARIANT path that this segment does not store is NULL on every 
row, which the
+// index can answer exactly. Without that answer the MATCH falls back to row 
evaluation, and
+// score() then rejects an AND/OR whose other branches were scored. For 
example, in a segment
+// written from {"title":"apple archive"}, `v['content'] MATCH 'search'` is 
answered here, so
+// `v['title'] MATCH 'apple' OR v['content'] MATCH 'search'` can still score 
the title branch.
+Status VMatchPredicate::_evaluate_absent_variant_path(IndexExecContext& 
index_context,
+                                                      uint32_t 
segment_num_rows) {
+    // The planner reads `v['content']` as a path slot, usually under a cast 
to the MATCH type.
+    // Without a segment there is no VARIANT metadata to prove the path absent 
from.
+    const auto input = expr_without_cast(get_child(0));
+    if (!input->is_slot_ref() || index_context.segment() == nullptr) {
+        return Status::OK();
+    }
+    // A path with an index iterator has already been answered or declined by 
its index, and
+    // only an extracted VARIANT path can be absent from a segment.
+    const int column_id = assert_cast<const 
VSlotRef*>(input.get())->column_id();
+    const auto& column = *index_context.read_schema()->column(column_id);
+    if (index_context.get_inverted_index_iterator(column_id) != nullptr ||
+        !column.is_extracted_column()) {
+        return Status::OK();
+    }
+    bool absent = false;
+    RETURN_IF_ERROR(index_context.is_variant_path_absent(
+            column_id, column.path_info_ptr()->copy_pop_front(), &absent));
+    // A path that is stored but has no index, such as one in the sparse 
column, still needs
+    // row evaluation.
+    if (!absent) {
+        return Status::OK();
+    }
+    auto null_rows = std::make_shared<roaring::Roaring>();
+    null_rows->addRange(0, segment_num_rows);
+    index_context.set_index_result_for_expr(

Review Comment:
   Confirmed and fixed in fd239162100. The AND early exit (from #38908) skipped 
the remaining branches as soon as no row was TRUE, keeping NULL rows that a 
later FALSE branch turns FALSE. This is also reachable without VARIANT, for any 
nullable indexed column. `VCompoundPred` now stops an AND only when no row is 
TRUE or NULL. Tests: 
`VCompoundPredScoreTest.AndWithOnlyNullRowsLeftEvaluatesLaterBranches` (fails 
without the change), and regression `nullable_not_and` (3 -> 2,3) and 
`variant_not_and_absent` (2,6 -> 2,4,6) with `SIMPLIFY_NOT_EXPR` disabled; both 
now match row evaluation.



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