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


##########
be/src/storage/segment/segment_iterator.cpp:
##########
@@ -1365,6 +1374,27 @@ Status SegmentIterator::_apply_index_expr() {
     return Status::OK();
 }
 
+void SegmentIterator::_apply_approx_index_result(VExprContext* expr_ctx) {
+    // An approximate result is a superset of candidates: rows outside the 
bitmap certainly do
+    // not match, while rows inside it may not match. So this only narrows 
_row_bitmap down to
+    // the candidate set and never records the expression in consumed_by_index 
-- it must stay in
+    // _common_expr_ctxs_push_down so that _execute_common_expr re-verifies 
each candidate row.
+    const auto* approx =
+            
expr_ctx->get_index_context()->get_approx_index_result_for_expr(expr_ctx->root().get());
+    if (approx == nullptr || approx->get_data_bitmap() == nullptr) {
+        // InvertedIndexResultBitmap allows a null data bitmap (the 
default-constructed "no
+        // result" shape). In theory the approximate map only ever holds 
results with
+        // is_empty() == false, but dereferencing a null pointer here would be 
a segfault, which
+        // costs far more than one extra null check.
+        return;
+    }
+    const uint64_t before = _row_bitmap.cardinality();
+    _row_bitmap &= *approx->get_data_bitmap();
+    const uint64_t after = _row_bitmap.cardinality();
+    _opts.stats->gram_index_candidate_rows += static_cast<int64_t>(after);

Review Comment:
   Confirmed with a red test: an approximate intersection narrowed 100 to 80 
rows, an exact intersection to 60, another approximate one to 50, and a final 
exact one to 10. The old counter reported 130 candidates although the final 
bitmap held 10. In 6b48969eb16f, `gram_index_candidate_rows` records the final 
index-stage bitmap once, while `rows_gram_index_filtered` still totals 30 for 
the two gram intersections. 
`SegmentIteratorConjunctShortCircuitTest.approx_candidates_count_final_index_bitmap_once`
 and 54 other related ASAN BE tests passed on a16d0bbe81c.



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