This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new c95b81f950 [fix](order by) fix bug of order by desc when rowsets is no 
overlapping (#18100)
c95b81f950 is described below

commit c95b81f9504ccfc8b0064f0a7ca7afd9408559b7
Author: TengJianPing <[email protected]>
AuthorDate: Tue Mar 28 09:31:37 2023 +0800

    [fix](order by) fix bug of order by desc when rowsets is no overlapping 
(#18100)
    
    In the case of rowets non-overlap and desc sorting, the logic of 
VCollectIterator::Level0Iterator::init_for_union will be followed. In this 
function, the row ref pos of the first level0 iterator is set to 0, and the row 
pos of other level0 iterators are all Set to -1.
    
    But in the level1iterator, when rowets are non-overlapping and is ordering 
by desc, the list of rowset iterators will be reversed, causing the row ref pos 
of the first level0 iterator in the list to be -1, causing the block reader to 
think that the entire tablet has no data.
---
 be/src/vec/olap/vcollect_iterator.cpp            | 43 ++++++++++++++----------
 be/src/vec/olap/vcollect_iterator.h              |  2 ++
 regression-test/data/query_p0/sort/sort.out      |  6 ++++
 regression-test/suites/query_p0/sort/sort.groovy | 33 ++++++++++++++++++
 4 files changed, 67 insertions(+), 17 deletions(-)

diff --git a/be/src/vec/olap/vcollect_iterator.cpp 
b/be/src/vec/olap/vcollect_iterator.cpp
index 5c9ef48965..f21dd25ab8 100644
--- a/be/src/vec/olap/vcollect_iterator.cpp
+++ b/be/src/vec/olap/vcollect_iterator.cpp
@@ -156,23 +156,11 @@ Status 
VCollectIterator::build_heap(std::vector<RowsetReaderSharedPtr>& rs_reade
                     new Level1Iterator(_children, _reader, _merge, 
_is_reverse, _skip_same));
         }
     } else {
-        bool have_multiple_child = false;
-        bool is_first_child = true;
-        for (auto iter = _children.begin(); iter != _children.end();) {
-            auto s = (*iter)->init_for_union(is_first_child, 
have_multiple_child);
-            if (!s.ok()) {
-                delete (*iter);
-                iter = _children.erase(iter);
-                if (!s.is<END_OF_FILE>()) {
-                    return s;
-                }
-            } else {
-                have_multiple_child = true;
-                is_first_child = false;
-                ++iter;
-            }
-        }
-        _inner_iter.reset(new Level1Iterator(_children, _reader, _merge, 
_is_reverse, _skip_same));
+        auto level1_iter = std::make_unique<Level1Iterator>(_children, 
_reader, _merge, _is_reverse,
+                                                            _skip_same);
+        _children.clear();
+        RETURN_IF_ERROR(level1_iter->init_level0_iterators_for_union());
+        _inner_iter.reset(level1_iter.release());
     }
     RETURN_IF_NOT_EOF_AND_OK(_inner_iter->init());
     // Clear _children earlier to release any related references
@@ -639,6 +627,27 @@ Status VCollectIterator::Level1Iterator::init(bool 
get_data_by_ref) {
     return Status::OK();
 }
 
+Status VCollectIterator::Level1Iterator::init_level0_iterators_for_union() {
+    bool have_multiple_child = false;
+    bool is_first_child = true;
+    for (auto iter = _children.begin(); iter != _children.end();) {
+        auto s = (*iter)->init_for_union(is_first_child, have_multiple_child);
+        if (!s.ok()) {
+            delete (*iter);
+            iter = _children.erase(iter);
+            if (!s.is<END_OF_FILE>()) {
+                return s;
+            }
+        } else {
+            have_multiple_child = true;
+            is_first_child = false;
+            ++iter;
+        }
+    }
+
+    return Status::OK();
+}
+
 Status VCollectIterator::Level1Iterator::_merge_next(IteratorRowRef* ref) {
     _heap->pop();
     auto res = _cur_child->next(ref);
diff --git a/be/src/vec/olap/vcollect_iterator.h 
b/be/src/vec/olap/vcollect_iterator.h
index 3018768d4a..cf1af2f73a 100644
--- a/be/src/vec/olap/vcollect_iterator.h
+++ b/be/src/vec/olap/vcollect_iterator.h
@@ -268,6 +268,8 @@ private:
             return false;
         }
 
