This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 5f5542c889399c1031b853f11ffdab811b4f361f
Author: Pxl <[email protected]>
AuthorDate: Wed Feb 7 11:57:17 2024 +0800

    [Improvement](memory) clear arena when finalize one row #30788
---
 be/src/olap/memtable.cpp         | 18 ++++++++++++++----
 be/src/vec/olap/block_reader.cpp |  7 +++++--
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/be/src/olap/memtable.cpp b/be/src/olap/memtable.cpp
index d6a0ad93f2b..3e6381a0e6e 100644
--- a/be/src/olap/memtable.cpp
+++ b/be/src/olap/memtable.cpp
@@ -373,19 +373,29 @@ void MemTable::_finalize_one_row(RowInBlock* row,
         // get value columns from agg_places
         for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; 
++i) {
             auto function = _agg_functions[i];
-            auto agg_place = row->agg_places(i);
-            auto col_ptr = 
_output_mutable_block.get_column_by_position(i).get();
+            auto* agg_place = row->agg_places(i);
+            auto* col_ptr = 
_output_mutable_block.get_column_by_position(i).get();
             function->insert_result_into(agg_place, *col_ptr);
+
             if constexpr (is_final) {
                 function->destroy(agg_place);
             } else {
                 function->reset(agg_place);
-                function->add(agg_place, const_cast<const 
doris::vectorized::IColumn**>(&col_ptr),
-                              row_pos, _arena.get());
             }
         }
+
+        _arena->clear();
+
         if constexpr (is_final) {
             row->remove_init_agg();
+        } else {
+            for (size_t i = _tablet_schema->num_key_columns(); i < 
_num_columns; ++i) {
+                auto function = _agg_functions[i];
+                auto* agg_place = row->agg_places(i);
+                auto* col_ptr = 
_output_mutable_block.get_column_by_position(i).get();
+                function->add(agg_place, const_cast<const 
doris::vectorized::IColumn**>(&col_ptr),
+                              row_pos, _arena.get());
+            }
         }
     } else {
         // move columns for rows do not need agg
diff --git a/be/src/vec/olap/block_reader.cpp b/be/src/vec/olap/block_reader.cpp
index 7073d880f38..99d8a9f47f6 100644
--- a/be/src/vec/olap/block_reader.cpp
+++ b/be/src/vec/olap/block_reader.cpp
@@ -521,7 +521,7 @@ void BlockReader::_update_agg_value(MutableColumns& 
columns, int begin, int end,
 
         AggregateFunctionPtr function = _agg_functions[i];
         AggregateDataPtr place = _agg_places[i];
-        auto column_ptr = _stored_data_columns[idx].get();
+        auto* column_ptr = _stored_data_columns[idx].get();
 
         if (begin <= end) {
             function->add_batch_range(begin, end, place, const_cast<const 
IColumn**>(&column_ptr),
@@ -534,13 +534,16 @@ void BlockReader::_update_agg_value(MutableColumns& 
columns, int begin, int end,
             function->reset(place);
         }
     }
+    if (is_close) {
+        _arena.clear();
+    }
 }
 
 bool BlockReader::_get_next_row_same() {
     if (_next_row.is_same) {
         return true;
     } else {
-        auto block = _next_row.block.get();
+        auto* block = _next_row.block.get();
         return block->get_same_bit(_next_row.row_pos);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to