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

dataroaring 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 a2ebbe2bffd [fix](cluster key) fix cluster key in topn (#44880)
a2ebbe2bffd is described below

commit a2ebbe2bffdbef6804dfcfd7c09ad109b4cef6fe
Author: meiyi <me...@selectdb.com>
AuthorDate: Wed Dec 4 11:36:44 2024 +0800

    [fix](cluster key) fix cluster key in topn (#44880)
---
 be/src/olap/tablet_reader.cpp                      | 33 +++++++---
 .../data/unique_with_mow_c_p0/test_select.out      |  9 +++
 .../suites/unique_with_mow_c_p0/test_select.groovy | 70 ++++++++++++++++++++++
 3 files changed, 105 insertions(+), 7 deletions(-)

diff --git a/be/src/olap/tablet_reader.cpp b/be/src/olap/tablet_reader.cpp
index 7410b70f4aa..cfd5aa2068b 100644
--- a/be/src/olap/tablet_reader.cpp
+++ b/be/src/olap/tablet_reader.cpp
@@ -464,13 +464,32 @@ Status TabletReader::_init_orderby_keys_param(const 
ReaderParams& read_params) {
     // UNIQUE_KEYS will compare all keys as before
     if (_tablet_schema->keys_type() == DUP_KEYS || 
(_tablet_schema->keys_type() == UNIQUE_KEYS &&
                                                     
_tablet->enable_unique_key_merge_on_write())) {
-        // find index in vector _return_columns
-        //   for the read_orderby_key_num_prefix_columns orderby keys
-        for (uint32_t i = 0; i < 
read_params.read_orderby_key_num_prefix_columns; i++) {
-            for (uint32_t idx = 0; idx < _return_columns.size(); idx++) {
-                if (_return_columns[idx] == i) {
-                    _orderby_key_columns.push_back(idx);
-                    break;
+        if (!_tablet_schema->cluster_key_idxes().empty()) {
+            for (uint32_t i = 0; i < 
read_params.read_orderby_key_num_prefix_columns; i++) {
+                auto cid = _tablet_schema->cluster_key_idxes()[i];
+                auto index = _tablet_schema->field_index(cid);
+                if (index < 0) {
+                    return Status::Error<ErrorCode::INTERNAL_ERROR>(
+                            "could not find cluster key column with 
unique_id=" +
+                            std::to_string(cid) +
+                            " in tablet schema, tablet_id=" + 
std::to_string(_tablet->tablet_id()));
+                }
+                for (uint32_t idx = 0; idx < _return_columns.size(); idx++) {
+                    if (_return_columns[idx] == index) {
+                        _orderby_key_columns.push_back(idx);
+                        break;
+                    }
+                }
+            }
+        } else {
+            // find index in vector _return_columns
+            //   for the read_orderby_key_num_prefix_columns orderby keys
+            for (uint32_t i = 0; i < 
read_params.read_orderby_key_num_prefix_columns; i++) {
+                for (uint32_t idx = 0; idx < _return_columns.size(); idx++) {
+                    if (_return_columns[idx] == i) {
+                        _orderby_key_columns.push_back(idx);
+                        break;
+                    }
                 }
             }
         }
diff --git a/regression-test/data/unique_with_mow_c_p0/test_select.out 
b/regression-test/data/unique_with_mow_c_p0/test_select.out
new file mode 100644
index 00000000000..11c66ecf4db
--- /dev/null
+++ b/regression-test/data/unique_with_mow_c_p0/test_select.out
@@ -0,0 +1,9 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !sql0 --
+0
+can
+
+-- !sql1 --
+0
+can
+
diff --git a/regression-test/suites/unique_with_mow_c_p0/test_select.groovy 
b/regression-test/suites/unique_with_mow_c_p0/test_select.groovy
new file mode 100644
index 00000000000..8cf169e6272
--- /dev/null
+++ b/regression-test/suites/unique_with_mow_c_p0/test_select.groovy
@@ -0,0 +1,70 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_select") {
+    sql """ DROP TABLE IF EXISTS test_select0 """
+    sql """ DROP TABLE IF EXISTS test_select1 """
+
+    sql """ 
+        create table test_select0 (
+            pk int,
+            v1 char(255) null,
+            v2 varchar(255) not null, 
+            v3 varchar(1000) not null 
+        ) engine=olap
+        UNIQUE KEY(pk)
+        distributed by hash(pk) buckets 10
+        properties("replication_num" = "1");
+    """
+
+    sql """ 
+        create table test_select1 (
+            pk int,
+            v1 char(255) null,
+            v2 varchar(255) not null, 
+            v3 varchar(1000) not null 
+        ) engine=olap
+        UNIQUE KEY(pk)
+        cluster by(v2, v3)
+        distributed by hash(pk) buckets 10
+        properties("replication_num" = "1");
+    """
+
+    sql """
+        insert into test_select0 values 
+        (0,null,'a','1'),
+        (1,'r','0','9999-12-31 23:59:59'),
+        (2,'n','she','i'),
+        (3,'but','can','2024-08-03 13:08:30');
+    """
+
+    sql """
+        insert into test_select1 values 
+        (0,null,'a','1'),
+        (1,'r','0','9999-12-31 23:59:59'),
+        (2,'n','she','i'),
+        (3,'but','can','2024-08-03 13:08:30');
+    """
+
+    order_qt_sql0 """ 
+        select v2  from test_select0 where v1 is not null  ORDER BY v2 LIMIT 2 
;
+    """
+
+    order_qt_sql1 """ 
+        select v2  from test_select1 where v1 is not null  ORDER BY v2 LIMIT 2 
;
+    """
+}


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

Reply via email to