Skip to content

[test]#62841

Closed
linrrzqqq wants to merge 1 commit into
apache:masterfrom
linrrzqqq:opt-bitmap
Closed

[test]#62841
linrrzqqq wants to merge 1 commit into
apache:masterfrom
linrrzqqq:opt-bitmap

Conversation

@linrrzqqq

Copy link
Copy Markdown
Collaborator

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

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

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (33/33) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 66.67% (22/33) 🎉
Increment coverage report
Complete coverage report

@linrrzqqq linrrzqqq force-pushed the opt-bitmap branch 2 times, most recently from 1604506 to df06f67 Compare April 27, 2026 02:01
@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (33/33) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.34% (20414/38271)
Line Coverage 36.90% (192425/521523)
Region Coverage 33.23% (149783/450749)
Branch Coverage 34.34% (65503/190764)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 0.75% (3/399) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.24% (23729/37522)
Line Coverage 46.68% (242989/520562)
Region Coverage 43.77% (199274/455321)
Branch Coverage 44.85% (85990/191747)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 25.29% (22/87) 🎉
Increment coverage report
Complete coverage report

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (33/33) 🎉
Increment coverage report
Complete coverage report

@wyxxxcat

Copy link
Copy Markdown
Collaborator

/review

1 similar comment
@wyxxxcat

Copy link
Copy Markdown
Collaborator

/review

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@zclllyybb zclllyybb requested a review from Copilot April 29, 2026 09:21
@zclllyybb

Copy link
Copy Markdown
Contributor

/review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates bitmap count handling across FE (Nereids) and BE by rewriting bitmap_count(bitmap_op(...)) into dedicated bitmap_*_count(...) functions, and aligning nullability/NULL-handling semantics for bitmap count functions.

Changes:

  • Add a Nereids expression rewrite rule to convert bitmap_count(bitmap_and/or/xor/not/and_not(...)) into the corresponding bitmap_*_count(...) expression, plus a unit test.
  • Mark FE bitmap *_count scalar functions as always-not-nullable via AlwaysNotNullable and remove per-child nullable inference.
  • Adjust BE bitmap count implementations and tests to treat results as non-nullable (with NULL inputs producing 0 / identity behavior), and refactor BitmapValue internals (SET representation + new helpers used by bitmap predicates).

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/BitmapCountToBitmapOpCountTest.java New unit test for the bitmap_count → bitmap_*_count rewrite rule.
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapXorCount.java Switch to AlwaysNotNullable; remove nullable derivation from children.
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapOrCount.java Switch to AlwaysNotNullable; remove nullable derivation from children.
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndNotCountAlias.java Switch to AlwaysNotNullable; remove nullable derivation from children.
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndNotCount.java Switch to AlwaysNotNullable; remove nullable derivation from children.
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndCount.java Switch to AlwaysNotNullable; remove nullable derivation from children.
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/BitmapCountToBitmapOpCount.java New expression rewrite rule implementing bitmap_count(bitmap_op) → bitmap_op_count.
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionRuleType.java Add rule enum BITMAP_COUNT_TO_BITMAP_OP_COUNT.
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionOptimization.java Register the new rewrite rule in the optimization pipeline.
be/test/exprs/function/function_bitmap_test.cpp Update bitmap_*_count tests to expect non-nullable results.
be/src/exprs/function/function_bitmap_variadic.cpp Make bitmap_*_count return types non-nullable; add optimized binary path that handles const/nullable without full expansion.
be/src/exprs/function/function_bitmap_min_or_max.h Refactor result materialization to write directly to resized result buffers.
be/src/exprs/function/function_bitmap.cpp Simplify bitmap_and_not_count computation and use new BitmapValue helpers for bitmap_has_any/all; adjust null-to-zero handling.
be/src/core/value/bitmap_value.h Replace SET backing container, add intersects/contains_all, and refactor set/bitmap transitions + (de)serialization logic.

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

Comment on lines 2174 to +2184
case BitmapTypeCode::SET: {
_type = SET;
++src;
uint8_t count = *src;
++src;
if (count > SET_TYPE_THRESHOLD) {
throw Exception(ErrorCode::INTERNAL_ERROR,
"bitmap value with incorrect set count, count: {}", count);
}
_set.reserve(count);
for (uint8_t i = 0; i != count; ++i, src += sizeof(uint64_t)) {
_set.insert(decode_fixed64_le(reinterpret_cast<const uint8_t*>(src)));
}
if (_set.size() != count) {
throw Exception(ErrorCode::INTERNAL_ERROR,
"bitmap value with incorrect set count, count: {}, set size: {}",
count, _set.size());
}
_set.read(src, count);
src += sizeof(uint64_t) * count;
Comment on lines +40 to +46
/**
* Rewrite bitmap_count(bitmap_xxx(...)) to bitmap_xxx_count(...).
*/
public class BitmapCountToBitmapOpCount implements ExpressionPatternRuleFactory {

public static final BitmapCountToBitmapOpCount INSTANCE = new BitmapCountToBitmapOpCount();

@zclllyybb

Copy link
Copy Markdown
Contributor

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found one additional correctness regression beyond the already-open review threads. The SET deserialization uniqueness issue and PR metadata mismatch were already raised, so I did not duplicate those inline comments.

Critical checkpoint conclusions:

  • Goal/test coverage: the PR aims to optimize BitmapValue SET operations and rewrite bitmap_count(bitmap_op(...)) to *_count functions. Unit tests cover some count/rewrite behavior, but the bitmap_has_all mixed-representation case below is not covered and can return wrong results.
  • Scope/focus: the changes are mostly focused on bitmap performance and nullable count semantics, but they include user-visible planner and function behavior changes.
  • Concurrency/lifecycle: no new concurrency or special lifecycle/static initialization concerns found.
  • Configuration/compatibility: no new config item; serialized bitmap compatibility is touched indirectly. Existing review context already covers the missing SET duplicate validation in deserialize().
  • Parallel paths: FE and BE count nullability paths were reviewed together; the new bitmap_has_all helper path has a missing mixed-representation case.
  • Error handling/memory/observability: no additional Status propagation, memory tracking, or observability blockers found in the reviewed paths.
  • Tests: BE/FE unit coverage was added, but lacks coverage for bitmap_has_all when lhs is SET/SINGLE and rhs is BITMAP.

User focus: no additional user-provided review focus was specified.

bitmap |= rvec[i];
res[i] = bitmap.cardinality() == lhs_cardinality;
res[i] = lvec[i].contains_all(rvec[i]);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fast path changes bitmap_has_all results for mixed representations. contains_all() returns false whenever rhs is BITMAP and lhs is SINGLE or SET, but the previous implementation checked whether lhs | rhs kept the same cardinality, so it returned true when all rhs values were present in lhs. That representation mix is possible, for example a small SET lhs compared with a deserialized roaring BITMAP rhs containing the same values. In that case bitmap_has_all(lhs, rhs) now incorrectly returns 0. Please handle rhs._type == BITMAP by checking all rhs values against the lhs (or by falling back to the old cardinality logic) instead of rejecting non-BITMAP lhs representations.

@linrrzqqq linrrzqqq closed this Jul 6, 2026
@linrrzqqq linrrzqqq deleted the opt-bitmap branch July 6, 2026 02:33
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.

5 participants