Skip to content

cherry pick 60989:[opt](query cache) Support multiple tablets in cache key building#61527

Merged
yiguolei merged 2 commits intoapache:branch-4.1from
HappenLee:branch-4.1
Mar 20, 2026
Merged

cherry pick 60989:[opt](query cache) Support multiple tablets in cache key building#61527
yiguolei merged 2 commits intoapache:branch-4.1from
HappenLee:branch-4.1

Conversation

@HappenLee
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • 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
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@HappenLee HappenLee requested a review from yiguolei as a code owner March 19, 2026 10:47
Copilot AI review requested due to automatic review settings March 19, 2026 10:47
@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?

@HappenLee
Copy link
Copy Markdown
Contributor Author

run buildall

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR cherry-picks changes to extend BE query-cache key construction to support fragment instances that scan multiple tablets, and updates BE unit tests accordingly.

Changes:

  • Update QueryCache::build_cache_key() to accept multiple scan ranges and incorporate multiple tablet IDs into the cache key.
  • Remove the “only one scan range” restriction in CacheSourceLocalState::init() and record multiple tablet IDs in the runtime profile.
  • Adjust/extend BE unit tests to set digest and validate multi-tablet cache-key behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
be/test/pipeline/operator/query_cache_operator_test.cpp Updates operator tests to use Status::ok() and set digest for cache params.
be/test/pipeline/exec/query_cache_test.cpp Expands cache-key tests to cover multiple tablets and additional error paths.
be/src/pipeline/query_cache/query_cache.h Implements multi-tablet cache-key building logic (sorting tablet IDs, validating version/range assumptions).
be/src/pipeline/exec/cache_source_operator.cpp Removes single-scan-range restriction and records multiple tablet IDs in the profile.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +163 to +171
if (current_version != first_version) {
return Status::InternalError(
"All tablets in one instance must have the same version, plan error");
}
if (find_tablet->second != first_tablet_range) {
return Status::InternalError(
"All tablets in one instance must have the same tablet_to_range, plan "
"error");
}
Comment on lines +116 to +121
std::string digest;
try {
digest = cache_param.digest;
} catch (const std::exception&) {
return Status::InternalError("digest is invalid, plan error");
}
Comment on lines +130 to +135
std::vector<int64_t> tablet_ids;
tablet_ids.reserve(scan_ranges.size());
for (const auto& scan_range : scan_ranges) {
auto tablet_id = scan_range.scan_range.palo_scan_range.tablet_id;
tablet_ids.push_back(tablet_id);
}
Comment on lines +153 to +158
int64_t current_version = -1;
std::from_chars(scan_range_iter->scan_range.palo_scan_range.version.data(),
scan_range_iter->scan_range.palo_scan_range.version.data() +
scan_range_iter->scan_range.palo_scan_range.version.size(),
current_version);

Comment on lines +130 to +152
std::vector<int64_t> tablet_ids;
tablet_ids.reserve(scan_ranges.size());
for (const auto& scan_range : scan_ranges) {
auto tablet_id = scan_range.scan_range.palo_scan_range.tablet_id;
tablet_ids.push_back(tablet_id);
}
std::sort(tablet_ids.begin(), tablet_ids.end());

int64_t first_version = -1;
std::string first_tablet_range;
for (size_t i = 0; i < tablet_ids.size(); ++i) {
auto tablet_id = tablet_ids[i];

auto find_tablet = cache_param.tablet_to_range.find(tablet_id);
if (find_tablet == cache_param.tablet_to_range.end()) {
return Status::InternalError("Not find tablet in partition_to_tablets, plan error");
}

auto scan_range_iter =
std::find_if(scan_ranges.begin(), scan_ranges.end(),
[&tablet_id](const TScanRangeParams& range) {
return range.scan_range.palo_scan_range.tablet_id == tablet_id;
});

auto find_tablet = cache_param.tablet_to_range.find(tablet_id);
if (find_tablet == cache_param.tablet_to_range.end()) {
return Status::InternalError("Not find tablet in partition_to_tablets, plan error");
Comment on lines +143 to 146
cache_param.digest = "test_digest";
cache_param.output_slot_mapping[0] = 0;
cache_param.tablet_to_range.insert({42, "test"});
cache_param.force_refresh_query_cache = false;
@hello-stephen
Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 91.78% (67/73) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.82% (19394/36714)
Line Coverage 36.23% (181444/500766)
Region Coverage 32.67% (140103/428794)
Branch Coverage 33.69% (61031/181141)

@yiguolei
Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 91.78% (67/73) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.63% (19447/36952)
Line Coverage 36.07% (181400/502965)
Region Coverage 32.52% (140264/431377)
Branch Coverage 33.48% (61206/182813)

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 91.78% (67/73) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.10% (25708/36158)
Line Coverage 53.97% (271461/502994)
Region Coverage 51.57% (224494/435340)
Branch Coverage 52.80% (96813/183359)

@yiguolei yiguolei merged commit a824e74 into apache:branch-4.1 Mar 20, 2026
26 of 28 checks passed
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.

4 participants