yiguolei commented on code in PR #62835:
URL: https://github.com/apache/doris/pull/62835#discussion_r3145245720


##########
be/src/storage/iterator/vcollect_iterator.cpp:
##########
@@ -488,10 +495,56 @@ Status VCollectIterator::_topn_next(Block* block) {
                << " mutable_block.rows()=" << mutable_block.rows();
     *block = mutable_block.to_block();
 
+    // If byte budget is active and the result exceeds it, split into chunks.
+    size_t preferred_bytes = _reader->preferred_block_size_bytes();
+    if (preferred_bytes > 0 && block->rows() > 1 && block->bytes() > 
preferred_bytes) {
+        _topn_result_block = std::move(*block);
+        _topn_result_offset = 0;
+        return _topn_next_chunk(block);
+    }
+
     _topn_eof = true;
     return block->rows() > 0 ? Status::OK() : Status::Error<END_OF_FILE>("");
 }
 
+Status VCollectIterator::_topn_next_chunk(Block* block) {
+    size_t total_rows = _topn_result_block.rows();
+    if (_topn_result_offset >= total_rows) {
+        _topn_result_block.clear();
+        _topn_eof = true;
+        return Status::Error<END_OF_FILE>("");
+    }
+
+    size_t remaining = total_rows - _topn_result_offset;
+    size_t chunk_rows = remaining;
+
+    // Cap by batch_max_rows.
+    chunk_rows = std::min(chunk_rows, (size_t)_reader->batch_max_rows());
+
+    // Cap by byte budget.
+    size_t preferred_bytes = _reader->preferred_block_size_bytes();
+    if (preferred_bytes > 0 && total_rows > 0) {
+        size_t avg_row_bytes = std::max<size_t>(1, _topn_result_block.bytes() 
/ total_rows);
+        chunk_rows = std::min(chunk_rows, std::max<size_t>(1, preferred_bytes 
/ avg_row_bytes));
+    }
+
+    *block = _topn_result_block.clone_empty();

Review Comment:
   这里的逻辑,不单纯是在改变block 大小,感觉风险很高



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