+        Status init_level0_iterators_for_union();
+
     private:
         Status _merge_next(IteratorRowRef* ref);
 
diff --git a/regression-test/data/query_p0/sort/sort.out 
b/regression-test/data/query_p0/sort/sort.out
index 7f5a500a5c..e78ae593eb 100644
--- a/regression-test/data/query_p0/sort/sort.out
+++ b/regression-test/data/query_p0/sort/sort.out
@@ -53,3 +53,9 @@ z
 睿
 丝
 
+-- !sql_orderby_non_overlap_desc --
+2023-03-21T09:00       area1   p0      aaaaa   ddddd6  100.000 100.000 100.000 
100.000 2023-03-21T17:00
+2023-03-21T08:00       area1   p0      aaaaa   ddddd5  100.000 100.000 100.000 
100.000 2023-03-21T17:00
+2023-03-21T07:00       area1   p0      aaaaa   ddddd2  100.000 100.000 100.000 
100.000 2023-03-21T17:00
+2023-03-21T06:00       area1   p0      aaaaa   ddddd1  100.000 100.000 100.000 
100.000 2023-03-21T17:00
+
diff --git a/regression-test/suites/query_p0/sort/sort.groovy 
b/regression-test/suites/query_p0/sort/sort.groovy
index 193598f3ce..c3fdd818e7 100644
--- a/regression-test/suites/query_p0/sort/sort.groovy
+++ b/regression-test/suites/query_p0/sort/sort.groovy
@@ -67,4 +67,37 @@ suite("sort") {
                );"""
     sql """insert into test_convert values("b"),("z"),("a"), ("c"), ("睿"), 
("多"), ("丝");"""
     qt_sql """select * from test_convert order by convert(a using gbk);"""
+
+    sql """ DROP TABLE if exists `sort_non_overlap`; """
+    sql """ CREATE TABLE `sort_non_overlap` (
+      `time_period` datetime NOT NULL,
+      `area_name` varchar(255) NOT NULL,
+      `province` varchar(255) NOT NULL,
+      `res_name` varchar(255) NOT NULL,
+      `dev` varchar(255) NOT NULL,
+      `dec0` decimal(10, 3) REPLACE_IF_NOT_NULL NULL,
+      `dec1` decimal(10, 3) REPLACE_IF_NOT_NULL NULL,
+      `dec2` decimal(10, 3) REPLACE_IF_NOT_NULL NULL,
+      `dec3` decimal(10, 3) REPLACE_IF_NOT_NULL NULL,
+      `update_time` datetime REPLACE NULL
+    ) ENGINE=OLAP
+    AGGREGATE KEY(`time_period`, `area_name`, `province`, `res_name`, `dev`)
+    DISTRIBUTED BY HASH(`area_name`) BUCKETS 1
+    PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1",
+    "disable_auto_compaction" = "true"
+    );
+    """
+
+    sql """ insert into sort_non_overlap values
+        ('2023-03-21 06:00:00', 'area1', 'p0', 'aaaaa', 'ddddd1', 100, 100, 
100, 100, '2023-03-21 17:00:00'),
+        ('2023-03-21 07:00:00', 'area1', 'p0', 'aaaaa', 'ddddd2', 100, 100, 
100, 100, '2023-03-21 17:00:00');
+    """
+
+    sql """ insert into sort_non_overlap values
+                ('2023-03-21 08:00:00', 'area1', 'p0', 'aaaaa', 'ddddd5', 100, 
100, 100, 100, '2023-03-21 17:00:00'),
+                ('2023-03-21 09:00:00', 'area1', 'p0', 'aaaaa', 'ddddd6', 100, 
100, 100, 100, '2023-03-21 17:00:00');
+    """
+
+    qt_sql_orderby_non_overlap_desc """ select * from sort_non_overlap order 
by time_period desc limit 4; """
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to