github-actions[bot] commented on code in PR #65421:
URL: https://github.com/apache/doris/pull/65421#discussion_r3568677529


##########
be/src/core/value/bitmap_value.h:
##########
@@ -1633,14 +1975,26 @@ class BitmapValue {
                 _convert_to_smaller_type();
                 break;
             case SET:
-                for (auto v : rhs._set) {
-                    if (_set.contains(v)) {
-                        _set.erase(v);
-                    } else {
-                        _set.insert(v);
+                if (this == &rhs) {
+                    reset();
+                    break;
+                }
+
+                std::array<uint64_t, SET_TYPE_THRESHOLD> values_to_add {};
+                size_t add_count = 0;
+                for (size_t i = 0; i < rhs._set.size(); ++i) {
+                    auto v = rhs._set[i];
+                    if (_set.erase(v) == 0) {
+                        values_to_add[add_count++] = v;
                     }
                 }
-                _convert_to_smaller_type();
+
+                if (_set.size() + add_count <= SET_TYPE_THRESHOLD) {

Review Comment:
   This SET/SET xor path can leave a zero-cardinality bitmap represented as 
`SET`. For two distinct SET operands with the same values, for example 
`bitmap_xor(bitmap_from_array([1,2]), bitmap_from_array([1,2]))`, the loop 
erases both values, `add_count` remains 0, `_set.insert_many(..., 0)` returns 
immediately, and the branch exits without `_convert_to_smaller_type()` or 
`reset()`. The result has cardinality 0 but `get_type_code()` still returns 
`SET`, so normal xor can serialize a SET-count-0 payload instead of the 
canonical EMPTY bitmap and recreate the zero-cardinality non-EMPTY state that 
other code has to special-case. Please shrink/reset the SET after this branch 
when it becomes empty.



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