Skip to content

branch-4.2: [improvement](be) Skip dictionary entry bodies of non-matching terms in SNII term expansion #69600 - #69637

Merged
yiguolei merged 1 commit into
apache:branch-4.2from
airborne12:backport/69600-branch-4.2
Oct 27, 2026
Merged

yiguolei merged 1 commit into
apache:branch-4.2from
airborne12:backport/69600-branch-4.2

Conversation

@airborne12

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: None

Related PR: #69600

Problem Summary: Backport of #69600 to branch-4.2. MATCH_REGEXP, wildcard, suffix and contains patterns without a literal prefix make SniiIndexSource::expand_terms enumerate the whole dictionary of every segment. LogicalIndexReader::visit_prefix_terms passed an empty accept_key, so the body of every dictionary entry was decoded before the caller rejected almost all of them. visit_prefix_terms now takes an optional accept_key, and expand_terms passes its term test as that predicate, so a rejected term is skipped before its body is decoded. Terms are tested exactly as before, only earlier.

Measured on master's parent line (99M AgentLogs rows, 722 segments): token regexp transi.* on SNII 6028 ms -> 945 ms, V3 about 590 ms.

Branch adaptations

None. git cherry-pick -x 6979f7fa1e applied cleanly to the current branch-4.2 and touches the same four files as the original: logical_index_reader.{h,cpp}, snii_index_source.cpp and snii_query_test.cpp.

Validation

  • The same change (before the one-line clang-format fix of the declaration in logical_index_reader.h) was built and run on an earlier branch-4.2 base (ecbc5feab9): SniiB2T07Dict* and SniiRegexpQueryTest*, 31 tests passed, including the two new tests.
  • On master, Snii* passed (1373 tests) and the master CI passed all checks.
  • Not rebuilt locally on the current branch-4.2 tip; this PR's BE UT run covers that.

Release note

Faster MATCH_REGEXP / wildcard term expansion on SNII inverted indexes.

Check List (For Author)

  • Test: Unit Test
  • Behavior changed: No
  • Does this need documentation: No

🤖 Generated with Claude Code

…in SNII term expansion

### What problem does this PR solve?

Issue Number: None

Related PR: apache#69600

Problem Summary: MATCH_REGEXP, wildcard, suffix and contains patterns without a literal
prefix make SniiIndexSource::expand_terms enumerate the whole dictionary of every segment.
LogicalIndexReader::visit_prefix_terms always passed an empty accept_key to
DictBlockReader::visit_prefix_range, so the body of every dictionary entry was decoded
(decode_dict_entry_rest) and the caller then rejected almost all of them with the
required-text test and the pattern match. DictBlockReader already supports a key-only
accept_key that skips the body of a rejected term.

visit_prefix_terms now takes an optional accept_key, and expand_terms passes its term test
(required text, then pattern match) as that predicate. Terms are tested exactly as before, only
earlier, and the visitor still sees only accepted terms, so max_expansions and early stop count
the same terms. Other callers keep the default (accept all).

Measured on 99M AgentLogs rows (722 segments, tenant and status filters, token regexp
'transi.*', hot median): SNII 6028 ms -> 945 ms, V3 unchanged at about 590 ms. Patterns with a
literal prefix (for example '^transi.*') seek into the dictionary and are unchanged.

### Release note

Faster MATCH_REGEXP / wildcard term expansion on SNII inverted indexes.

### Check List (For Author)

- Test: Unit Test (SniiRegexpQueryTest.AcceptKeySkipsBodiesOfRejectedTerms, SniiRegexpQueryTest.UnanchoredRegexpDecodesOnlyMatchedBodies)
- Behavior changed: No
- Does this need documentation: No

Source-PR: apache#69600
Source-Head: 6979f7f

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@airborne12
airborne12 requested a review from yiguolei as a code owner October 26, 2026 10:52
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@airborne12

Copy link
Copy Markdown
Member Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (10/10) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.32% (34521/45234)
Line Coverage 61.22% (390267/637506)
Region Coverage 58.04% (328972/566794)
Branch Coverage 58.98% (151647/257103)

@yiguolei
yiguolei merged commit 729d605 into apache:branch-4.2 Oct 27, 2026
29 of 30 checks passed
@airborne12
airborne12 deleted the backport/69600-branch-4.2 branch October 27, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants