HappenLee commented on code in PR #68312:
URL: https://github.com/apache/doris/pull/68312#discussion_r4228151968


##########
be/src/exprs/aggregate/aggregate_function_state_union.h:
##########
@@ -107,6 +108,32 @@ class AggregateStateUnion : public 
AggregateFunctionNonFinalBase,
 
     size_t align_of_data() const override { return _function->align_of_data(); 
}
 
+private:
+    template <bool selected>
+    void add_batch_impl(size_t batch_size, AggregateDataPtr* places, size_t 
place_offset,
+                        const IColumn** columns, Arena& arena) const {
+        // Some batch implementations read the first serialized row before 
entering their loop.
+        if (batch_size == 0) {
+            return;
+        }
+        // Delegate the whole batch so native state columns (e.g. SUM) can 
merge directly,
+        // instead of dispatching through the range interface for every input 
row.
+        // Generic implementations need aligned scratch states and manage 
their construction,
+        // destruction and exception cleanup. Release only this storage after 
the batch;
+        // keep passing the caller's arena for allocations that merged states 
may retain.
+        // The function can be shared by evaluators, so scratch must not be a 
mutable member.
+        Arena scratch_arena;
+        auto* scratch = scratch_arena.aligned_alloc(batch_size * 
_function->size_of_data(),
+                                                    
_function->align_of_data());
+        if constexpr (selected) {
+            _function->deserialize_and_merge_vec_selected(places, 
place_offset, scratch, columns[0],

Review Comment:
   After discussion, we have decided not to address this wide-state batch 
deserialization issue in this PR. The current batch/selected behavior is 
intentionally left unchanged. The two accompanying changes address unused 
native-reader scratch allocation and direct single-state finalization; neither 
is claimed to fix this finding.



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