You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ya...@apache.org on 2022/10/14 04:45:13 UTC

[doris] branch master updated: [fix](sort) fix nullable column sorting incorrectly (#13125)

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

yangzhg 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 71f167ac51 [fix](sort) fix nullable column sorting incorrectly (#13125)
71f167ac51 is described below

commit 71f167ac51464074f7590d9e2a405cd779514976
Author: luozenglin <37...@users.noreply.github.com>
AuthorDate: Fri Oct 14 12:45:04 2022 +0800

    [fix](sort) fix nullable column sorting incorrectly (#13125)
---
 be/src/vec/core/sort_block.h                          | 19 ++++++++++++++++---
 regression-test/data/correctness_p0/test_sort.out     | 18 ++++++++++++++++++
 .../suites/correctness_p0/test_sort.groovy            |  4 ++++
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/be/src/vec/core/sort_block.h b/be/src/vec/core/sort_block.h
index c7ff4c70e4..ef21d99d92 100644
--- a/be/src/vec/core/sort_block.h
+++ b/be/src/vec/core/sort_block.h
@@ -223,6 +223,8 @@ public:
             column.get_nested_column().sort_column(this, flags, perms, range, last_column);
         } else {
             const auto& null_map = column.get_null_map_data();
+            int limit = _limit;
+            std::vector<std::pair<size_t, size_t>> is_null_ranges;
             EqualRangeIterator iterator(flags, range.first, range.second);
             while (iterator.next()) {
                 int range_begin = iterator.range_begin;
@@ -259,15 +261,26 @@ public:
                         flags[not_null_range.first] = 0;
                     }
                     if (is_null_range.first < is_null_range.second) {
+                        // do not sort null values
                         std::fill(flags.begin() + is_null_range.first,
-                                  flags.begin() + is_null_range.second, 1);
+                                  flags.begin() + is_null_range.second, 0);
 
-                        flags[is_null_range.first] = 0;
+                        if (UNLIKELY(_limit > is_null_range.first &&
+                                     _limit <= is_null_range.second)) {
+                            _limit = is_null_range.second;
+                        }
+                        is_null_ranges.push_back(std::move(is_null_range));
                     }
                 }
             }
 
             column.get_nested_column().sort_column(this, flags, perms, range, last_column);
+            _limit = limit;
+            if (!last_column) {
+                for (const auto& nr : is_null_ranges) {
+                    std::fill(flags.begin() + nr.first + 1, flags.begin() + nr.second, 1);
+                }
+            }
         }
     }
 
@@ -452,7 +465,7 @@ private:
     }
 
     const ColumnWithSortDescription& _column_with_sort_desc;
-    const int _limit;
+    mutable int _limit;
     const int _nulls_direction;
     const int _direction;
 };
diff --git a/regression-test/data/correctness_p0/test_sort.out b/regression-test/data/correctness_p0/test_sort.out
index 095c7b2035..6f3c3484ed 100644
--- a/regression-test/data/correctness_p0/test_sort.out
+++ b/regression-test/data/correctness_p0/test_sort.out
@@ -2,3 +2,21 @@
 -- !sql --
 1
 
+-- !sql --
+\N	\N	\N	\N
+\N	1	\N	11011902
+\N	2	\N	11011903
+\N	3	\N	11011905
+\N	4	\N	-11011907
+\N	5	\N	-11011903
+\N	6	\N	123456
+\N	7	\N	7210457
+\N	8	\N	11011920
+\N	9	\N	11011902
+\N	10	\N	9223372036854775807
+\N	11	\N	-9223372036854775807
+\N	12	\N	9223372036854775807
+\N	13	\N	-9223372036854775807
+\N	14	\N	11011902
+\N	15	\N	11011920
+
diff --git a/regression-test/suites/correctness_p0/test_sort.groovy b/regression-test/suites/correctness_p0/test_sort.groovy
index ba77916d3b..4bda135ee8 100644
--- a/regression-test/suites/correctness_p0/test_sort.groovy
+++ b/regression-test/suites/correctness_p0/test_sort.groovy
@@ -53,4 +53,8 @@ suite("test_sort") {
     """
 
     sql "DROP TABLE test_sort_table"
+
+    qt_sql """
+        select b.k1, a.k1, b.k4, a.k4 from test_query_db.baseall a left join test_query_db.test b on a.k2 = b.k4  order by 1, 2, 3, 4;
+    """
 }


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