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


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 419456f3a9f branch-2.1: [fix](sort)fix merge sort may miss the limit 
#46072 (#46158)
419456f3a9f is described below

commit 419456f3a9f38a996de9e7483f2f840875c39371
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Dec 30 20:02:24 2024 +0800

    branch-2.1: [fix](sort)fix merge sort may miss the limit #46072 (#46158)
    
    Cherry-picked from #46072
    
    Co-authored-by: Mryange <yanxuech...@selectdb.com>
---
 be/src/vec/runtime/vsorted_run_merger.cpp | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/be/src/vec/runtime/vsorted_run_merger.cpp 
b/be/src/vec/runtime/vsorted_run_merger.cpp
index f321622012f..c5a054bd359 100644
--- a/be/src/vec/runtime/vsorted_run_merger.cpp
+++ b/be/src/vec/runtime/vsorted_run_merger.cpp
@@ -21,6 +21,7 @@
 #include <vector>
 
 #include "common/exception.h"
+#include "common/logging.h"
 #include "common/status.h"
 #include "util/runtime_profile.h"
 #include "util/stopwatch.hpp"
@@ -97,6 +98,14 @@ Status VSortedRunMerger::get_next(Block* output_block, bool* 
eos) {
         _pending_cursor = nullptr;
     }
 
+    Defer set_limit([&]() {
+        _num_rows_returned += output_block->rows();
+        if (_limit != -1 && _num_rows_returned >= _limit) {
+            output_block->set_num_rows(output_block->rows() - 
(_num_rows_returned - _limit));
+            *eos = true;
+        }
+    });
+
     if (_priority_queue.empty()) {
         *eos = true;
         return Status::OK();
@@ -204,11 +213,6 @@ Status VSortedRunMerger::get_next(Block* output_block, 
bool* eos) {
         }
     }
 
-    _num_rows_returned += output_block->rows();
-    if (_limit != -1 && _num_rows_returned >= _limit) {
-        output_block->set_num_rows(output_block->rows() - (_num_rows_returned 
- _limit));
-        *eos = true;
-    }
     return Status::OK();
 }
 


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

Reply via email to