diff --git a/be/src/vec/exec/vpartition_sort_node.cpp b/be/src/vec/exec/vpartition_sort_node.cpp index 7f407e517e..66dcfa951b 100644 --- a/be/src/vec/exec/vpartition_sort_node.cpp +++ b/be/src/vec/exec/vpartition_sort_node.cpp @@ -64,6 +64,7 @@ Status VPartitionSortNode::init(const TPlanNode& tnode, RuntimeState* state) { _has_global_limit = tnode.partition_sort_node.has_global_limit; _top_n_algorithm = tnode.partition_sort_node.top_n_algorithm; _partition_inner_limit = tnode.partition_sort_node.partition_inner_limit; + _topn_phase = tnode.partition_sort_node.ptopn_phase; return Status::OK(); } @@ -173,7 +174,9 @@ Status VPartitionSortNode::sink(RuntimeState* state, vectorized::Block* input_bl _value_places[0]->append_whole_block(input_block, child(0)->row_desc()); } else { //just simply use partition num to check - if (_num_partition > config::partition_topn_partition_threshold && + //if is TWO_PHASE_GLOBAL, must be sort all data thought partition num threshold have been exceeded. + if (_topn_phase != TPartTopNPhase::TWO_PHASE_GLOBAL && + _num_partition > config::partition_topn_partition_threshold && child_input_rows < 10000 * _num_partition) { { std::lock_guard lock(_buffer_mutex); diff --git a/be/src/vec/exec/vpartition_sort_node.h b/be/src/vec/exec/vpartition_sort_node.h index a583d99b1f..84e31db016 100644 --- a/be/src/vec/exec/vpartition_sort_node.h +++ b/be/src/vec/exec/vpartition_sort_node.h @@ -435,6 +435,7 @@ private: std::queue _blocks_buffer; int64_t child_input_rows = 0; std::mutex _buffer_mutex; + TPartTopNPhase::type _topn_phase; RuntimeProfile::Counter* _build_timer; RuntimeProfile::Counter* _emplace_key_timer; diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/PartitionSortNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/PartitionSortNode.java index cfdbfd54c7..fc63af3b6c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/PartitionSortNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/PartitionSortNode.java @@ -148,11 +148,11 @@ public class PartitionSortNode extends PlanNode { TPartTopNPhase pTopNPhase; if (phase == PartitionTopnPhase.ONE_PHASE_GLOBAL_PTOPN) { - pTopNPhase = TPartTopNPhase.ONE_PAHSE_GLOBAL; + pTopNPhase = TPartTopNPhase.ONE_PHASE_GLOBAL; } else if (phase == PartitionTopnPhase.TWO_PHASE_LOCAL_PTOPN) { - pTopNPhase = TPartTopNPhase.TWO_PAHSE_LOCAL; + pTopNPhase = TPartTopNPhase.TWO_PHASE_LOCAL; } else if (phase == PartitionTopnPhase.TWO_PHASE_GLOBAL_PTOPN) { - pTopNPhase = TPartTopNPhase.TWO_PAHSE_GLOBAL; + pTopNPhase = TPartTopNPhase.TWO_PHASE_GLOBAL; } else { pTopNPhase = TPartTopNPhase.UNKNOWN; } diff --git a/gensrc/thrift/PlanNodes.thrift b/gensrc/thrift/PlanNodes.thrift index 1e8eba5bb9..08be029401 100644 --- a/gensrc/thrift/PlanNodes.thrift +++ b/gensrc/thrift/PlanNodes.thrift @@ -856,9 +856,9 @@ enum TopNAlgorithm { enum TPartTopNPhase { UNKNOWN, - ONE_PAHSE_GLOBAL, - TWO_PAHSE_LOCAL, - TWO_PAHSE_GLOBAL + ONE_PHASE_GLOBAL, + TWO_PHASE_LOCAL, + TWO_PHASE_GLOBAL } struct TPartitionSortNode { diff --git a/regression-test/data/ssb_unique_sql_zstd_p0/partition_sort_node/test_partiiton_sort.out b/regression-test/data/ssb_unique_sql_zstd_p0/partition_sort_node/test_partiiton_sort.out new file mode 100644 index 0000000000..9beba7f0bd --- /dev/null +++ b/regression-test/data/ssb_unique_sql_zstd_p0/partition_sort_node/test_partiiton_sort.out @@ -0,0 +1,24 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select0 -- +20000 + +-- !select1 -- +7463 92 14 14 13 + +-- !select2 -- +aquamarine blue seashell 14 + +-- !select3 -- +aquamarine blue peru 11 +indian coral smoke 11 +lace blue spring 11 + +-- !select4 -- +aquamarine blue peru 10 +beige blanched thistle 10 +beige forest white 10 +bisque orange violet 10 +blush frosted thistle 10 +indian coral seashell 10 +lace blue midnight 10 + diff --git a/regression-test/suites/ssb_unique_sql_zstd_p0/partition_sort_node/test_partiiton_sort.groovy b/regression-test/suites/ssb_unique_sql_zstd_p0/partition_sort_node/test_partiiton_sort.groovy new file mode 100644 index 0000000000..d9f6776b3a --- /dev/null +++ b/regression-test/suites/ssb_unique_sql_zstd_p0/partition_sort_node/test_partiiton_sort.groovy @@ -0,0 +1,34 @@ +// 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_partition_sort") { + sql "use regression_test_ssb_unique_sql_zstd_p0" + qt_select0 """ select count() from part; """ + qt_select1 """ select count(distinct p_name), count(distinct p_color),count(distinct rn),count(distinct rk),count(distinct dr) from ( + select p_name, p_color , row_number() over(partition by p_name order by p_color) as rn,rank() over(partition by p_name order by p_color) as rk, + dense_rank() over(partition by p_name order by p_color) as dr from part) as t; """ + + qt_select2 """ select * from ( + select p_name, p_color , row_number() over(partition by p_name order by p_color) as rn from part) as t where rn=14 order by 1,2,3; """ + + qt_select3 """ select * from ( select p_name, p_color , rank() over(partition by p_name order by p_color) as rn from part) as t where rn=11 order by 1,2,3; """ + + qt_select4 """ select * from ( select p_name, p_color , dense_rank() over(partition by p_name order by p_color) as rn from part) as t where rn=10 order by 1,2,3; """ + + + +} \ No newline at end of file