airborne12 opened a new pull request, #71176:
URL: https://github.com/apache/doris/pull/71176
### What problem does this PR solve?
Issue Number: None
Related PR: #67171 (source)
Problem Summary:
Pick of apache/doris#67171 to branch-4.1.
`SegmentIterator::_apply_index_expr` evaluated every pushed-down conjunct
against the inverted index and only intersected their results into
`_row_bitmap` afterwards, so an expensive conjunct such as `msg
MATCH_PHRASE_PREFIX '...'` paid its whole-segment postings and positions cost
even when a cheaper, more selective conjunct had already emptied the candidate
rows. The column predicate path and the AND inside one expression already stop
early on an empty bitmap; top-level AND conjuncts did not.
Same change as #67171: each consumed index result is intersected into
`_row_bitmap` as soon as it is produced, and the remaining conjuncts are not
evaluated against the index once the bitmap is empty. With zero surviving rows
the remaining conjuncts are consumed, virtual column MATCH projections, the ANN
range search pass and ANN TopN are skipped, and `_index_conjuncts_proved_empty`
keeps the condition cache digest so the all-false result stays cacheable. The
new profile counter `InvertedIndexConjunctsShortCircuited` reports the skipped
conjuncts.
### Details
- **Source:** apache/doris#67171, squash merge commit
40ff995f890802d5c6877b3e6f390f117d7c5629 (one parent; its diff equals the PR
diff), picked with `git cherry-pick -x`. Master has no follow-up or revert of
it.
- **Pick type:** cherry-pick with conflicts in `segment_iterator.cpp` and
`segment_iterator.h`, resolved by hand; the other five files applied without
conflict. Behavior is unchanged from the source. One existing test fixture is
adapted (below).
- **Conflicts and resolutions:**
- `segment_iterator.cpp`, start of `_apply_index_expr`: master computes
`enable_ann_index_result_cache` there for its ANN range search; branch-4.1 has
no such query option. Kept only the new short-circuit state
(`consumed_by_index`, `bitmap_exhausted`, `considered_conjuncts`).
- `segment_iterator.cpp`, virtual column loop: on branch-4.1 the loop is
inside a block that hides `collection_similarity` while projections run, so
they add no BM25 scores. Kept that block and added the empty-bitmap `break` at
the top of its loop.
- `segment_iterator.h`: the source adds `_index_conjuncts_proved_empty`
next to master's COUNT fast path fields, which branch-4.1 does not have. Added
it after `_index_query_context`, without those fields.
- **Adapted without conflict:** the ANN range search hunk keeps branch-4.1's
`evaluate_ann_range_search` call and statistics; `_apply_ann_topn_predicate`
gets the empty-bitmap early return before it reads the ANN source column.
- **New unit test `segment_iterator_conjunct_short_circuit_test.cpp`**,
adapted to branch-4.1 APIs, following this branch's
`segment_iterator_apply_index_expr_test.cpp`: the read schema is a `Schema`
with column IDs (master has `ReadSchema`), `IndexExecContext` takes the column
ID list first, and the mock overrides branch-4.1's
`VExpr::evaluate_ann_range_search` signature (with `idx_to_cid`, without the
result cache flag). The test cases and their assertions are unchanged.
- **Existing test fixture, `segment_iterator_apply_index_expr_test.cpp`:**
`SegmentIteratorApplyIndexExprTest` leaves the candidate row bitmap empty, so
with this pick `_apply_index_expr` skips the virtual column expressions those
tests check, and 8 of its 12 cases failed (for example,
`inverted_index_downgrade_count` stayed 0). The fixture now starts with all 100
segment rows, as master's fixture does since #68695, which fixed the same
interaction there. The test cases are unchanged. #68695's other change, the
`MATCH_PRED` node type of the mock, is for a master-only
`is_virtual_slot_ref()` check and is not needed here.
Hunk audit against #67171:
| File | Source hunk | Status |
| --- | --- | --- |
| be/src/exec/operator/olap_scan_operator.cpp | `@@ -290,6 +290,8 @@` |
Ported (verbatim) |
| be/src/exec/operator/olap_scan_operator.h | `@@ -265,6 +265,7 @@` | Ported
(verbatim) |
| be/src/exec/scan/olap_scanner.cpp | `@@ -881,6 +881,8 @@` | Ported
(verbatim) |
| be/src/storage/olap_common.h | `@@ -325,6 +325,9 @@` | Ported (verbatim) |
| be/src/storage/segment/segment_iterator.cpp | `@@ -858,7 +858,9 @@`
condition cache digest | Ported |
| be/src/storage/segment/segment_iterator.cpp | `@@ -925,6 +927,13 @@` ANN
TopN early return | Ported |
| be/src/storage/segment/segment_iterator.cpp | `@@ -1237,7 +1246,23 @@`
short-circuit state and check | Adapted: without master's
`enable_ann_index_result_cache` |
| be/src/storage/segment/segment_iterator.cpp | `@@ -1249,12 +1274,25 @@`
progressive intersection; virtual column skip | Adapted: skip placed inside
branch-4.1's similarity-hiding block |
| be/src/storage/segment/segment_iterator.cpp | `@@ -1272,6 +1310,13 @@` ANN
range search skip | Ported |
| be/src/storage/segment/segment_iterator.cpp | `@@ -1302,6 +1347,22 @@`
consume or erase after the ANN pass | Ported |
| be/src/storage/segment/segment_iterator.h | `@@ -484,6 +484,14 @@`
`_index_conjuncts_proved_empty` | Adapted: placed without master's COUNT fast
path fields |
| be/test/storage/segment/segment_iterator_conjunct_short_circuit_test.cpp |
`@@ -0,0 +1,327 @@` new test | Adapted: branch-4.1 `Schema`, `IndexExecContext`
and `evaluate_ann_range_search` APIs |
| be/test/storage/segment/segment_iterator_apply_index_expr_test.cpp | not
in #67171 | Added for branch-4.1: fixture row bitmap from #68695 |
### Release note
Inverted index: once earlier pushed-down conjuncts empty the candidate row
bitmap, remaining conjuncts (e.g. expensive MATCH_PHRASE_PREFIX) are no longer
evaluated against the index.
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
Local results on this commit, ASAN:
- `./build.sh --be`: passed.
- `./run-be-ut.sh --run --filter='SegmentIterator*'`: 26 tests from 6
suites, all passed, no sanitizer report. That covers the 7 new
`SegmentIteratorConjunctShortCircuitTest` cases and the existing
`SegmentIteratorApplyIndexExprTest` (12), `SegmentIteratorExprZonemapTest` (3),
`SegmentIteratorScoreCommonExprTest` (2), `SegmentIteratorNoNeedReadDataTest`
(1) and `SegmentIteratorVirtualColumnTest` (1). Before the fixture change, the
same run failed 8 `SegmentIteratorApplyIndexExprTest` cases, as described above.
- clang-format 16: the changed files need no change. This branch has no
`run-clang-tidy.sh` or `check-build-hygiene.sh`.
- Not run locally: regression tests.
- Behavior changed:
- [ ] No.
- [x] Yes. Index results are intersected as they are produced, before
the ANN range search pass; conjuncts skipped after the bitmap is empty are not
evaluated against the index. Query results are the same.
- Does this need documentation?
- [x] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should
merge into -->
🤖 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]