This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.2-lts by this push:
new 4342a34e2d [fix](sort) fix bug of sort (#17149)
4342a34e2d is described below
commit 4342a34e2d2c215ea26a25738ff3014640fd0be6
Author: TengJianPing <[email protected]>
AuthorDate: Mon Feb 27 10:54:06 2023 +0800
[fix](sort) fix bug of sort (#17149)
The logic of topn and full sort is wrong when there are both offsets and
limits, the offset is not considered when doing the max heap optimization,
which will lead to wrong result.
cherry-pick #17151
---
be/src/vec/common/sort/sorter.cpp | 2 +-
be/src/vec/common/sort/topn_sorter.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/common/sort/sorter.cpp
b/be/src/vec/common/sort/sorter.cpp
index f41ceeb5b7..3c8a73e971 100644
--- a/be/src/vec/common/sort/sorter.cpp
+++ b/be/src/vec/common/sort/sorter.cpp
@@ -183,7 +183,7 @@ Status FullSorter::_do_sort() {
// to order the block in _block_priority_queue.
// if one block totally greater the heap top of _block_priority_queue
// we can throw the block data directly.
- if (_state->num_rows < _limit) {
+ if (_state->num_rows < _offset + _limit) {
_state->num_rows += desc_block.rows();
_state->sorted_blocks.emplace_back(std::move(desc_block));
_block_priority_queue.emplace(_pool->add(
diff --git a/be/src/vec/common/sort/topn_sorter.cpp
b/be/src/vec/common/sort/topn_sorter.cpp
index 411a41efd5..c277a5e27b 100644
--- a/be/src/vec/common/sort/topn_sorter.cpp
+++ b/be/src/vec/common/sort/topn_sorter.cpp
@@ -62,7 +62,7 @@ Status TopNSorter::_do_sort(Block* block) {
// to order the block in _block_priority_queue.
// if one block totally greater the heap top of _block_priority_queue
// we can throw the block data directly.
- if (_state->num_rows < _limit) {
+ if (_state->num_rows < _offset + _limit) {
_state->num_rows += sorted_block.rows();
_state->sorted_blocks.emplace_back(std::move(sorted_block));
_block_priority_queue.emplace(_pool->add(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]