From b9dcb601729c3ddfe6ccabe627293c26bc9a75b5 Mon Sep 17 00:00:00 2001 From: Kikyou1997 <33112463+Kikyou1997@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:52:54 +0800 Subject: [PATCH] [Planner](fix)Fix unexpected index out of bound exception (#11819) --- .../org/apache/doris/planner/SortNode.java | 2 +- .../data/correctness_p0/test_sort.out | 4 ++ .../suites/correctness_p0/test_sort.groovy | 56 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 regression-test/data/correctness_p0/test_sort.out create mode 100644 regression-test/suites/correctness_p0/test_sort.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SortNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/SortNode.java index 8395f749b2..dbd532d4e0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/SortNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SortNode.java @@ -274,7 +274,7 @@ public class SortNode extends PlanNode { @Override public Set computeInputSlotIds(Analyzer analyzer) throws NotImplementedException { List slotDescriptorList = this.info.getSortTupleDescriptor().getSlots(); - for (int i = 0; i < slotDescriptorList.size(); i++) { + for (int i = slotDescriptorList.size() - 1; i >= 0; i--) { if (!slotDescriptorList.get(i).isMaterialized()) { resolvedTupleExprs.remove(i); } diff --git a/regression-test/data/correctness_p0/test_sort.out b/regression-test/data/correctness_p0/test_sort.out new file mode 100644 index 0000000000..095c7b2035 --- /dev/null +++ b/regression-test/data/correctness_p0/test_sort.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +1 + diff --git a/regression-test/suites/correctness_p0/test_sort.groovy b/regression-test/suites/correctness_p0/test_sort.groovy new file mode 100644 index 0000000000..ba77916d3b --- /dev/null +++ b/regression-test/suites/correctness_p0/test_sort.groovy @@ -0,0 +1,56 @@ +// 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_sort") { + + sql """ + DROP TABLE IF EXISTS test_sort_table + """ + + sql """ + CREATE TABLE `test_sort_table` ( + `p_partkey` int(11) NOT NULL COMMENT "", + `p_name` varchar(23) NOT NULL COMMENT "", + `p_mfgr` varchar(7) NOT NULL COMMENT "", + `p_category` varchar(8) NOT NULL COMMENT "", + `p_brand` varchar(10) NOT NULL COMMENT "", + `p_color` varchar(12) NOT NULL COMMENT "", + `p_type` varchar(26) NOT NULL COMMENT "", + `p_size` int(11) NOT NULL COMMENT "", + `p_container` varchar(11) NOT NULL COMMENT "" + ) ENGINE=OLAP + DUPLICATE KEY(`p_partkey`) + COMMENT "OLAP" + DISTRIBUTED BY HASH(`p_partkey`) BUCKETS 12 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "colocate_with" = "groupa5", + "in_memory" = "false", + "storage_format" = "V2" + ) + """ + + sql """ + INSERT INTO test_sort_table VALUES (1, '1', '1', '1', '1', '1', '1', 1, '1'); + """ + + qt_sql """ + select count(1) from (select* from test_sort_table where p_partkey = 1 order by p_partkey desc limit 1) a; + """ + + sql "DROP TABLE test_sort_table" +}