zhangstar333 commented on code in PR #45952:
URL: https://github.com/apache/doris/pull/45952#discussion_r1899945230
##########
be/src/vec/common/sort/sorter.cpp:
##########
@@ -90,53 +90,48 @@ Status
MergeSorterState::merge_sort_read(doris::vectorized::Block* block, int ba
bool* eos) {
DCHECK(sorted_blocks_.empty());
DCHECK(unsorted_block_->empty());
- if (priority_queue_.empty()) {
- *eos = true;
- } else if (priority_queue_.size() == 1) {
- if (offset_ != 0 || priority_queue_.top()->pos != 0) {
- // Skip rows already returned or need to be ignored
- int64_t offset = offset_ + (int64_t)priority_queue_.top()->pos;
- priority_queue_.top().impl->block->skip_num_rows(offset);
- }
- block->swap(*priority_queue_.top().impl->block);
- *eos = true;
- } else {
- RETURN_IF_ERROR(_merge_sort_read_impl(batch_size, block, eos));
- }
+ RETURN_IF_ERROR(_merge_sort_read_impl(batch_size, block, eos));
return Status::OK();
}
Status MergeSorterState::_merge_sort_read_impl(int batch_size,
doris::vectorized::Block* block,
bool* eos) {
- size_t num_columns = priority_queue_.top().impl->block->columns();
+ size_t num_columns = unsorted_block_->columns();
- MutableBlock m_block = VectorizedUtils::build_mutable_mem_reuse_block(
- block, *priority_queue_.top().impl->block);
+ MutableBlock m_block =
VectorizedUtils::build_mutable_mem_reuse_block(block, *unsorted_block_);
MutableColumns& merged_columns = m_block.mutable_columns();
/// Take rows from queue in right order and push to 'merged'.
size_t merged_rows = 0;
// process single element queue on merge_sort_read()
- while (priority_queue_.size() > 1 && merged_rows < batch_size) {
- auto current = priority_queue_.top();
- priority_queue_.pop();
+ while (queue_.is_valid() && merged_rows < batch_size) {
+ auto [current, current_rows] = queue_.current();
+ current_rows = std::min(current_rows, batch_size - merged_rows);
+
+ size_t step = std::min(offset_, current_rows);
+ offset_ -= step;
+ current_rows -= step;
- if (offset_ == 0) {
+ if (current_rows) {
for (size_t i = 0; i < num_columns; ++i) {
-
merged_columns[i]->insert_from(*current->block->get_columns()[i], current->pos);
+
merged_columns[i]->insert_range_from(*current->impl->columns[i],
current->impl->pos,
Review Comment:
maybe start pos at: current->impl->pos + offset ?
--
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]