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


##########
be/src/vec/common/sort/sorter.cpp:
##########
@@ -210,11 +211,27 @@ FullSorter::FullSorter(VSortExecExprs& vsort_exec_exprs, 
int limit, int64_t offs
         : Sorter(vsort_exec_exprs, limit, offset, pool, is_asc_order, 
nulls_first),
           _state(MergeSorterState::create_unique(row_desc, offset, limit, 
state, profile)) {}
 
+// check whether the unsorted block can hold more data from input block and no 
need to alloc new memory
+bool FullSorter::has_enough_capacity(Block* input_block, Block* 
unsorted_block) const {
+    DCHECK_EQ(input_block->columns(), unsorted_block->columns());
+    for (auto i = 0; i < input_block->columns(); ++i) {
+        if (unsorted_block->get_by_position(i).column->has_enough_capacity(
+                    *input_block->get_by_position(i).column)) {
+            return false;
+        }
+    }
+    return true;
+}
+
 Status FullSorter::append_block(Block* block) {
     DCHECK(block->rows() > 0);
 
-    if (_reach_limit() && block->bytes() > 
_state->unsorted_block()->allocated_bytes() -
-                                                   
_state->unsorted_block()->bytes()) {
+    // iff have reach limit and the unsorted block capacity can't hold the 
block data size
+    if (_reach_limit() && !has_enough_capacity(block, 
_state->unsorted_block().get())) {
+        RETURN_IF_ERROR(_do_sort());
+    } else if (_reach_limit(2)) {

Review Comment:
   what the code ? 



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to